PageRenderTime 63ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 2ms

/app/cache/dev/classes.php

https://github.com/djae138/symfony
PHP | 6174 lines | 6174 code | 0 blank | 0 comment | 754 complexity | 30d4af11c158b9d4b25030d5fa5aa148 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. namespace Symfony\Component\EventDispatcher
  3. {
  4. interface EventSubscriberInterface
  5. {
  6. public static function getSubscribedEvents();
  7. }
  8. }
  9. namespace Symfony\Bundle\FrameworkBundle\EventListener
  10. {
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Symfony\Component\HttpKernel\HttpKernelInterface;
  13. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class SessionListener implements EventSubscriberInterface
  17. {
  18. private $container;
  19. public function __construct(ContainerInterface $container)
  20. {
  21. $this->container = $container;
  22. }
  23. public function onKernelRequest(GetResponseEvent $event)
  24. {
  25. if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
  26. return;
  27. }
  28. $request = $event->getRequest();
  29. if (!$this->container->has('session') || $request->hasSession()) {
  30. return;
  31. }
  32. $request->setSession($this->container->get('session'));
  33. }
  34. public static function getSubscribedEvents()
  35. {
  36. return array(
  37. KernelEvents::REQUEST => array('onKernelRequest', 128),
  38. );
  39. }
  40. }
  41. }
  42. namespace Symfony\Component\HttpFoundation\Session\Storage
  43. {
  44. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  45. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  46. interface SessionStorageInterface
  47. {
  48. public function start();
  49. public function isStarted();
  50. public function getId();
  51. public function setId($id);
  52. public function getName();
  53. public function setName($name);
  54. public function regenerate($destroy = false, $lifetime = null);
  55. public function save();
  56. public function clear();
  57. public function getBag($name);
  58. public function registerBag(SessionBagInterface $bag);
  59. public function getMetadataBag();
  60. }
  61. }
  62. namespace Symfony\Component\HttpFoundation\Session\Storage
  63. {
  64. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  65. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
  66. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  67. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
  68. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  69. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
  70. class NativeSessionStorage implements SessionStorageInterface
  71. {
  72. protected $bags;
  73. protected $started = false;
  74. protected $closed = false;
  75. protected $saveHandler;
  76. protected $metadataBag;
  77. public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
  78. {
  79. session_cache_limiter(''); ini_set('session.use_cookies', 1);
  80. if (version_compare(phpversion(),'5.4.0','>=')) {
  81. session_register_shutdown();
  82. } else {
  83. register_shutdown_function('session_write_close');
  84. }
  85. $this->setMetadataBag($metaBag);
  86. $this->setOptions($options);
  87. $this->setSaveHandler($handler);
  88. }
  89. public function getSaveHandler()
  90. {
  91. return $this->saveHandler;
  92. }
  93. public function start()
  94. {
  95. if ($this->started && !$this->closed) {
  96. return true;
  97. }
  98. if (version_compare(phpversion(),'5.4.0','>=') && \PHP_SESSION_ACTIVE === session_status()) {
  99. throw new \RuntimeException('Failed to start the session: already started by PHP.');
  100. }
  101. if (version_compare(phpversion(),'5.4.0','<') && isset($_SESSION) && session_id()) {
  102. throw new \RuntimeException('Failed to start the session: already started by PHP ($_SESSION is set).');
  103. }
  104. if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
  105. throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
  106. }
  107. if (!session_start()) {
  108. throw new \RuntimeException('Failed to start the session');
  109. }
  110. $this->loadSession();
  111. if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
  112. $this->saveHandler->setActive(true);
  113. }
  114. return true;
  115. }
  116. public function getId()
  117. {
  118. if (!$this->started) {
  119. return''; }
  120. return $this->saveHandler->getId();
  121. }
  122. public function setId($id)
  123. {
  124. $this->saveHandler->setId($id);
  125. }
  126. public function getName()
  127. {
  128. return $this->saveHandler->getName();
  129. }
  130. public function setName($name)
  131. {
  132. $this->saveHandler->setName($name);
  133. }
  134. public function regenerate($destroy = false, $lifetime = null)
  135. {
  136. if (null !== $lifetime) {
  137. ini_set('session.cookie_lifetime', $lifetime);
  138. }
  139. if ($destroy) {
  140. $this->metadataBag->stampNew();
  141. }
  142. $ret = session_regenerate_id($destroy);
  143. if ('files'=== $this->getSaveHandler()->getSaveHandlerName()) {
  144. session_write_close();
  145. if (isset($_SESSION)) {
  146. $backup = $_SESSION;
  147. session_start();
  148. $_SESSION = $backup;
  149. } else {
  150. session_start();
  151. }
  152. $this->loadSession();
  153. }
  154. return $ret;
  155. }
  156. public function save()
  157. {
  158. session_write_close();
  159. if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
  160. $this->saveHandler->setActive(false);
  161. }
  162. $this->closed = true;
  163. $this->started = false;
  164. }
  165. public function clear()
  166. {
  167. foreach ($this->bags as $bag) {
  168. $bag->clear();
  169. }
  170. $_SESSION = array();
  171. $this->loadSession();
  172. }
  173. public function registerBag(SessionBagInterface $bag)
  174. {
  175. $this->bags[$bag->getName()] = $bag;
  176. }
  177. public function getBag($name)
  178. {
  179. if (!isset($this->bags[$name])) {
  180. throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
  181. }
  182. if ($this->saveHandler->isActive() && !$this->started) {
  183. $this->loadSession();
  184. } elseif (!$this->started) {
  185. $this->start();
  186. }
  187. return $this->bags[$name];
  188. }
  189. public function setMetadataBag(MetadataBag $metaBag = null)
  190. {
  191. if (null === $metaBag) {
  192. $metaBag = new MetadataBag();
  193. }
  194. $this->metadataBag = $metaBag;
  195. }
  196. public function getMetadataBag()
  197. {
  198. return $this->metadataBag;
  199. }
  200. public function isStarted()
  201. {
  202. return $this->started;
  203. }
  204. public function setOptions(array $options)
  205. {
  206. $validOptions = array_flip(array('cache_limiter','cookie_domain','cookie_httponly','cookie_lifetime','cookie_path','cookie_secure','entropy_file','entropy_length','gc_divisor','gc_maxlifetime','gc_probability','hash_bits_per_character','hash_function','name','referer_check','serialize_handler','use_cookies','use_only_cookies','use_trans_sid','upload_progress.enabled','upload_progress.cleanup','upload_progress.prefix','upload_progress.name','upload_progress.freq','upload_progress.min-freq','url_rewriter.tags',
  207. ));
  208. foreach ($options as $key => $value) {
  209. if (isset($validOptions[$key])) {
  210. ini_set('session.'.$key, $value);
  211. }
  212. }
  213. }
  214. public function setSaveHandler($saveHandler = null)
  215. {
  216. if (!$saveHandler instanceof AbstractProxy &&
  217. !$saveHandler instanceof NativeSessionHandler &&
  218. !$saveHandler instanceof \SessionHandlerInterface &&
  219. null !== $saveHandler) {
  220. throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
  221. }
  222. if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
  223. $saveHandler = new SessionHandlerProxy($saveHandler);
  224. } elseif (!$saveHandler instanceof AbstractProxy) {
  225. $saveHandler = version_compare(phpversion(),'5.4.0','>=') ?
  226. new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy();
  227. }
  228. $this->saveHandler = $saveHandler;
  229. if ($this->saveHandler instanceof \SessionHandlerInterface) {
  230. if (version_compare(phpversion(),'5.4.0','>=')) {
  231. session_set_save_handler($this->saveHandler, false);
  232. } else {
  233. session_set_save_handler(
  234. array($this->saveHandler,'open'),
  235. array($this->saveHandler,'close'),
  236. array($this->saveHandler,'read'),
  237. array($this->saveHandler,'write'),
  238. array($this->saveHandler,'destroy'),
  239. array($this->saveHandler,'gc')
  240. );
  241. }
  242. }
  243. }
  244. protected function loadSession(array &$session = null)
  245. {
  246. if (null === $session) {
  247. $session = &$_SESSION;
  248. }
  249. $bags = array_merge($this->bags, array($this->metadataBag));
  250. foreach ($bags as $bag) {
  251. $key = $bag->getStorageKey();
  252. $session[$key] = isset($session[$key]) ? $session[$key] : array();
  253. $bag->initialize($session[$key]);
  254. }
  255. $this->started = true;
  256. $this->closed = false;
  257. }
  258. }
  259. }
  260. namespace Symfony\Component\HttpFoundation\Session\Storage
  261. {
  262. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  263. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  264. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
  265. class PhpBridgeSessionStorage extends NativeSessionStorage
  266. {
  267. public function __construct($handler = null, MetadataBag $metaBag = null)
  268. {
  269. $this->setMetadataBag($metaBag);
  270. $this->setSaveHandler($handler);
  271. }
  272. public function start()
  273. {
  274. if ($this->started && !$this->closed) {
  275. return true;
  276. }
  277. $this->loadSession();
  278. if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
  279. $this->saveHandler->setActive(true);
  280. }
  281. return true;
  282. }
  283. public function clear()
  284. {
  285. foreach ($this->bags as $bag) {
  286. $bag->clear();
  287. }
  288. $this->loadSession();
  289. }
  290. }
  291. }
  292. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  293. {
  294. if (version_compare(phpversion(),'5.4.0','>=')) {
  295. class NativeSessionHandler extends \SessionHandler {}
  296. } else {
  297. class NativeSessionHandler {}
  298. }
  299. }
  300. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  301. {
  302. class NativeFileSessionHandler extends NativeSessionHandler
  303. {
  304. public function __construct($savePath = null)
  305. {
  306. if (null === $savePath) {
  307. $savePath = ini_get('session.save_path');
  308. }
  309. $baseDir = $savePath;
  310. if ($count = substr_count($savePath,';')) {
  311. if ($count > 2) {
  312. throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
  313. }
  314. $baseDir = ltrim(strrchr($savePath,';'),';');
  315. }
  316. if ($baseDir && !is_dir($baseDir)) {
  317. mkdir($baseDir, 0777, true);
  318. }
  319. ini_set('session.save_path', $savePath);
  320. ini_set('session.save_handler','files');
  321. }
  322. }
  323. }
  324. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  325. {
  326. abstract class AbstractProxy
  327. {
  328. protected $wrapper = false;
  329. protected $active = false;
  330. protected $saveHandlerName;
  331. public function getSaveHandlerName()
  332. {
  333. return $this->saveHandlerName;
  334. }
  335. public function isSessionHandlerInterface()
  336. {
  337. return ($this instanceof \SessionHandlerInterface);
  338. }
  339. public function isWrapper()
  340. {
  341. return $this->wrapper;
  342. }
  343. public function isActive()
  344. {
  345. if (version_compare(phpversion(),'5.4.0','>=')) {
  346. return $this->active = \PHP_SESSION_ACTIVE === session_status();
  347. }
  348. return $this->active;
  349. }
  350. public function setActive($flag)
  351. {
  352. if (version_compare(phpversion(),'5.4.0','>=')) {
  353. throw new \LogicException('This method is disabled in PHP 5.4.0+');
  354. }
  355. $this->active = (bool) $flag;
  356. }
  357. public function getId()
  358. {
  359. return session_id();
  360. }
  361. public function setId($id)
  362. {
  363. if ($this->isActive()) {
  364. throw new \LogicException('Cannot change the ID of an active session');
  365. }
  366. session_id($id);
  367. }
  368. public function getName()
  369. {
  370. return session_name();
  371. }
  372. public function setName($name)
  373. {
  374. if ($this->isActive()) {
  375. throw new \LogicException('Cannot change the name of an active session');
  376. }
  377. session_name($name);
  378. }
  379. }
  380. }
  381. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  382. {
  383. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
  384. {
  385. protected $handler;
  386. public function __construct(\SessionHandlerInterface $handler)
  387. {
  388. $this->handler = $handler;
  389. $this->wrapper = ($handler instanceof \SessionHandler);
  390. $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') :'user';
  391. }
  392. public function open($savePath, $sessionName)
  393. {
  394. $return = (bool) $this->handler->open($savePath, $sessionName);
  395. if (true === $return) {
  396. $this->active = true;
  397. }
  398. return $return;
  399. }
  400. public function close()
  401. {
  402. $this->active = false;
  403. return (bool) $this->handler->close();
  404. }
  405. public function read($id)
  406. {
  407. return (string) $this->handler->read($id);
  408. }
  409. public function write($id, $data)
  410. {
  411. return (bool) $this->handler->write($id, $data);
  412. }
  413. public function destroy($id)
  414. {
  415. return (bool) $this->handler->destroy($id);
  416. }
  417. public function gc($maxlifetime)
  418. {
  419. return (bool) $this->handler->gc($maxlifetime);
  420. }
  421. }
  422. }
  423. namespace Symfony\Component\HttpFoundation\Session
  424. {
  425. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  426. interface SessionInterface
  427. {
  428. public function start();
  429. public function getId();
  430. public function setId($id);
  431. public function getName();
  432. public function setName($name);
  433. public function invalidate($lifetime = null);
  434. public function migrate($destroy = false, $lifetime = null);
  435. public function save();
  436. public function has($name);
  437. public function get($name, $default = null);
  438. public function set($name, $value);
  439. public function all();
  440. public function replace(array $attributes);
  441. public function remove($name);
  442. public function clear();
  443. public function isStarted();
  444. public function registerBag(SessionBagInterface $bag);
  445. public function getBag($name);
  446. public function getMetadataBag();
  447. }
  448. }
  449. namespace Symfony\Component\HttpFoundation\Session
  450. {
  451. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  452. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  453. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  454. use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  455. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  456. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  457. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  458. class Session implements SessionInterface, \IteratorAggregate, \Countable
  459. {
  460. protected $storage;
  461. private $flashName;
  462. private $attributeName;
  463. public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
  464. {
  465. $this->storage = $storage ?: new NativeSessionStorage();
  466. $attributes = $attributes ?: new AttributeBag();
  467. $this->attributeName = $attributes->getName();
  468. $this->registerBag($attributes);
  469. $flashes = $flashes ?: new FlashBag();
  470. $this->flashName = $flashes->getName();
  471. $this->registerBag($flashes);
  472. }
  473. public function start()
  474. {
  475. return $this->storage->start();
  476. }
  477. public function has($name)
  478. {
  479. return $this->storage->getBag($this->attributeName)->has($name);
  480. }
  481. public function get($name, $default = null)
  482. {
  483. return $this->storage->getBag($this->attributeName)->get($name, $default);
  484. }
  485. public function set($name, $value)
  486. {
  487. $this->storage->getBag($this->attributeName)->set($name, $value);
  488. }
  489. public function all()
  490. {
  491. return $this->storage->getBag($this->attributeName)->all();
  492. }
  493. public function replace(array $attributes)
  494. {
  495. $this->storage->getBag($this->attributeName)->replace($attributes);
  496. }
  497. public function remove($name)
  498. {
  499. return $this->storage->getBag($this->attributeName)->remove($name);
  500. }
  501. public function clear()
  502. {
  503. $this->storage->getBag($this->attributeName)->clear();
  504. }
  505. public function isStarted()
  506. {
  507. return $this->storage->isStarted();
  508. }
  509. public function getIterator()
  510. {
  511. return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
  512. }
  513. public function count()
  514. {
  515. return count($this->storage->getBag($this->attributeName)->all());
  516. }
  517. public function invalidate($lifetime = null)
  518. {
  519. $this->storage->clear();
  520. return $this->migrate(true, $lifetime);
  521. }
  522. public function migrate($destroy = false, $lifetime = null)
  523. {
  524. return $this->storage->regenerate($destroy, $lifetime);
  525. }
  526. public function save()
  527. {
  528. $this->storage->save();
  529. }
  530. public function getId()
  531. {
  532. return $this->storage->getId();
  533. }
  534. public function setId($id)
  535. {
  536. $this->storage->setId($id);
  537. }
  538. public function getName()
  539. {
  540. return $this->storage->getName();
  541. }
  542. public function setName($name)
  543. {
  544. $this->storage->setName($name);
  545. }
  546. public function getMetadataBag()
  547. {
  548. return $this->storage->getMetadataBag();
  549. }
  550. public function registerBag(SessionBagInterface $bag)
  551. {
  552. $this->storage->registerBag($bag);
  553. }
  554. public function getBag($name)
  555. {
  556. return $this->storage->getBag($name);
  557. }
  558. public function getFlashBag()
  559. {
  560. return $this->getBag($this->flashName);
  561. }
  562. }
  563. }
  564. namespace Symfony\Bundle\FrameworkBundle\Templating
  565. {
  566. use Symfony\Component\DependencyInjection\ContainerInterface;
  567. use Symfony\Component\HttpFoundation\Session\Session;
  568. use Symfony\Component\Security\Core\SecurityContext;
  569. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  570. use Symfony\Component\HttpFoundation\Request;
  571. class GlobalVariables
  572. {
  573. protected $container;
  574. public function __construct(ContainerInterface $container)
  575. {
  576. $this->container = $container;
  577. }
  578. public function getSecurity()
  579. {
  580. if ($this->container->has('security.context')) {
  581. return $this->container->get('security.context');
  582. }
  583. }
  584. public function getUser()
  585. {
  586. if (!$security = $this->getSecurity()) {
  587. return;
  588. }
  589. if (!$token = $security->getToken()) {
  590. return;
  591. }
  592. $user = $token->getUser();
  593. if (!is_object($user)) {
  594. return;
  595. }
  596. return $user;
  597. }
  598. public function getRequest()
  599. {
  600. if ($this->container->has('request') && $request = $this->container->get('request')) {
  601. return $request;
  602. }
  603. }
  604. public function getSession()
  605. {
  606. if ($request = $this->getRequest()) {
  607. return $request->getSession();
  608. }
  609. }
  610. public function getEnvironment()
  611. {
  612. return $this->container->getParameter('kernel.environment');
  613. }
  614. public function getDebug()
  615. {
  616. return (Boolean) $this->container->getParameter('kernel.debug');
  617. }
  618. }
  619. }
  620. namespace Symfony\Component\Templating
  621. {
  622. interface TemplateReferenceInterface
  623. {
  624. public function all();
  625. public function set($name, $value);
  626. public function get($name);
  627. public function getPath();
  628. public function getLogicalName();
  629. }
  630. }
  631. namespace Symfony\Component\Templating
  632. {
  633. class TemplateReference implements TemplateReferenceInterface
  634. {
  635. protected $parameters;
  636. public function __construct($name = null, $engine = null)
  637. {
  638. $this->parameters = array('name'=> $name,'engine'=> $engine,
  639. );
  640. }
  641. public function __toString()
  642. {
  643. return $this->getLogicalName();
  644. }
  645. public function set($name, $value)
  646. {
  647. if (array_key_exists($name, $this->parameters)) {
  648. $this->parameters[$name] = $value;
  649. } else {
  650. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  651. }
  652. return $this;
  653. }
  654. public function get($name)
  655. {
  656. if (array_key_exists($name, $this->parameters)) {
  657. return $this->parameters[$name];
  658. }
  659. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  660. }
  661. public function all()
  662. {
  663. return $this->parameters;
  664. }
  665. public function getPath()
  666. {
  667. return $this->parameters['name'];
  668. }
  669. public function getLogicalName()
  670. {
  671. return $this->parameters['name'];
  672. }
  673. }
  674. }
  675. namespace Symfony\Bundle\FrameworkBundle\Templating
  676. {
  677. use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
  678. class TemplateReference extends BaseTemplateReference
  679. {
  680. public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
  681. {
  682. $this->parameters = array('bundle'=> $bundle,'controller'=> $controller,'name'=> $name,'format'=> $format,'engine'=> $engine,
  683. );
  684. }
  685. public function getPath()
  686. {
  687. $controller = str_replace('\\','/', $this->get('controller'));
  688. $path = (empty($controller) ?'': $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
  689. return empty($this->parameters['bundle']) ?'views/'.$path :'@'.$this->get('bundle').'/Resources/views/'.$path;
  690. }
  691. public function getLogicalName()
  692. {
  693. return sprintf('%s:%s:%s.%s.%s', $this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
  694. }
  695. }
  696. }
  697. namespace Symfony\Component\Templating
  698. {
  699. interface TemplateNameParserInterface
  700. {
  701. public function parse($name);
  702. }
  703. }
  704. namespace Symfony\Bundle\FrameworkBundle\Templating
  705. {
  706. use Symfony\Component\Templating\TemplateNameParserInterface;
  707. use Symfony\Component\Templating\TemplateReferenceInterface;
  708. use Symfony\Component\HttpKernel\KernelInterface;
  709. class TemplateNameParser implements TemplateNameParserInterface
  710. {
  711. protected $kernel;
  712. protected $cache;
  713. public function __construct(KernelInterface $kernel)
  714. {
  715. $this->kernel = $kernel;
  716. $this->cache = array();
  717. }
  718. public function parse($name)
  719. {
  720. if ($name instanceof TemplateReferenceInterface) {
  721. return $name;
  722. } elseif (isset($this->cache[$name])) {
  723. return $this->cache[$name];
  724. }
  725. $name = str_replace(':/',':', preg_replace('#/{2,}#','/', strtr($name,'\\','/')));
  726. if (false !== strpos($name,'..')) {
  727. throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
  728. }
  729. if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
  730. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
  731. }
  732. $template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
  733. if ($template->get('bundle')) {
  734. try {
  735. $this->kernel->getBundle($template->get('bundle'));
  736. } catch (\Exception $e) {
  737. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
  738. }
  739. }
  740. return $this->cache[$name] = $template;
  741. }
  742. }
  743. }
  744. namespace Symfony\Component\Config
  745. {
  746. interface FileLocatorInterface
  747. {
  748. public function locate($name, $currentPath = null, $first = true);
  749. }
  750. }
  751. namespace Symfony\Bundle\FrameworkBundle\Templating\Loader
  752. {
  753. use Symfony\Component\Config\FileLocatorInterface;
  754. use Symfony\Component\Templating\TemplateReferenceInterface;
  755. class TemplateLocator implements FileLocatorInterface
  756. {
  757. protected $locator;
  758. protected $cache;
  759. public function __construct(FileLocatorInterface $locator, $cacheDir = null)
  760. {
  761. if (null !== $cacheDir && is_file($cache = $cacheDir.'/templates.php')) {
  762. $this->cache = require $cache;
  763. }
  764. $this->locator = $locator;
  765. }
  766. protected function getCacheKey($template)
  767. {
  768. return $template->getLogicalName();
  769. }
  770. public function locate($template, $currentPath = null, $first = true)
  771. {
  772. if (!$template instanceof TemplateReferenceInterface) {
  773. throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
  774. }
  775. $key = $this->getCacheKey($template);
  776. if (isset($this->cache[$key])) {
  777. return $this->cache[$key];
  778. }
  779. try {
  780. return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
  781. } catch (\InvalidArgumentException $e) {
  782. throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
  783. }
  784. }
  785. }
  786. }
  787. namespace Symfony\Component\Routing
  788. {
  789. interface RequestContextAwareInterface
  790. {
  791. public function setContext(RequestContext $context);
  792. public function getContext();
  793. }
  794. }
  795. namespace Symfony\Component\Routing\Generator
  796. {
  797. use Symfony\Component\Routing\Exception\InvalidParameterException;
  798. use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
  799. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  800. use Symfony\Component\Routing\RequestContextAwareInterface;
  801. interface UrlGeneratorInterface extends RequestContextAwareInterface
  802. {
  803. const ABSOLUTE_URL = true;
  804. const ABSOLUTE_PATH = false;
  805. const RELATIVE_PATH ='relative';
  806. const NETWORK_PATH ='network';
  807. public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH);
  808. }
  809. }
  810. namespace Symfony\Component\Routing\Generator
  811. {
  812. interface ConfigurableRequirementsInterface
  813. {
  814. public function setStrictRequirements($enabled);
  815. public function isStrictRequirements();
  816. }
  817. }
  818. namespace Symfony\Component\Routing\Generator
  819. {
  820. use Symfony\Component\Routing\RouteCollection;
  821. use Symfony\Component\Routing\RequestContext;
  822. use Symfony\Component\Routing\Exception\InvalidParameterException;
  823. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  824. use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
  825. use Psr\Log\LoggerInterface;
  826. class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface
  827. {
  828. protected $routes;
  829. protected $context;
  830. protected $strictRequirements = true;
  831. protected $logger;
  832. protected $decodedChars = array('%2F'=>'/','%40'=>'@','%3A'=>':','%3B'=>';','%2C'=>',','%3D'=>'=','%2B'=>'+','%21'=>'!','%2A'=>'*','%7C'=>'|',
  833. );
  834. public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null)
  835. {
  836. $this->routes = $routes;
  837. $this->context = $context;
  838. $this->logger = $logger;
  839. }
  840. public function setContext(RequestContext $context)
  841. {
  842. $this->context = $context;
  843. }
  844. public function getContext()
  845. {
  846. return $this->context;
  847. }
  848. public function setStrictRequirements($enabled)
  849. {
  850. $this->strictRequirements = null === $enabled ? null : (Boolean) $enabled;
  851. }
  852. public function isStrictRequirements()
  853. {
  854. return $this->strictRequirements;
  855. }
  856. public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
  857. {
  858. if (null === $route = $this->routes->get($name)) {
  859. throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
  860. }
  861. $compiledRoute = $route->compile();
  862. return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens());
  863. }
  864. protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens)
  865. {
  866. $variables = array_flip($variables);
  867. $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
  868. if ($diff = array_diff_key($variables, $mergedParams)) {
  869. throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', array_keys($diff)), $name));
  870. }
  871. $url ='';
  872. $optional = true;
  873. foreach ($tokens as $token) {
  874. if ('variable'=== $token[0]) {
  875. if (!$optional || !array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
  876. if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
  877. $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
  878. if ($this->strictRequirements) {
  879. throw new InvalidParameterException($message);
  880. }
  881. if ($this->logger) {
  882. $this->logger->error($message);
  883. }
  884. return null;
  885. }
  886. $url = $token[1].$mergedParams[$token[3]].$url;
  887. $optional = false;
  888. }
  889. } else {
  890. $url = $token[1].$url;
  891. $optional = false;
  892. }
  893. }
  894. if (''=== $url) {
  895. $url ='/';
  896. }
  897. $url = strtr(rawurlencode($url), $this->decodedChars);
  898. $url = strtr($url, array('/../'=>'/%2E%2E/','/./'=>'/%2E/'));
  899. if ('/..'=== substr($url, -3)) {
  900. $url = substr($url, 0, -2).'%2E%2E';
  901. } elseif ('/.'=== substr($url, -2)) {
  902. $url = substr($url, 0, -1).'%2E';
  903. }
  904. $schemeAuthority ='';
  905. if ($host = $this->context->getHost()) {
  906. $scheme = $this->context->getScheme();
  907. if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
  908. $referenceType = self::ABSOLUTE_URL;
  909. $scheme = $req;
  910. }
  911. if ($hostTokens) {
  912. $routeHost ='';
  913. foreach ($hostTokens as $token) {
  914. if ('variable'=== $token[0]) {
  915. if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
  916. $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
  917. if ($this->strictRequirements) {
  918. throw new InvalidParameterException($message);
  919. }
  920. if ($this->logger) {
  921. $this->logger->error($message);
  922. }
  923. return null;
  924. }
  925. $routeHost = $token[1].$mergedParams[$token[3]].$routeHost;
  926. } else {
  927. $routeHost = $token[1].$routeHost;
  928. }
  929. }
  930. if ($routeHost !== $host) {
  931. $host = $routeHost;
  932. if (self::ABSOLUTE_URL !== $referenceType) {
  933. $referenceType = self::NETWORK_PATH;
  934. }
  935. }
  936. }
  937. if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) {
  938. $port ='';
  939. if ('http'=== $scheme && 80 != $this->context->getHttpPort()) {
  940. $port =':'.$this->context->getHttpPort();
  941. } elseif ('https'=== $scheme && 443 != $this->context->getHttpsPort()) {
  942. $port =':'.$this->context->getHttpsPort();
  943. }
  944. $schemeAuthority = self::NETWORK_PATH === $referenceType ?'//': "$scheme://";
  945. $schemeAuthority .= $host.$port;
  946. }
  947. }
  948. if (self::RELATIVE_PATH === $referenceType) {
  949. $url = self::getRelativePath($this->context->getPathInfo(), $url);
  950. } else {
  951. $url = $schemeAuthority.$this->context->getBaseUrl().$url;
  952. }
  953. $extra = array_diff_key($parameters, $variables, $defaults);
  954. if ($extra && $query = http_build_query($extra,'','&')) {
  955. $url .='?'.$query;
  956. }
  957. return $url;
  958. }
  959. public static function getRelativePath($basePath, $targetPath)
  960. {
  961. if ($basePath === $targetPath) {
  962. return'';
  963. }
  964. $sourceDirs = explode('/', isset($basePath[0]) &&'/'=== $basePath[0] ? substr($basePath, 1) : $basePath);
  965. $targetDirs = explode('/', isset($targetPath[0]) &&'/'=== $targetPath[0] ? substr($targetPath, 1) : $targetPath);
  966. array_pop($sourceDirs);
  967. $targetFile = array_pop($targetDirs);
  968. foreach ($sourceDirs as $i => $dir) {
  969. if (isset($targetDirs[$i]) && $dir === $targetDirs[$i]) {
  970. unset($sourceDirs[$i], $targetDirs[$i]);
  971. } else {
  972. break;
  973. }
  974. }
  975. $targetDirs[] = $targetFile;
  976. $path = str_repeat('../', count($sourceDirs)).implode('/', $targetDirs);
  977. return''=== $path ||'/'=== $path[0]
  978. || false !== ($colonPos = strpos($path,':')) && ($colonPos < ($slashPos = strpos($path,'/')) || false === $slashPos)
  979. ? "./$path" : $path;
  980. }
  981. }
  982. }
  983. namespace Symfony\Component\Routing
  984. {
  985. use Symfony\Component\HttpFoundation\Request;
  986. class RequestContext
  987. {
  988. private $baseUrl;
  989. private $pathInfo;
  990. private $method;
  991. private $host;
  992. private $scheme;
  993. private $httpPort;
  994. private $httpsPort;
  995. private $queryString;
  996. private $parameters = array();
  997. public function __construct($baseUrl ='', $method ='GET', $host ='localhost', $scheme ='http', $httpPort = 80, $httpsPort = 443, $path ='/', $queryString ='')
  998. {
  999. $this->baseUrl = $baseUrl;
  1000. $this->method = strtoupper($method);
  1001. $this->host = $host;
  1002. $this->scheme = strtolower($scheme);
  1003. $this->httpPort = $httpPort;
  1004. $this->httpsPort = $httpsPort;
  1005. $this->pathInfo = $path;
  1006. $this->queryString = $queryString;
  1007. }
  1008. public function fromRequest(Request $request)
  1009. {
  1010. $this->setBaseUrl($request->getBaseUrl());
  1011. $this->setPathInfo($request->getPathInfo());
  1012. $this->setMethod($request->getMethod());
  1013. $this->setHost($request->getHost());
  1014. $this->setScheme($request->getScheme());
  1015. $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
  1016. $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
  1017. $this->setQueryString($request->server->get('QUERY_STRING'));
  1018. }
  1019. public function getBaseUrl()
  1020. {
  1021. return $this->baseUrl;
  1022. }
  1023. public function setBaseUrl($baseUrl)
  1024. {
  1025. $this->baseUrl = $baseUrl;
  1026. }
  1027. public function getPathInfo()
  1028. {
  1029. return $this->pathInfo;
  1030. }
  1031. public function setPathInfo($pathInfo)
  1032. {
  1033. $this->pathInfo = $pathInfo;
  1034. }
  1035. public function getMethod()
  1036. {
  1037. return $this->method;
  1038. }
  1039. public function setMethod($method)
  1040. {
  1041. $this->method = strtoupper($method);
  1042. }
  1043. public function getHost()
  1044. {
  1045. return $this->host;
  1046. }
  1047. public function setHost($host)
  1048. {
  1049. $this->host = $host;
  1050. }
  1051. public function getScheme()
  1052. {
  1053. return $this->scheme;
  1054. }
  1055. public function setScheme($scheme)
  1056. {
  1057. $this->scheme = strtolower($scheme);
  1058. }
  1059. public function getHttpPort()
  1060. {
  1061. return $this->httpPort;
  1062. }
  1063. public function setHttpPort($httpPort)
  1064. {
  1065. $this->httpPort = $httpPort;
  1066. }
  1067. public function getHttpsPort()
  1068. {
  1069. return $this->httpsPort;
  1070. }
  1071. public function setHttpsPort($httpsPort)
  1072. {
  1073. $this->httpsPort = $httpsPort;
  1074. }
  1075. public function getQueryString()
  1076. {
  1077. return $this->queryString;
  1078. }
  1079. public function setQueryString($queryString)
  1080. {
  1081. $this->queryString = $queryString;
  1082. }
  1083. public function getParameters()
  1084. {
  1085. return $this->parameters;
  1086. }
  1087. public function setParameters(array $parameters)
  1088. {
  1089. $this->parameters = $parameters;
  1090. return $this;
  1091. }
  1092. public function getParameter($name)
  1093. {
  1094. return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
  1095. }
  1096. public function hasParameter($name)
  1097. {
  1098. return array_key_exists($name, $this->parameters);
  1099. }
  1100. public function setParameter($name, $parameter)
  1101. {
  1102. $this->parameters[$name] = $parameter;
  1103. }
  1104. }
  1105. }
  1106. namespace Symfony\Component\Routing\Matcher
  1107. {
  1108. use Symfony\Component\Routing\RequestContextAwareInterface;
  1109. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1110. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  1111. interface UrlMatcherInterface extends RequestContextAwareInterface
  1112. {
  1113. public function match($pathinfo);
  1114. }
  1115. }
  1116. namespace Symfony\Component\Routing
  1117. {
  1118. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  1119. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  1120. interface RouterInterface extends UrlMatcherInterface, UrlGeneratorInterface
  1121. {
  1122. public function getRouteCollection();
  1123. }
  1124. }
  1125. namespace Symfony\Component\Routing
  1126. {
  1127. use Symfony\Component\Config\Loader\LoaderInterface;
  1128. use Symfony\Component\Config\ConfigCache;
  1129. use Psr\Log\LoggerInterface;
  1130. use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
  1131. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  1132. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  1133. class Router implements RouterInterface
  1134. {
  1135. protected $matcher;
  1136. protected $generator;
  1137. protected $context;
  1138. protected $loader;
  1139. protected $collection;
  1140. protected $resource;
  1141. protected $options = array();
  1142. protected $logger;
  1143. public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
  1144. {
  1145. $this->loader = $loader;
  1146. $this->resource = $resource;
  1147. $this->logger = $logger;
  1148. $this->context = null === $context ? new RequestContext() : $context;
  1149. $this->setOptions($options);
  1150. }
  1151. public function setOptions(array $options)
  1152. {
  1153. $this->options = array('cache_dir'=> null,'debug'=> false,'generator_class'=>'Symfony\\Component\\Routing\\Generator\\UrlGenerator','generator_base_class'=>'Symfony\\Component\\Routing\\Generator\\UrlGenerator','generator_dumper_class'=>'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper','generator_cache_class'=>'ProjectUrlGenerator','matcher_class'=>'Symfony\\Component\\Routing\\Matcher\\UrlMatcher','matcher_base_class'=>'Symfony\\Component\\Routing\\Matcher\\UrlMatcher','matcher_dumper_class'=>'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper','matcher_cache_class'=>'ProjectUrlMatcher','resource_type'=> null,'strict_requirements'=> true,
  1154. );
  1155. $invalid = array();
  1156. foreach ($options as $key => $value) {
  1157. if (array_key_exists($key, $this->options)) {
  1158. $this->options[$key] = $value;
  1159. } else {
  1160. $invalid[] = $key;
  1161. }
  1162. }
  1163. if ($invalid) {
  1164. throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('", "', $invalid)));
  1165. }
  1166. }
  1167. public function setOption($key, $value)
  1168. {
  1169. if (!array_key_exists($key, $this->options)) {
  1170. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
  1171. }
  1172. $this->options[$key] = $value;
  1173. }
  1174. public function getOption($key)
  1175. {
  1176. if (!array_key_exists($key, $this->options)) {
  1177. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
  1178. }
  1179. return $this->options[$key];
  1180. }
  1181. public function getRouteCollection()
  1182. {
  1183. if (null === $this->collection) {
  1184. $this->collection = $this->loader->load($this->resource, $this->options['resource_type']);
  1185. }
  1186. return $this->collection;
  1187. }
  1188. public function setContext(RequestContext $context)
  1189. {
  1190. $this->context = $context;
  1191. if (null !== $this->matcher) {
  1192. $this->getMatcher()->setContext($context);
  1193. }
  1194. if (null !== $this->generator) {
  1195. $this->getGenerator()->setContext($context);
  1196. }
  1197. }
  1198. public function getContext()
  1199. {
  1200. return $this->context;
  1201. }
  1202. public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
  1203. {
  1204. return $this->getGenerator()->generate($name, $parameters, $referenceType);
  1205. }
  1206. public function match($pathinfo)
  1207. {
  1208. return $this->getMatcher()->match($pathinfo);
  1209. }
  1210. public function getMatcher()
  1211. {
  1212. if (null !== $this->matcher) {
  1213. return $this->matcher;
  1214. }
  1215. if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
  1216. return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
  1217. }
  1218. $class = $this->options['matcher_cache_class'];
  1219. $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
  1220. if (!$cache->isFresh()) {
  1221. $dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
  1222. $options = array('class'=> $class,'base_class'=> $this->options['matcher_base_class'],
  1223. );
  1224. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  1225. }
  1226. require_once $cache;
  1227. return $this->matcher = new $class($this->context);
  1228. }
  1229. public function getGenerator()
  1230. {
  1231. if (null !== $this->generator) {
  1232. return $this->generator;
  1233. }
  1234. if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
  1235. $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->logger);
  1236. } else {
  1237. $class = $this->options['generator_cache_class'];
  1238. $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
  1239. if (!$cache->isFresh()) {
  1240. $dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
  1241. $options = array('class'=> $class,'base_class'=> $this->options['generator_base_class'],
  1242. );
  1243. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  1244. }
  1245. require_once $cache;
  1246. $this->generator = new $class($this->context, $this->logger);
  1247. }
  1248. if ($this->generator instanceof ConfigurableRequirementsInterface) {
  1249. $this->generator->setStrictRequirements($this->options['strict_requirements']);
  1250. }
  1251. return $this->generator;
  1252. }
  1253. }
  1254. }
  1255. namespace Symfony\Component\Routing\Matcher
  1256. {
  1257. interface RedirectableUrlMatcherInterface
  1258. {
  1259. public function redirect($path, $route, $scheme = null);
  1260. }
  1261. }
  1262. namespace Symfony\Component\Routing\Matcher
  1263. {
  1264. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  1265. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1266. use Symfony\Component\Routing\RouteCollection;
  1267. use Symfony\Component\Routing\RequestContext;
  1268. use Symfony\Component\Routing\Route;
  1269. class UrlMatcher implements UrlMatcherInterface
  1270. {
  1271. const REQUIREMENT_MATCH = 0;
  1272. const REQUIREMENT_MISMATCH = 1;
  1273. const ROUTE_MATCH = 2;
  1274. protected $context;
  1275. protected $allow = array();
  1276. protected $routes;
  1277. public function __construct(RouteCollection $routes, RequestContext $context)
  1278. {
  1279. $this->routes = $routes;
  1280. $this->context = $context;
  1281. }
  1282. public function setContext(RequestContext $context)
  1283. {
  1284. $this->context = $context;
  1285. }
  1286. public function getContext()
  1287. {
  1288. return $this->context;
  1289. }
  1290. public function match($pathinfo)
  1291. {
  1292. $this->allow = array();
  1293. if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
  1294. return $ret;
  1295. }
  1296. throw 0 < count($this->allow)
  1297. ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow)))
  1298. : new ResourceNotFoundException();
  1299. }
  1300. protected function matchCollection($pathinfo, RouteCollection $routes)
  1301. {
  1302. foreach ($routes as $name => $route) {
  1303. $compiledRoute = $route->compile();
  1304. if (''!== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
  1305. continue;
  1306. }
  1307. if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
  1308. continue;
  1309. }
  1310. $hostMatches = array();
  1311. if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
  1312. continue;
  1313. }
  1314. if ($req = $route->getRequirement('_method')) {
  1315. if ('HEAD'=== $method = $this->context->getMethod()) {
  1316. $method ='GET';
  1317. }
  1318. if (!in_array($method, $req = explode('|', strtoupper($req)))) {
  1319. $this->allow = array_merge($this->allow, $req);
  1320. continue;
  1321. }
  1322. }
  1323. $status = $this->handleRouteRequirements($pathinfo, $name, $route);
  1324. if (self::ROUTE_MATCH === $status[0]) {
  1325. return $status[1];
  1326. }
  1327. if (self::REQUIREMENT_MISMATCH === $status[0]) {
  1328. continue;
  1329. }
  1330. return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
  1331. }
  1332. }
  1333. protected function getAttributes(Route $route, $name, array $attributes)
  1334. {
  1335. $attributes['_route'] = $name;
  1336. return $this->mergeDefaults($attributes, $route->getDefaults());
  1337. }
  1338. protected function handleRouteRequirements($pathinfo, $name, Route $route)
  1339. {
  1340. $scheme = $route->getRequirement('_scheme');
  1341. $status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
  1342. return array($status, null);
  1343. }
  1344. protected function mergeDefaults($params, $defaults)
  1345. {
  1346. foreach ($params as $key => $value) {
  1347. if (!is_int($key)) {
  1348. $defaults[$key] = $value;
  1349. }
  1350. }
  1351. return $defaults;
  1352. }
  1353. }
  1354. }
  1355. namespace Symfony\Component\Routing\Matcher
  1356. {
  1357. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1358. use Symfony\Component\Routing\Route;
  1359. abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
  1360. {
  1361. public function match($pathinfo)
  1362. {
  1363. try {
  1364. $parameters = parent::match($pathinfo);
  1365. } catch (ResourceNotFoundException $e) {
  1366. if ('/'=== substr($pathinfo, -1) || !in_array($this->context->getMethod(), array('HEAD','GET'))) {
  1367. throw $e;
  1368. }
  1369. try {
  1370. parent::match($pathinfo.'/');
  1371. return $this->redirect($pathinfo.'/', null);
  1372. } catch (ResourceNotFoundException $e2) {
  1373. throw $e;
  1374. }
  1375. }
  1376. return $parameters;
  1377. }
  1378. protected function handleRouteRequirements($pathinfo, $name, Route $route)
  1379. {
  1380. $scheme = $route->getRequirement('_scheme');
  1381. if ($scheme && $this->context->getScheme() !== $scheme) {
  1382. return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
  1383. }
  1384. return array(self::REQUIREMENT_MATCH, null);
  1385. }
  1386. }
  1387. }
  1388. namespace Symfony\Bundle\FrameworkBundle\Routing
  1389. {
  1390. use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
  1391. class RedirectableUrlMatcher extends BaseMatcher
  1392. {
  1393. public function redirect($path, $route, $scheme = null)
  1394. {
  1395. return array('_controller'=>'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction','path'=> $path,'permanent'=> true,'scheme'=> $scheme,'httpPort'=> $this->context->getHttpPort(),'httpsPort'=> $this->context->getHttpsPort(),'_route'=> $route,
  1396. );
  1397. }
  1398. }
  1399. }
  1400. namespace Symfony\Component\HttpKernel\CacheWarmer
  1401. {
  1402. interface WarmableInterface
  1403. {
  1404. public function warmUp($cacheDir);
  1405. }
  1406. }
  1407. namespace Symfony\Bundle\FrameworkBundle\Routing
  1408. {
  1409. use Symfony\Component\Routing\Router as BaseRouter;
  1410. use Symfony\Component\Routing\RequestContext;
  1411. use Symfony\Component\DependencyInjection\ContainerInterface;
  1412. use Symfony\Component\Routing\RouteCollection;
  1413. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  1414. use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
  1415. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  1416. class Router extends BaseRouter implements WarmableInterface
  1417. {
  1418. private $container;
  1419. public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
  1420. {
  1421. $this->container = $container;
  1422. $this->resource = $resource;
  1423. $this->context = null === $context ? new RequestContext() : $context;
  1424. $this->setOptions($options);
  1425. }
  1426. public function getRouteCollection()
  1427. {
  1428. if (null === $this->collection) {
  1429. $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
  1430. $this->resolveParameters($this->collection);
  1431. }
  1432. return $this->collection;
  1433. }
  1434. public function warmUp($cacheDir)
  1435. {
  1436. $currentDir = $this->getOption('cache_dir');
  1437. $this->setOption('cache_dir', $cacheDir);
  1438. $this->getMatcher();
  1439. $this->getGenerator();
  1440. $this->setOption('cache_dir', $currentDir);
  1441. }
  1442. private function resolveParameters(RouteCollection $collection)
  1443. {
  1444. foreach ($collection as $route) {
  1445. foreach ($route->getDefaults() as $name => $value) {
  1446. $route->setDefault($name, $this->resolve($value));
  1447. }
  1448. foreach ($route->getRequirements() as $name => $value) {
  1449. $route->setRequirement($name, $this->resolve($value));
  1450. }
  1451. $route->setPath($this->resolve($route->getPath()));
  1452. $route->setHost($this->resolve($route->getHost()));
  1453. }
  1454. }
  1455. private function resolve($value)
  1456. {
  1457. if (is_array($value)) {
  1458. foreach ($value as $key => $val) {
  1459. $value[$key] = $this->resolve($val);
  1460. }
  1461. return $value;
  1462. }
  1463. if (!is_string($value)) {
  1464. return $value;
  1465. }
  1466. $container = $this->container;
  1467. $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) {
  1468. if (!isset($match[1])) {
  1469. return'%%';
  1470. }
  1471. $resolved = $container->getParameter($match[1]);
  1472. if (is_string($resolved) || is_numeric($resolved)) {
  1473. return (string) $resolved;
  1474. }
  1475. throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", '.'must be a string or numeric, but it is of type %s.',
  1476. $match[1],
  1477. $value,
  1478. gettype($resolved)
  1479. )
  1480. );
  1481. }, $value);
  1482. return str_replace('%%','%', $escapedValue);
  1483. }
  1484. }
  1485. }
  1486. namespace Symfony\Component\Config
  1487. {
  1488. class FileLocator implements FileLocatorInterface
  1489. {
  1490. protected $paths;
  1491. public function __construct($paths = array())
  1492. {
  1493. $this->paths = (array) $paths;
  1494. }
  1495. public function locate($name, $currentPath = null, $first = true)
  1496. {
  1497. if ($this->isAbsolutePath($name)) {
  1498. if (!file_exists($name)) {
  1499. throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
  1500. }
  1501. return $name;
  1502. }
  1503. $filepaths = array();
  1504. if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
  1505. if (true === $first) {
  1506. return $file;
  1507. }
  1508. $filepaths[] = $file;
  1509. }
  1510. foreach ($this->paths as $path) {
  1511. if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
  1512. if (true === $first) {
  1513. return $file;
  1514. }
  1515. $filepaths[] = $file;
  1516. }
  1517. }
  1518. if (!$filepaths) {
  1519. throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ':'', implode(', ', $this->paths)));
  1520. }
  1521. return array_values(array_unique($filepaths));
  1522. }
  1523. private function isAbsolutePath($file)
  1524. {
  1525. if ($file[0] =='/'|| $file[0] =='\\'|| (strlen($file) > 3 && ctype_alpha($file[0])
  1526. && $file[1] ==':'&& ($file[2] =='\\'|| $file[2] =='/')
  1527. )
  1528. || null !== parse_url($file, PHP_URL_SCHEME)
  1529. ) {
  1530. return true;
  1531. }
  1532. return false;
  1533. }
  1534. }
  1535. }
  1536. namespace Symfony\Component\EventDispatcher
  1537. {
  1538. class Event
  1539. {
  1540. private $propagationStopped = false;
  1541. private $dispatcher;
  1542. private $name;
  1543. public function isPropagationStopped()
  1544. {
  1545. return $this->propagationStopped;
  1546. }
  1547. public function stopPropagation()
  1548. {
  1549. $this->propagationStopped = true;
  1550. }
  1551. public function setDispatcher(EventDispatcherInterface $dispatcher)
  1552. {
  1553. $this->dispatcher = $dispatcher;
  1554. }
  1555. public function getDispatcher()
  1556. {
  1557. return $this->dispatcher;
  1558. }
  1559. public function getName()
  1560. {
  1561. return $this->name;
  1562. }
  1563. public function setName($name)
  1564. {
  1565. $this->name = $name;
  1566. }
  1567. }
  1568. }
  1569. namespace Symfony\Component\EventDispatcher
  1570. {
  1571. interface EventDispatcherInterface
  1572. {
  1573. public function dispatch($eventName, Event $event = null);
  1574. public function addListener($eventName, $listener, $priority = 0);
  1575. public function addSubscriber(EventSubscriberInterface $subscriber);
  1576. public function removeListener($eventName, $listener);
  1577. public function removeSubscriber(EventSubscriberInterface $subscriber);
  1578. public function getListeners($eventName = null);
  1579. public function hasListeners($eventName = null);
  1580. }
  1581. }
  1582. namespace Symfony\Component\EventDispatcher
  1583. {
  1584. class EventDispatcher implements EventDispatcherInterface
  1585. {
  1586. private $listeners = array();
  1587. private $sorted = array();
  1588. public function dispatch($eventName, Event $event = null)
  1589. {
  1590. if (null === $event) {
  1591. $event = new Event();
  1592. }
  1593. $event->setDispatcher($this);
  1594. $event->setName($eventName);
  1595. if (!isset($this->listeners[$eventName])) {
  1596. return $event;
  1597. }
  1598. $this->doDispatch($this->getListeners($eventName), $eventName, $event);
  1599. return $event;
  1600. }
  1601. public function getListeners($eventName = null)
  1602. {
  1603. if (null !== $eventName) {
  1604. if (!isset($this->sorted[$eventName])) {
  1605. $this->sortListeners($eventName);
  1606. }
  1607. return $this->sorted[$eventName];
  1608. }
  1609. foreach (array_keys($this->listeners) as $eventName) {
  1610. if (!isset($this->sorted[$eventName])) {
  1611. $this->sortListeners($eventName);
  1612. }
  1613. }
  1614. return $this->sorted;
  1615. }
  1616. public function hasListeners($eventName = null)
  1617. {
  1618. return (Boolean) count($this->getListeners($eventName));
  1619. }
  1620. public function addListener($eventName, $listener, $priority = 0)
  1621. {
  1622. $this->listeners[$eventName][$priority][] = $listener;
  1623. unset($this->sorted[$eventName]);
  1624. }
  1625. public function removeListener($eventName, $listener)
  1626. {
  1627. if (!isset($this->listeners[$eventName])) {
  1628. return;
  1629. }
  1630. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  1631. if (false !== ($key = array_search($listener, $listeners, true))) {
  1632. unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
  1633. }
  1634. }
  1635. }
  1636. public function addSubscriber(EventSubscriberInterface $subscriber)
  1637. {
  1638. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  1639. if (is_string($params)) {
  1640. $this->addListener($eventName, array($subscriber, $params));
  1641. } elseif (is_string($params[0])) {
  1642. $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
  1643. } else {
  1644. foreach ($params as $listener) {
  1645. $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
  1646. }
  1647. }
  1648. }
  1649. }
  1650. public function removeSubscriber(EventSubscriberInterface $subscriber)
  1651. {
  1652. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  1653. if (is_array($params) && is_array($params[0])) {
  1654. foreach ($params as $listener) {
  1655. $this->removeListener($eventName, array($subscriber, $listener[0]));
  1656. }
  1657. } else {
  1658. $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
  1659. }
  1660. }
  1661. }
  1662. protected function doDispatch($listeners, $eventName, Event $event)
  1663. {
  1664. foreach ($listeners as $listener) {
  1665. call_user_func($listener, $event);
  1666. if ($event->isPropagationStopped()) {
  1667. break;
  1668. }
  1669. }
  1670. }
  1671. private function sortListeners($eventName)
  1672. {
  1673. $this->sorted[$eventName] = array();
  1674. if (isset($this->listeners[$eventName])) {
  1675. krsort($this->listeners[$eventName]);
  1676. $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
  1677. }
  1678. }
  1679. }
  1680. }
  1681. namespace Symfony\Component\EventDispatcher
  1682. {
  1683. use Symfony\Component\DependencyInjection\ContainerInterface;
  1684. class ContainerAwareEventDispatcher extends EventDispatcher
  1685. {
  1686. private $container;
  1687. private $listenerIds = array();
  1688. private $listeners = array();
  1689. public function __construct(ContainerInterface $container)
  1690. {
  1691. $this->container = $container;
  1692. }
  1693. public function addListenerService($eventName, $callback, $priority = 0)
  1694. {
  1695. if (!is_array($callback) || 2 !== count($callback)) {
  1696. throw new \InvalidArgumentException('Expected an array("service", "method") argument');
  1697. }
  1698. $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
  1699. }
  1700. public function removeListener($eventName, $listener)
  1701. {
  1702. $this->lazyLoad($eventName);
  1703. if (isset($this->listeners[$eventName])) {
  1704. foreach ($this->listeners[$eventName] as $key =>

Large files files are truncated, but you can click here to view the full file