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

/app/cache/dev/classes.php

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

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