PageRenderTime 71ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/app/cache/prod/classes.php

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

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