PageRenderTime 66ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/app/cache/dev/classes.php

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

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