PageRenderTime 64ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 1ms

/app/cache/dev/classes.php

https://bitbucket.org/polipetr/cms
PHP | 10686 lines | 7027 code | 2355 blank | 1304 comment | 903 complexity | cef9856e75cbacf1883e769170a0751e MD5 | raw file
Possible License(s): Apache-2.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(
  192. 'cache_limiter', 'cookie_domain', 'cookie_httponly',
  193. 'cookie_lifetime', 'cookie_path', 'cookie_secure',
  194. 'entropy_file', 'entropy_length', 'gc_divisor',
  195. 'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character',
  196. 'hash_function', 'name', 'referer_check',
  197. 'serialize_handler', 'use_cookies',
  198. 'use_only_cookies', 'use_trans_sid', 'upload_progress.enabled',
  199. 'upload_progress.cleanup', 'upload_progress.prefix', 'upload_progress.name',
  200. 'upload_progress.freq', 'upload_progress.min-freq', 'url_rewriter.tags',
  201. ));
  202. foreach ($options as $key => $value) {
  203. if (isset($validOptions[$key])) {
  204. ini_set('session.'.$key, $value);
  205. }
  206. }
  207. }
  208. public function setSaveHandler($saveHandler = null)
  209. {
  210. if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
  211. $saveHandler = new SessionHandlerProxy($saveHandler);
  212. } elseif (!$saveHandler instanceof AbstractProxy) {
  213. $saveHandler = new NativeProxy();
  214. }
  215. $this->saveHandler = $saveHandler;
  216. if ($this->saveHandler instanceof \SessionHandlerInterface) {
  217. if (version_compare(phpversion(), '5.4.0', '>=')) {
  218. session_set_save_handler($this->saveHandler, false);
  219. } else {
  220. session_set_save_handler(
  221. array($this->saveHandler, 'open'),
  222. array($this->saveHandler, 'close'),
  223. array($this->saveHandler, 'read'),
  224. array($this->saveHandler, 'write'),
  225. array($this->saveHandler, 'destroy'),
  226. array($this->saveHandler, 'gc')
  227. );
  228. }
  229. }
  230. }
  231. protected function loadSession(array &$session = null)
  232. {
  233. if (null === $session) {
  234. $session = &$_SESSION;
  235. }
  236. $bags = array_merge($this->bags, array($this->metadataBag));
  237. foreach ($bags as $bag) {
  238. $key = $bag->getStorageKey();
  239. $session[$key] = isset($session[$key]) ? $session[$key] : array();
  240. $bag->initialize($session[$key]);
  241. }
  242. $this->started = true;
  243. $this->closed = false;
  244. }
  245. }
  246. }
  247. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  248. {
  249. if (version_compare(phpversion(), '5.4.0', '>=')) {
  250. class NativeSessionHandler extends \SessionHandler {}
  251. } else {
  252. class NativeSessionHandler {}
  253. }
  254. }
  255. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  256. {
  257. class NativeFileSessionHandler extends NativeSessionHandler
  258. {
  259. public function __construct($savePath = null)
  260. {
  261. if (null === $savePath) {
  262. $savePath = ini_get('session.save_path');
  263. }
  264. $baseDir = $savePath;
  265. if ($count = substr_count($savePath, ';')) {
  266. if ($count > 2) {
  267. throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
  268. }
  269. $baseDir = ltrim(strrchr($savePath, ';'), ';');
  270. }
  271. if ($baseDir && !is_dir($baseDir)) {
  272. mkdir($baseDir, 0777, true);
  273. }
  274. ini_set('session.save_path', $savePath);
  275. ini_set('session.save_handler', 'files');
  276. }
  277. }
  278. }
  279. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  280. {
  281. abstract class AbstractProxy
  282. {
  283. protected $wrapper = false;
  284. protected $active = false;
  285. protected $saveHandlerName;
  286. public function getSaveHandlerName()
  287. {
  288. return $this->saveHandlerName;
  289. }
  290. public function isSessionHandlerInterface()
  291. {
  292. return ($this instanceof \SessionHandlerInterface);
  293. }
  294. public function isWrapper()
  295. {
  296. return $this->wrapper;
  297. }
  298. public function isActive()
  299. {
  300. return $this->active;
  301. }
  302. public function setActive($flag)
  303. {
  304. $this->active = (bool) $flag;
  305. }
  306. public function getId()
  307. {
  308. return session_id();
  309. }
  310. public function setId($id)
  311. {
  312. if ($this->isActive()) {
  313. throw new \LogicException('Cannot change the ID of an active session');
  314. }
  315. session_id($id);
  316. }
  317. public function getName()
  318. {
  319. return session_name();
  320. }
  321. public function setName($name)
  322. {
  323. if ($this->isActive()) {
  324. throw new \LogicException('Cannot change the name of an active session');
  325. }
  326. session_name($name);
  327. }
  328. }
  329. }
  330. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  331. {
  332. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
  333. {
  334. protected $handler;
  335. public function __construct(\SessionHandlerInterface $handler)
  336. {
  337. $this->handler = $handler;
  338. $this->wrapper = ($handler instanceof \SessionHandler);
  339. $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') : 'user';
  340. }
  341. public function open($savePath, $sessionName)
  342. {
  343. $return = (bool) $this->handler->open($savePath, $sessionName);
  344. if (true === $return) {
  345. $this->active = true;
  346. }
  347. return $return;
  348. }
  349. public function close()
  350. {
  351. $this->active = false;
  352. return (bool) $this->handler->close();
  353. }
  354. public function read($id)
  355. {
  356. return (string) $this->handler->read($id);
  357. }
  358. public function write($id, $data)
  359. {
  360. return (bool) $this->handler->write($id, $data);
  361. }
  362. public function destroy($id)
  363. {
  364. return (bool) $this->handler->destroy($id);
  365. }
  366. public function gc($maxlifetime)
  367. {
  368. return (bool) $this->handler->gc($maxlifetime);
  369. }
  370. }
  371. }
  372. namespace Symfony\Component\HttpFoundation\Session
  373. {
  374. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  375. interface SessionInterface
  376. {
  377. public function start();
  378. public function getId();
  379. public function setId($id);
  380. public function getName();
  381. public function setName($name);
  382. public function invalidate($lifetime = null);
  383. public function migrate($destroy = false, $lifetime = null);
  384. public function save();
  385. public function has($name);
  386. public function get($name, $default = null);
  387. public function set($name, $value);
  388. public function all();
  389. public function replace(array $attributes);
  390. public function remove($name);
  391. public function clear();
  392. public function isStarted();
  393. public function registerBag(SessionBagInterface $bag);
  394. public function getBag($name);
  395. public function getMetadataBag();
  396. }
  397. }
  398. namespace Symfony\Component\HttpFoundation\Session
  399. {
  400. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  401. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  402. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  403. use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  404. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  405. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  406. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  407. class Session implements SessionInterface, \IteratorAggregate, \Countable
  408. {
  409. protected $storage;
  410. private $flashName;
  411. private $attributeName;
  412. public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
  413. {
  414. $this->storage = $storage ?: new NativeSessionStorage();
  415. $attributes = $attributes ?: new AttributeBag();
  416. $this->attributeName = $attributes->getName();
  417. $this->registerBag($attributes);
  418. $flashes = $flashes ?: new FlashBag();
  419. $this->flashName = $flashes->getName();
  420. $this->registerBag($flashes);
  421. }
  422. public function start()
  423. {
  424. return $this->storage->start();
  425. }
  426. public function has($name)
  427. {
  428. return $this->storage->getBag($this->attributeName)->has($name);
  429. }
  430. public function get($name, $default = null)
  431. {
  432. return $this->storage->getBag($this->attributeName)->get($name, $default);
  433. }
  434. public function set($name, $value)
  435. {
  436. $this->storage->getBag($this->attributeName)->set($name, $value);
  437. }
  438. public function all()
  439. {
  440. return $this->storage->getBag($this->attributeName)->all();
  441. }
  442. public function replace(array $attributes)
  443. {
  444. $this->storage->getBag($this->attributeName)->replace($attributes);
  445. }
  446. public function remove($name)
  447. {
  448. return $this->storage->getBag($this->attributeName)->remove($name);
  449. }
  450. public function clear()
  451. {
  452. $this->storage->getBag($this->attributeName)->clear();
  453. }
  454. public function isStarted()
  455. {
  456. return $this->storage->isStarted();
  457. }
  458. public function getIterator()
  459. {
  460. return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
  461. }
  462. public function count()
  463. {
  464. return count($this->storage->getBag($this->attributeName)->all());
  465. }
  466. public function invalidate($lifetime = null)
  467. {
  468. $this->storage->clear();
  469. return $this->migrate(true, $lifetime);
  470. }
  471. public function migrate($destroy = false, $lifetime = null)
  472. {
  473. return $this->storage->regenerate($destroy, $lifetime);
  474. }
  475. public function save()
  476. {
  477. $this->storage->save();
  478. }
  479. public function getId()
  480. {
  481. return $this->storage->getId();
  482. }
  483. public function setId($id)
  484. {
  485. $this->storage->setId($id);
  486. }
  487. public function getName()
  488. {
  489. return $this->storage->getName();
  490. }
  491. public function setName($name)
  492. {
  493. $this->storage->setName($name);
  494. }
  495. public function getMetadataBag()
  496. {
  497. return $this->storage->getMetadataBag();
  498. }
  499. public function registerBag(SessionBagInterface $bag)
  500. {
  501. $this->storage->registerBag($bag);
  502. }
  503. public function getBag($name)
  504. {
  505. return $this->storage->getBag($name);
  506. }
  507. public function getFlashBag()
  508. {
  509. return $this->getBag($this->flashName);
  510. }
  511. public function getFlashes()
  512. {
  513. $all = $this->getBag($this->flashName)->all();
  514. $return = array();
  515. if ($all) {
  516. foreach ($all as $name => $array) {
  517. if (is_numeric(key($array))) {
  518. $return[$name] = reset($array);
  519. } else {
  520. $return[$name] = $array;
  521. }
  522. }
  523. }
  524. return $return;
  525. }
  526. public function setFlashes($values)
  527. {
  528. foreach ($values as $name => $value) {
  529. $this->getBag($this->flashName)->set($name, $value);
  530. }
  531. }
  532. public function getFlash($name, $default = null)
  533. {
  534. $return = $this->getBag($this->flashName)->get($name);
  535. return empty($return) ? $default : reset($return);
  536. }
  537. public function setFlash($name, $value)
  538. {
  539. $this->getBag($this->flashName)->set($name, $value);
  540. }
  541. public function hasFlash($name)
  542. {
  543. return $this->getBag($this->flashName)->has($name);
  544. }
  545. public function removeFlash($name)
  546. {
  547. $this->getBag($this->flashName)->get($name);
  548. }
  549. public function clearFlashes()
  550. {
  551. return $this->getBag($this->flashName)->clear();
  552. }
  553. }
  554. }
  555. namespace Symfony\Component\Routing
  556. {
  557. interface RequestContextAwareInterface
  558. {
  559. public function setContext(RequestContext $context);
  560. public function getContext();
  561. }
  562. }
  563. namespace Symfony\Component\Routing\Generator
  564. {
  565. use Symfony\Component\Routing\RequestContextAwareInterface;
  566. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  567. interface UrlGeneratorInterface extends RequestContextAwareInterface
  568. {
  569. public function generate($name, $parameters = array(), $absolute = false);
  570. }
  571. }
  572. namespace Symfony\Component\Routing\Generator
  573. {
  574. interface ConfigurableRequirementsInterface
  575. {
  576. public function setStrictRequirements($enabled);
  577. public function isStrictRequirements();
  578. }
  579. }
  580. namespace Symfony\Component\Routing\Generator
  581. {
  582. use Symfony\Component\Routing\RouteCollection;
  583. use Symfony\Component\Routing\RequestContext;
  584. use Symfony\Component\Routing\Exception\InvalidParameterException;
  585. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  586. use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
  587. use Symfony\Component\HttpKernel\Log\LoggerInterface;
  588. class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface
  589. {
  590. protected $context;
  591. protected $strictRequirements = true;
  592. protected $logger;
  593. protected $decodedChars = array(
  594. '%2F' => '/',
  595. '%40' => '@',
  596. '%3A' => ':',
  597. '%3B' => ';',
  598. '%2C' => ',',
  599. '%3D' => '=',
  600. '%2B' => '+',
  601. '%21' => '!',
  602. '%2A' => '*',
  603. '%7C' => '|',
  604. );
  605. protected $routes;
  606. public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null)
  607. {
  608. $this->routes = $routes;
  609. $this->context = $context;
  610. $this->logger = $logger;
  611. }
  612. public function setContext(RequestContext $context)
  613. {
  614. $this->context = $context;
  615. }
  616. public function getContext()
  617. {
  618. return $this->context;
  619. }
  620. public function setStrictRequirements($enabled)
  621. {
  622. $this->strictRequirements = (Boolean) $enabled;
  623. }
  624. public function isStrictRequirements()
  625. {
  626. return $this->strictRequirements;
  627. }
  628. public function generate($name, $parameters = array(), $absolute = false)
  629. {
  630. if (null === $route = $this->routes->get($name)) {
  631. throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
  632. }
  633. $compiledRoute = $route->compile();
  634. return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $absolute);
  635. }
  636. protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute)
  637. {
  638. $variables = array_flip($variables);
  639. $originParameters = $parameters;
  640. $parameters = array_replace($this->context->getParameters(), $parameters);
  641. $tparams = array_replace($defaults, $parameters);
  642. if ($diff = array_diff_key($variables, $tparams)) {
  643. throw new MissingMandatoryParametersException(sprintf('The "%s" route has some missing mandatory parameters ("%s").', $name, implode('", "', array_keys($diff))));
  644. }
  645. $url = '';
  646. $optional = true;
  647. foreach ($tokens as $token) {
  648. if ('variable' === $token[0]) {
  649. if (false === $optional || !array_key_exists($token[3], $defaults) || (isset($parameters[$token[3]]) && (string) $parameters[$token[3]] != (string) $defaults[$token[3]])) {
  650. if (!$isEmpty = in_array($tparams[$token[3]], array(null, '', false), true)) {
  651. if ($tparams[$token[3]] && !preg_match('#^'.$token[2].'$#', $tparams[$token[3]])) {
  652. $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $tparams[$token[3]]);
  653. if ($this->strictRequirements) {
  654. throw new InvalidParameterException($message);
  655. }
  656. if ($this->logger) {
  657. $this->logger->err($message);
  658. }
  659. return null;
  660. }
  661. }
  662. if (!$isEmpty || !$optional) {
  663. $url = $token[1].$tparams[$token[3]].$url;
  664. }
  665. $optional = false;
  666. }
  667. } elseif ('text' === $token[0]) {
  668. $url = $token[1].$url;
  669. $optional = false;
  670. }
  671. }
  672. if ('' === $url) {
  673. $url = '/';
  674. }
  675. $url = $this->context->getBaseUrl().strtr(rawurlencode($url), $this->decodedChars);
  676. $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
  677. if ('/..' === substr($url, -3)) {
  678. $url = substr($url, 0, -2) . '%2E%2E';
  679. } elseif ('/.' === substr($url, -2)) {
  680. $url = substr($url, 0, -1) . '%2E';
  681. }
  682. $extra = array_diff_key($originParameters, $variables, $defaults);
  683. if ($extra && $query = http_build_query($extra, '', '&')) {
  684. $url .= '?'.$query;
  685. }
  686. if ($this->context->getHost()) {
  687. $scheme = $this->context->getScheme();
  688. if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme != $req) {
  689. $absolute = true;
  690. $scheme = $req;
  691. }
  692. if ($absolute) {
  693. $port = '';
  694. if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
  695. $port = ':'.$this->context->getHttpPort();
  696. } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
  697. $port = ':'.$this->context->getHttpsPort();
  698. }
  699. $url = $scheme.'://'.$this->context->getHost().$port.$url;
  700. }
  701. }
  702. return $url;
  703. }
  704. }
  705. }
  706. namespace Symfony\Component\Routing
  707. {
  708. use Symfony\Component\HttpFoundation\Request;
  709. class RequestContext
  710. {
  711. private $baseUrl;
  712. private $method;
  713. private $host;
  714. private $scheme;
  715. private $httpPort;
  716. private $httpsPort;
  717. private $parameters;
  718. public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443)
  719. {
  720. $this->baseUrl = $baseUrl;
  721. $this->method = strtoupper($method);
  722. $this->host = $host;
  723. $this->scheme = strtolower($scheme);
  724. $this->httpPort = $httpPort;
  725. $this->httpsPort = $httpsPort;
  726. $this->parameters = array();
  727. }
  728. public function fromRequest(Request $request)
  729. {
  730. $this->setBaseUrl($request->getBaseUrl());
  731. $this->setMethod($request->getMethod());
  732. $this->setHost($request->getHost());
  733. $this->setScheme($request->getScheme());
  734. $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
  735. $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
  736. }
  737. public function getBaseUrl()
  738. {
  739. return $this->baseUrl;
  740. }
  741. public function setBaseUrl($baseUrl)
  742. {
  743. $this->baseUrl = $baseUrl;
  744. }
  745. public function getMethod()
  746. {
  747. return $this->method;
  748. }
  749. public function setMethod($method)
  750. {
  751. $this->method = strtoupper($method);
  752. }
  753. public function getHost()
  754. {
  755. return $this->host;
  756. }
  757. public function setHost($host)
  758. {
  759. $this->host = $host;
  760. }
  761. public function getScheme()
  762. {
  763. return $this->scheme;
  764. }
  765. public function setScheme($scheme)
  766. {
  767. $this->scheme = strtolower($scheme);
  768. }
  769. public function getHttpPort()
  770. {
  771. return $this->httpPort;
  772. }
  773. public function setHttpPort($httpPort)
  774. {
  775. $this->httpPort = $httpPort;
  776. }
  777. public function getHttpsPort()
  778. {
  779. return $this->httpsPort;
  780. }
  781. public function setHttpsPort($httpsPort)
  782. {
  783. $this->httpsPort = $httpsPort;
  784. }
  785. public function getParameters()
  786. {
  787. return $this->parameters;
  788. }
  789. public function setParameters(array $parameters)
  790. {
  791. $this->parameters = $parameters;
  792. return $this;
  793. }
  794. public function getParameter($name)
  795. {
  796. return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
  797. }
  798. public function hasParameter($name)
  799. {
  800. return array_key_exists($name, $this->parameters);
  801. }
  802. public function setParameter($name, $parameter)
  803. {
  804. $this->parameters[$name] = $parameter;
  805. }
  806. }
  807. }
  808. namespace Symfony\Component\Routing\Matcher
  809. {
  810. use Symfony\Component\Routing\RequestContextAwareInterface;
  811. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  812. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  813. interface UrlMatcherInterface extends RequestContextAwareInterface
  814. {
  815. public function match($pathinfo);
  816. }
  817. }
  818. namespace Symfony\Component\Routing
  819. {
  820. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  821. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  822. interface RouterInterface extends UrlMatcherInterface, UrlGeneratorInterface
  823. {
  824. public function getRouteCollection();
  825. }
  826. }
  827. namespace Symfony\Component\Routing
  828. {
  829. use Symfony\Component\Config\Loader\LoaderInterface;
  830. use Symfony\Component\Config\ConfigCache;
  831. use Symfony\Component\HttpKernel\Log\LoggerInterface;
  832. use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
  833. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  834. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  835. class Router implements RouterInterface
  836. {
  837. protected $matcher;
  838. protected $generator;
  839. protected $context;
  840. protected $loader;
  841. protected $collection;
  842. protected $resource;
  843. protected $options;
  844. protected $logger;
  845. public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
  846. {
  847. $this->loader = $loader;
  848. $this->resource = $resource;
  849. $this->logger = $logger;
  850. $this->context = null === $context ? new RequestContext() : $context;
  851. $this->setOptions($options);
  852. }
  853. public function setOptions(array $options)
  854. {
  855. $this->options = array(
  856. 'cache_dir' => null,
  857. 'debug' => false,
  858. 'generator_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
  859. 'generator_base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
  860. 'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper',
  861. 'generator_cache_class' => 'ProjectUrlGenerator',
  862. 'matcher_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
  863. 'matcher_base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
  864. 'matcher_dumper_class' => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper',
  865. 'matcher_cache_class' => 'ProjectUrlMatcher',
  866. 'resource_type' => null,
  867. 'strict_requirements' => true,
  868. );
  869. $invalid = array();
  870. foreach ($options as $key => $value) {
  871. if (array_key_exists($key, $this->options)) {
  872. $this->options[$key] = $value;
  873. } else {
  874. $invalid[] = $key;
  875. }
  876. }
  877. if ($invalid) {
  878. throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('\', \'', $invalid)));
  879. }
  880. }
  881. public function setOption($key, $value)
  882. {
  883. if (!array_key_exists($key, $this->options)) {
  884. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
  885. }
  886. $this->options[$key] = $value;
  887. }
  888. public function getOption($key)
  889. {
  890. if (!array_key_exists($key, $this->options)) {
  891. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
  892. }
  893. return $this->options[$key];
  894. }
  895. public function getRouteCollection()
  896. {
  897. if (null === $this->collection) {
  898. $this->collection = $this->loader->load($this->resource, $this->options['resource_type']);
  899. }
  900. return $this->collection;
  901. }
  902. public function setContext(RequestContext $context)
  903. {
  904. $this->context = $context;
  905. if (null !== $this->matcher) {
  906. $this->getMatcher()->setContext($context);
  907. }
  908. if (null !== $this->generator) {
  909. $this->getGenerator()->setContext($context);
  910. }
  911. }
  912. public function getContext()
  913. {
  914. return $this->context;
  915. }
  916. public function generate($name, $parameters = array(), $absolute = false)
  917. {
  918. return $this->getGenerator()->generate($name, $parameters, $absolute);
  919. }
  920. public function match($pathinfo)
  921. {
  922. return $this->getMatcher()->match($pathinfo);
  923. }
  924. public function getMatcher()
  925. {
  926. if (null !== $this->matcher) {
  927. return $this->matcher;
  928. }
  929. if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
  930. return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
  931. }
  932. $class = $this->options['matcher_cache_class'];
  933. $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
  934. if (!$cache->isFresh($class)) {
  935. $dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
  936. $options = array(
  937. 'class' => $class,
  938. 'base_class' => $this->options['matcher_base_class'],
  939. );
  940. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  941. }
  942. require_once $cache;
  943. return $this->matcher = new $class($this->context);
  944. }
  945. public function getGenerator()
  946. {
  947. if (null !== $this->generator) {
  948. return $this->generator;
  949. }
  950. if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
  951. $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->logger);
  952. } else {
  953. $class = $this->options['generator_cache_class'];
  954. $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
  955. if (!$cache->isFresh($class)) {
  956. $dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
  957. $options = array(
  958. 'class' => $class,
  959. 'base_class' => $this->options['generator_base_class'],
  960. );
  961. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  962. }
  963. require_once $cache;
  964. $this->generator = new $class($this->context, $this->logger);
  965. }
  966. if ($this->generator instanceof ConfigurableRequirementsInterface) {
  967. $this->generator->setStrictRequirements($this->options['strict_requirements']);
  968. }
  969. return $this->generator;
  970. }
  971. }
  972. }
  973. namespace Symfony\Component\Routing\Matcher
  974. {
  975. interface RedirectableUrlMatcherInterface
  976. {
  977. public function redirect($path, $route, $scheme = null);
  978. }
  979. }
  980. namespace Symfony\Component\Routing\Matcher
  981. {
  982. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  983. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  984. use Symfony\Component\Routing\RouteCollection;
  985. use Symfony\Component\Routing\RequestContext;
  986. use Symfony\Component\Routing\Route;
  987. class UrlMatcher implements UrlMatcherInterface
  988. {
  989. const REQUIREMENT_MATCH = 0;
  990. const REQUIREMENT_MISMATCH = 1;
  991. const ROUTE_MATCH = 2;
  992. protected $context;
  993. protected $allow;
  994. private $routes;
  995. public function __construct(RouteCollection $routes, RequestContext $context)
  996. {
  997. $this->routes = $routes;
  998. $this->context = $context;
  999. }
  1000. public function setContext(RequestContext $context)
  1001. {
  1002. $this->context = $context;
  1003. }
  1004. public function getContext()
  1005. {
  1006. return $this->context;
  1007. }
  1008. public function match($pathinfo)
  1009. {
  1010. $this->allow = array();
  1011. if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
  1012. return $ret;
  1013. }
  1014. throw 0 < count($this->allow)
  1015. ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow)))
  1016. : new ResourceNotFoundException();
  1017. }
  1018. protected function matchCollection($pathinfo, RouteCollection $routes)
  1019. {
  1020. foreach ($routes as $name => $route) {
  1021. if ($route instanceof RouteCollection) {
  1022. if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
  1023. continue;
  1024. }
  1025. if (!$ret = $this->matchCollection($pathinfo, $route)) {
  1026. continue;
  1027. }
  1028. return $ret;
  1029. }
  1030. $compiledRoute = $route->compile();
  1031. if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
  1032. continue;
  1033. }
  1034. if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
  1035. continue;
  1036. }
  1037. if ($req = $route->getRequirement('_method')) {
  1038. if ('HEAD' === $method = $this->context->getMethod()) {
  1039. $method = 'GET';
  1040. }
  1041. if (!in_array($method, $req = explode('|', strtoupper($req)))) {
  1042. $this->allow = array_merge($this->allow, $req);
  1043. continue;
  1044. }
  1045. }
  1046. $status = $this->handleRouteRequirements($pathinfo, $name, $route);
  1047. if (self::ROUTE_MATCH === $status[0]) {
  1048. return $status[1];
  1049. }
  1050. if (self::REQUIREMENT_MISMATCH === $status[0]) {
  1051. continue;
  1052. }
  1053. return array_merge($this->mergeDefaults($matches, $route->getDefaults()), array('_route' => $name));
  1054. }
  1055. }
  1056. protected function handleRouteRequirements($pathinfo, $name, Route $route)
  1057. {
  1058. $scheme = $route->getRequirement('_scheme');
  1059. $status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
  1060. return array($status, null);
  1061. }
  1062. protected function mergeDefaults($params, $defaults)
  1063. {
  1064. foreach ($params as $key => $value) {
  1065. if (!is_int($key)) {
  1066. $defaults[$key] = $value;
  1067. }
  1068. }
  1069. return $defaults;
  1070. }
  1071. }
  1072. }
  1073. namespace Symfony\Component\Routing\Matcher
  1074. {
  1075. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1076. use Symfony\Component\Routing\Route;
  1077. abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
  1078. {
  1079. public function match($pathinfo)
  1080. {
  1081. try {
  1082. $parameters = parent::match($pathinfo);
  1083. } catch (ResourceNotFoundException $e) {
  1084. if ('/' === substr($pathinfo, -1) || !in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
  1085. throw $e;
  1086. }
  1087. try {
  1088. parent::match($pathinfo.'/');
  1089. return $this->redirect($pathinfo.'/', null);
  1090. } catch (ResourceNotFoundException $e2) {
  1091. throw $e;
  1092. }
  1093. }
  1094. return $parameters;
  1095. }
  1096. protected function handleRouteRequirements($pathinfo, $name, Route $route)
  1097. {
  1098. $scheme = $route->getRequirement('_scheme');
  1099. if ($scheme && $this->context->getScheme() !== $scheme) {
  1100. return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
  1101. }
  1102. return array(self::REQUIREMENT_MATCH, null);
  1103. }
  1104. }
  1105. }
  1106. namespace Symfony\Bundle\FrameworkBundle\Routing
  1107. {
  1108. use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
  1109. class RedirectableUrlMatcher extends BaseMatcher
  1110. {
  1111. public function redirect($path, $route, $scheme = null)
  1112. {
  1113. return array(
  1114. '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction',
  1115. 'path' => $path,
  1116. 'permanent' => true,
  1117. 'scheme' => $scheme,
  1118. 'httpPort' => $this->context->getHttpPort(),
  1119. 'httpsPort' => $this->context->getHttpsPort(),
  1120. '_route' => $route,
  1121. );
  1122. }
  1123. }
  1124. }
  1125. namespace Symfony\Component\HttpKernel\CacheWarmer
  1126. {
  1127. interface WarmableInterface
  1128. {
  1129. public function warmUp($cacheDir);
  1130. }
  1131. }
  1132. namespace Symfony\Bundle\FrameworkBundle\Routing
  1133. {
  1134. use Symfony\Component\Routing\Router as BaseRouter;
  1135. use Symfony\Component\Routing\RequestContext;
  1136. use Symfony\Component\DependencyInjection\ContainerInterface;
  1137. use Symfony\Component\Routing\RouteCollection;
  1138. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  1139. use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
  1140. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  1141. class Router extends BaseRouter implements WarmableInterface
  1142. {
  1143. private $container;
  1144. public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
  1145. {
  1146. $this->container = $container;
  1147. $this->resource = $resource;
  1148. $this->context = null === $context ? new RequestContext() : $context;
  1149. $this->setOptions($options);
  1150. }
  1151. public function getRouteCollection()
  1152. {
  1153. if (null === $this->collection) {
  1154. $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
  1155. $this->resolveParameters($this->collection);
  1156. }
  1157. return $this->collection;
  1158. }
  1159. public function warmUp($cacheDir)
  1160. {
  1161. $currentDir = $this->getOption('cache_dir');
  1162. $this->setOption('cache_dir', $cacheDir);
  1163. $this->getMatcher();
  1164. $this->getGenerator();
  1165. $this->setOption('cache_dir', $currentDir);
  1166. }
  1167. private function resolveParameters(RouteCollection $collection)
  1168. {
  1169. foreach ($collection as $route) {
  1170. if ($route instanceof RouteCollection) {
  1171. $this->resolveParameters($route);
  1172. } else {
  1173. foreach ($route->getDefaults() as $name => $value) {
  1174. $route->setDefault($name, $this->resolveString($value));
  1175. }
  1176. foreach ($route->getRequirements() as $name => $value) {
  1177. $route->setRequirement($name, $this->resolveString($value));
  1178. }
  1179. $route->setPattern($this->resolveString($route->getPattern()));
  1180. }
  1181. }
  1182. }
  1183. private function resolveString($value)
  1184. {
  1185. $container = $this->container;
  1186. if (null === $value || false === $value || true === $value || is_object($value) || is_array($value)) {
  1187. return $value;
  1188. }
  1189. $escapedValue = preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($container, $value) {
  1190. if (!isset($match[1])) {
  1191. return '%%';
  1192. }
  1193. $key = strtolower($match[1]);
  1194. if (!$container->hasParameter($key)) {
  1195. throw new ParameterNotFoundException($key);
  1196. }
  1197. $resolved = $container->getParameter($key);
  1198. if (is_string($resolved) || is_numeric($resolved)) {
  1199. return (string) $resolved;
  1200. }
  1201. throw new RuntimeException(sprintf(
  1202. 'A string value must be composed of strings and/or numbers,' .
  1203. 'but found parameter "%s" of type %s inside string value "%s".',
  1204. $key,
  1205. gettype($resolved),
  1206. $value)
  1207. );
  1208. }, $value);
  1209. return str_replace('%%', '%', $escapedValue);
  1210. }
  1211. }
  1212. }
  1213. namespace Symfony\Bundle\FrameworkBundle\Templating
  1214. {
  1215. use Symfony\Component\DependencyInjection\ContainerInterface;
  1216. class GlobalVariables
  1217. {
  1218. protected $container;
  1219. public function __construct(ContainerInterface $container)
  1220. {
  1221. $this->container = $container;
  1222. }
  1223. public function getSecurity()
  1224. {
  1225. if ($this->container->has('security.context')) {
  1226. return $this->container->get('security.context');
  1227. }
  1228. }
  1229. public function getUser()
  1230. {
  1231. if (!$security = $this->getSecurity()) {
  1232. return;
  1233. }
  1234. if (!$token = $security->getToken()) {
  1235. return;
  1236. }
  1237. $user = $token->getUser();
  1238. if (!is_object($user)) {
  1239. return;
  1240. }
  1241. return $user;
  1242. }
  1243. public function getRequest()
  1244. {
  1245. if ($this->container->has('request') && $request = $this->container->get('request')) {
  1246. return $request;
  1247. }
  1248. }
  1249. public function getSession()
  1250. {
  1251. if ($request = $this->getRequest()) {
  1252. return $request->getSession();
  1253. }
  1254. }
  1255. public function getEnvironment()
  1256. {
  1257. return $this->container->getParameter('kernel.environment');
  1258. }
  1259. public function getDebug()
  1260. {
  1261. return (Boolean) $this->container->getParameter('kernel.debug');
  1262. }
  1263. }
  1264. }
  1265. namespace Symfony\Component\Templating
  1266. {
  1267. interface TemplateReferenceInterface
  1268. {
  1269. public function all();
  1270. public function set($name, $value);
  1271. public function get($name);
  1272. public function getPath();
  1273. public function getLogicalName();
  1274. }
  1275. }
  1276. namespace Symfony\Component\Templating
  1277. {
  1278. class TemplateReference implements TemplateReferenceInterface
  1279. {
  1280. protected $parameters;
  1281. public function __construct($name = null, $engine = null)
  1282. {
  1283. $this->parameters = array(
  1284. 'name' => $name,
  1285. 'engine' => $engine,
  1286. );
  1287. }
  1288. public function __toString()
  1289. {
  1290. return $this->getLogicalName();
  1291. }
  1292. public function set($name, $value)
  1293. {
  1294. if (array_key_exists($name, $this->parameters)) {
  1295. $this->parameters[$name] = $value;
  1296. } else {
  1297. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  1298. }
  1299. return $this;
  1300. }
  1301. public function get($name)
  1302. {
  1303. if (array_key_exists($name, $this->parameters)) {
  1304. return $this->parameters[$name];
  1305. }
  1306. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  1307. }
  1308. public function all()
  1309. {
  1310. return $this->parameters;
  1311. }
  1312. public function getPath()
  1313. {
  1314. return $this->parameters['name'];
  1315. }
  1316. public function getLogicalName()
  1317. {
  1318. return $this->parameters['name'];
  1319. }
  1320. }
  1321. }
  1322. namespace Symfony\Bundle\FrameworkBundle\Templating
  1323. {
  1324. use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
  1325. class TemplateReference extends BaseTemplateReference
  1326. {
  1327. public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
  1328. {
  1329. $this->parameters = array(
  1330. 'bundle' => $bundle,
  1331. 'controller' => $controller,
  1332. 'name' => $name,
  1333. 'format' => $format,
  1334. 'engine' => $engine,
  1335. );
  1336. }
  1337. public function getPath()
  1338. {
  1339. $controller = str_replace('\\', '/', $this->get('controller'));
  1340. $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
  1341. return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
  1342. }
  1343. public function getLogicalName()
  1344. {
  1345. return sprintf('%s:%s:%s.%s.%s', $this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
  1346. }
  1347. }
  1348. }
  1349. namespace Symfony\Component\Templating
  1350. {
  1351. interface TemplateNameParserInterface
  1352. {
  1353. public function parse($name);
  1354. }
  1355. }
  1356. namespace Symfony\Bundle\FrameworkBundle\Templating
  1357. {
  1358. use Symfony\Component\Templating\TemplateNameParserInterface;
  1359. use Symfony\Component\Templating\TemplateReferenceInterface;
  1360. use Symfony\Component\HttpKernel\KernelInterface;
  1361. class TemplateNameParser implements TemplateNameParserInterface
  1362. {
  1363. protected $kernel;
  1364. protected $cache;
  1365. public function __construct(KernelInterface $kernel)
  1366. {
  1367. $this->kernel = $kernel;
  1368. $this->cache = array();
  1369. }
  1370. public function parse($name)
  1371. {
  1372. if ($name instanceof TemplateReferenceInterface) {
  1373. return $name;
  1374. } elseif (isset($this->cache[$name])) {
  1375. return $this->cache[$name];
  1376. }
  1377. $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));
  1378. if (false !== strpos($name, '..')) {
  1379. throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
  1380. }
  1381. $parts = explode(':', $name);
  1382. if (3 !== count($parts)) {
  1383. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
  1384. }
  1385. $elements = explode('.', $parts[2]);
  1386. if (3 > count($elements)) {
  1387. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
  1388. }
  1389. $engine = array_pop($elements);
  1390. $format = array_pop($elements);
  1391. $template = new TemplateReference($parts[0], $parts[1], implode('.', $elements), $format, $engine);
  1392. if ($template->get('bundle')) {
  1393. try {
  1394. $this->kernel->getBundle($template->get('bundle'));
  1395. } catch (\Exception $e) {
  1396. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
  1397. }
  1398. }
  1399. return $this->cache[$name] = $t

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