PageRenderTime 87ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 2ms

/app/cache/dev/classes.php

https://github.com/RomainTweaks/BaseSymfony2
PHP | 7549 lines | 7549 code | 0 blank | 0 comment | 955 complexity | 92b56a0888bf12d0173218f9bf41456a MD5 | raw file
Possible License(s): BSD-3-Clause

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

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

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