var/cache/dev/classes.php line 3535

Open in your IDE?
  1. <?php 
  2. namespace Symfony\Component\EventDispatcher
  3. {
  4. interface EventSubscriberInterface
  5. {
  6. public static function getSubscribedEvents();
  7. }
  8. }
  9. namespace Symfony\Component\HttpKernel\EventListener
  10. {
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. abstract class AbstractSessionListener implements EventSubscriberInterface
  16. {
  17. public function onKernelRequest(GetResponseEvent $event)
  18. {
  19. if (!$event->isMasterRequest()) {
  20. return;
  21. }
  22. $request $event->getRequest();
  23. $session $this->getSession();
  24. if (null === $session || $request->hasSession()) {
  25. return;
  26. }
  27. $request->setSession($session);
  28. }
  29. public static function getSubscribedEvents()
  30. {
  31. return array(
  32. KernelEvents::REQUEST => array('onKernelRequest'128),
  33. );
  34. }
  35. abstract protected function getSession();
  36. }
  37. }
  38. namespace Symfony\Component\HttpKernel\EventListener
  39. {
  40. use Psr\Container\ContainerInterface;
  41. class SessionListener extends AbstractSessionListener
  42. {
  43. private $container;
  44. public function __construct(ContainerInterface $container)
  45. {
  46. $this->container $container;
  47. }
  48. protected function getSession()
  49. {
  50. if (!$this->container->has('session')) {
  51. return;
  52. }
  53. return $this->container->get('session');
  54. }
  55. }
  56. }
  57. namespace Symfony\Component\HttpFoundation\Session\Storage
  58. {
  59. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  60. interface SessionStorageInterface
  61. {
  62. public function start();
  63. public function isStarted();
  64. public function getId();
  65. public function setId($id);
  66. public function getName();
  67. public function setName($name);
  68. public function regenerate($destroy false$lifetime null);
  69. public function save();
  70. public function clear();
  71. public function getBag($name);
  72. public function registerBag(SessionBagInterface $bag);
  73. public function getMetadataBag();
  74. }
  75. }
  76. namespace Symfony\Component\HttpFoundation\Session\Storage
  77. {
  78. use Symfony\Component\Debug\Exception\ContextErrorException;
  79. use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
  80. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
  81. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  82. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
  83. class NativeSessionStorage implements SessionStorageInterface
  84. {
  85. protected $bags;
  86. protected $started false;
  87. protected $closed false;
  88. protected $saveHandler;
  89. protected $metadataBag;
  90. public function __construct(array $options = array(), $handler nullMetadataBag $metaBag null)
  91. {
  92. $options += array('cache_limiter'=>'','use_cookies'=> 1,
  93. );
  94. session_register_shutdown();
  95. $this->setMetadataBag($metaBag);
  96. $this->setOptions($options);
  97. $this->setSaveHandler($handler);
  98. }
  99. public function getSaveHandler()
  100. {
  101. return $this->saveHandler;
  102. }
  103. public function start()
  104. {
  105. if ($this->started) {
  106. return true;
  107. }
  108. if (\PHP_SESSION_ACTIVE === session_status()) {
  109. throw new \RuntimeException('Failed to start the session: already started by PHP.');
  110. }
  111. if (ini_get('session.use_cookies') && headers_sent($file$line)) {
  112. throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.'$file$line));
  113. }
  114. if (!session_start()) {
  115. throw new \RuntimeException('Failed to start the session');
  116. }
  117. $this->loadSession();
  118. return true;
  119. }
  120. public function getId()
  121. {
  122. return $this->saveHandler->getId();
  123. }
  124. public function setId($id)
  125. {
  126. $this->saveHandler->setId($id);
  127. }
  128. public function getName()
  129. {
  130. return $this->saveHandler->getName();
  131. }
  132. public function setName($name)
  133. {
  134. $this->saveHandler->setName($name);
  135. }
  136. public function regenerate($destroy false$lifetime null)
  137. {
  138. if (\PHP_SESSION_ACTIVE !== session_status()) {
  139. return false;
  140. }
  141. if (headers_sent()) {
  142. return false;
  143. }
  144. if (null !== $lifetime) {
  145. ini_set('session.cookie_lifetime'$lifetime);
  146. }
  147. if ($destroy) {
  148. $this->metadataBag->stampNew();
  149. }
  150. $isRegenerated session_regenerate_id($destroy);
  151. $this->loadSession();
  152. return $isRegenerated;
  153. }
  154. public function save()
  155. {
  156. set_error_handler(function ($errno$errstr$errfile$errline$errcontext = array()) {
  157. throw new ContextErrorException($errstr$errnoE_WARNING$errfile$errline$errcontext);
  158. }, E_WARNING);
  159. try {
  160. session_write_close();
  161. restore_error_handler();
  162. } catch (ContextErrorException $e) {
  163. $handler $this->getSaveHandler();
  164. if ($handler instanceof SessionHandlerProxy) {
  165. $handler $handler->getHandler();
  166. }
  167. restore_error_handler();
  168. trigger_error(sprintf('session_write_close(): Failed to write session data with %s handler'get_class($handler)), E_USER_WARNING);
  169. }
  170. $this->closed true;
  171. $this->started false;
  172. }
  173. public function clear()
  174. {
  175. foreach ($this->bags as $bag) {
  176. $bag->clear();
  177. }
  178. $_SESSION = array();
  179. $this->loadSession();
  180. }
  181. public function registerBag(SessionBagInterface $bag)
  182. {
  183. if ($this->started) {
  184. throw new \LogicException('Cannot register a bag when the session is already started.');
  185. }
  186. $this->bags[$bag->getName()] = $bag;
  187. }
  188. public function getBag($name)
  189. {
  190. if (!isset($this->bags[$name])) {
  191. throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.'$name));
  192. }
  193. if (!$this->started && $this->saveHandler->isActive()) {
  194. $this->loadSession();
  195. } elseif (!$this->started) {
  196. $this->start();
  197. }
  198. return $this->bags[$name];
  199. }
  200. public function setMetadataBag(MetadataBag $metaBag null)
  201. {
  202. if (null === $metaBag) {
  203. $metaBag = new MetadataBag();
  204. }
  205. $this->metadataBag $metaBag;
  206. }
  207. public function getMetadataBag()
  208. {
  209. return $this->metadataBag;
  210. }
  211. public function isStarted()
  212. {
  213. return $this->started;
  214. }
  215. public function setOptions(array $options)
  216. {
  217. if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
  218. return;
  219. }
  220. $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','lazy_write','name','referer_check','serialize_handler','use_strict_mode','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','sid_length','sid_bits_per_character','trans_sid_hosts','trans_sid_tags',
  221. ));
  222. foreach ($options as $key => $value) {
  223. if (isset($validOptions[$key])) {
  224. ini_set('session.'.$key$value);
  225. }
  226. }
  227. }
  228. public function setSaveHandler($saveHandler null)
  229. {
  230. if (!$saveHandler instanceof AbstractProxy &&
  231. !$saveHandler instanceof NativeSessionHandler &&
  232. !$saveHandler instanceof \SessionHandlerInterface &&
  233. null !== $saveHandler) {
  234. throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
  235. }
  236. if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
  237. $saveHandler = new SessionHandlerProxy($saveHandler);
  238. } elseif (!$saveHandler instanceof AbstractProxy) {
  239. $saveHandler = new SessionHandlerProxy(new \SessionHandler());
  240. }
  241. $this->saveHandler $saveHandler;
  242. if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
  243. return;
  244. }
  245. if ($this->saveHandler instanceof \SessionHandlerInterface) {
  246. session_set_save_handler($this->saveHandlerfalse);
  247. }
  248. }
  249. protected function loadSession(array &$session null)
  250. {
  251. if (null === $session) {
  252. $session = &$_SESSION;
  253. }
  254. $bags array_merge($this->bags, array($this->metadataBag));
  255. foreach ($bags as $bag) {
  256. $key $bag->getStorageKey();
  257. $session[$key] = isset($session[$key]) ? $session[$key] : array();
  258. $bag->initialize($session[$key]);
  259. }
  260. $this->started true;
  261. $this->closed false;
  262. }
  263. }
  264. }
  265. namespace Symfony\Component\HttpFoundation\Session\Storage
  266. {
  267. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  268. use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
  269. class PhpBridgeSessionStorage extends NativeSessionStorage
  270. {
  271. public function __construct($handler nullMetadataBag $metaBag null)
  272. {
  273. $this->setMetadataBag($metaBag);
  274. $this->setSaveHandler($handler);
  275. }
  276. public function start()
  277. {
  278. if ($this->started) {
  279. return true;
  280. }
  281. $this->loadSession();
  282. return true;
  283. }
  284. public function clear()
  285. {
  286. foreach ($this->bags as $bag) {
  287. $bag->clear();
  288. }
  289. $this->loadSession();
  290. }
  291. }
  292. }
  293. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  294. {
  295. class NativeSessionHandler extends \SessionHandler
  296. {
  297. }
  298. }
  299. namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
  300. {
  301. class NativeFileSessionHandler extends NativeSessionHandler
  302. {
  303. public function __construct($savePath null)
  304. {
  305. if (null === $savePath) {
  306. $savePath ini_get('session.save_path');
  307. }
  308. $baseDir $savePath;
  309. if ($count substr_count($savePath,';')) {
  310. if ($count 2) {
  311. throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\''$savePath));
  312. }
  313. $baseDir ltrim(strrchr($savePath,';'),';');
  314. }
  315. if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir0777true) && !is_dir($baseDir)) {
  316. throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"'$baseDir));
  317. }
  318. ini_set('session.save_path'$savePath);
  319. ini_set('session.save_handler','files');
  320. }
  321. }
  322. }
  323. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  324. {
  325. abstract class AbstractProxy
  326. {
  327. protected $wrapper false;
  328. protected $saveHandlerName;
  329. public function getSaveHandlerName()
  330. {
  331. return $this->saveHandlerName;
  332. }
  333. public function isSessionHandlerInterface()
  334. {
  335. return $this instanceof \SessionHandlerInterface;
  336. }
  337. public function isWrapper()
  338. {
  339. return $this->wrapper;
  340. }
  341. public function isActive()
  342. {
  343. return \PHP_SESSION_ACTIVE === session_status();
  344. }
  345. public function getId()
  346. {
  347. return session_id();
  348. }
  349. public function setId($id)
  350. {
  351. if ($this->isActive()) {
  352. throw new \LogicException('Cannot change the ID of an active session');
  353. }
  354. session_id($id);
  355. }
  356. public function getName()
  357. {
  358. return session_name();
  359. }
  360. public function setName($name)
  361. {
  362. if ($this->isActive()) {
  363. throw new \LogicException('Cannot change the name of an active session');
  364. }
  365. session_name($name);
  366. }
  367. }
  368. }
  369. namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
  370. {
  371. class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
  372. {
  373. protected $handler;
  374. public function __construct(\SessionHandlerInterface $handler)
  375. {
  376. $this->handler $handler;
  377. $this->wrapper = ($handler instanceof \SessionHandler);
  378. $this->saveHandlerName $this->wrapper ini_get('session.save_handler') :'user';
  379. }
  380. public function getHandler()
  381. {
  382. return $this->handler;
  383. }
  384. public function open($savePath$sessionName)
  385. {
  386. return (bool) $this->handler->open($savePath$sessionName);
  387. }
  388. public function close()
  389. {
  390. return (bool) $this->handler->close();
  391. }
  392. public function read($sessionId)
  393. {
  394. return (string) $this->handler->read($sessionId);
  395. }
  396. public function write($sessionId$data)
  397. {
  398. return (bool) $this->handler->write($sessionId$data);
  399. }
  400. public function destroy($sessionId)
  401. {
  402. return (bool) $this->handler->destroy($sessionId);
  403. }
  404. public function gc($maxlifetime)
  405. {
  406. return (bool) $this->handler->gc($maxlifetime);
  407. }
  408. }
  409. }
  410. namespace Symfony\Component\HttpFoundation\Session
  411. {
  412. use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
  413. interface SessionInterface
  414. {
  415. public function start();
  416. public function getId();
  417. public function setId($id);
  418. public function getName();
  419. public function setName($name);
  420. public function invalidate($lifetime null);
  421. public function migrate($destroy false$lifetime null);
  422. public function save();
  423. public function has($name);
  424. public function get($name$default null);
  425. public function set($name$value);
  426. public function all();
  427. public function replace(array $attributes);
  428. public function remove($name);
  429. public function clear();
  430. public function isStarted();
  431. public function registerBag(SessionBagInterface $bag);
  432. public function getBag($name);
  433. public function getMetadataBag();
  434. }
  435. }
  436. namespace Symfony\Component\HttpFoundation\Session
  437. {
  438. use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
  439. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  440. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
  441. use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
  442. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  443. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  444. class Session implements SessionInterface, \IteratorAggregate, \Countable
  445. {
  446. protected $storage;
  447. private $flashName;
  448. private $attributeName;
  449. public function __construct(SessionStorageInterface $storage nullAttributeBagInterface $attributes nullFlashBagInterface $flashes null)
  450. {
  451. $this->storage $storage ?: new NativeSessionStorage();
  452. $attributes $attributes ?: new AttributeBag();
  453. $this->attributeName $attributes->getName();
  454. $this->registerBag($attributes);
  455. $flashes $flashes ?: new FlashBag();
  456. $this->flashName $flashes->getName();
  457. $this->registerBag($flashes);
  458. }
  459. public function start()
  460. {
  461. return $this->storage->start();
  462. }
  463. public function has($name)
  464. {
  465. return $this->getAttributeBag()->has($name);
  466. }
  467. public function get($name$default null)
  468. {
  469. return $this->getAttributeBag()->get($name$default);
  470. }
  471. public function set($name$value)
  472. {
  473. $this->getAttributeBag()->set($name$value);
  474. }
  475. public function all()
  476. {
  477. return $this->getAttributeBag()->all();
  478. }
  479. public function replace(array $attributes)
  480. {
  481. $this->getAttributeBag()->replace($attributes);
  482. }
  483. public function remove($name)
  484. {
  485. return $this->getAttributeBag()->remove($name);
  486. }
  487. public function clear()
  488. {
  489. $this->storage->getBag($this->attributeName)->clear();
  490. }
  491. public function isStarted()
  492. {
  493. return $this->storage->isStarted();
  494. }
  495. public function getIterator()
  496. {
  497. return new \ArrayIterator($this->getAttributeBag()->all());
  498. }
  499. public function count()
  500. {
  501. return count($this->getAttributeBag()->all());
  502. }
  503. public function invalidate($lifetime null)
  504. {
  505. $this->storage->clear();
  506. return $this->migrate(true$lifetime);
  507. }
  508. public function migrate($destroy false$lifetime null)
  509. {
  510. return $this->storage->regenerate($destroy$lifetime);
  511. }
  512. public function save()
  513. {
  514. $this->storage->save();
  515. }
  516. public function getId()
  517. {
  518. return $this->storage->getId();
  519. }
  520. public function setId($id)
  521. {
  522. $this->storage->setId($id);
  523. }
  524. public function getName()
  525. {
  526. return $this->storage->getName();
  527. }
  528. public function setName($name)
  529. {
  530. $this->storage->setName($name);
  531. }
  532. public function getMetadataBag()
  533. {
  534. return $this->storage->getMetadataBag();
  535. }
  536. public function registerBag(SessionBagInterface $bag)
  537. {
  538. $this->storage->registerBag($bag);
  539. }
  540. public function getBag($name)
  541. {
  542. return $this->storage->getBag($name);
  543. }
  544. public function getFlashBag()
  545. {
  546. return $this->getBag($this->flashName);
  547. }
  548. private function getAttributeBag()
  549. {
  550. return $this->storage->getBag($this->attributeName);
  551. }
  552. }
  553. }
  554. namespace Symfony\Bundle\FrameworkBundle\Templating
  555. {
  556. use Symfony\Component\DependencyInjection\ContainerInterface;
  557. use Symfony\Component\HttpFoundation\Request;
  558. use Symfony\Component\HttpFoundation\Session\Session;
  559. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  560. class GlobalVariables
  561. {
  562. protected $container;
  563. public function __construct(ContainerInterface $container)
  564. {
  565. $this->container $container;
  566. }
  567. public function getToken()
  568. {
  569. if (!$this->container->has('security.token_storage')) {
  570. return;
  571. }
  572. return $this->container->get('security.token_storage')->getToken();
  573. }
  574. public function getUser()
  575. {
  576. if (!$token $this->getToken()) {
  577. return;
  578. }
  579. $user $token->getUser();
  580. if (!is_object($user)) {
  581. return;
  582. }
  583. return $user;
  584. }
  585. public function getRequest()
  586. {
  587. if ($this->container->has('request_stack')) {
  588. return $this->container->get('request_stack')->getCurrentRequest();
  589. }
  590. }
  591. public function getSession()
  592. {
  593. if ($request $this->getRequest()) {
  594. return $request->getSession();
  595. }
  596. }
  597. public function getEnvironment()
  598. {
  599. return $this->container->getParameter('kernel.environment');
  600. }
  601. public function getDebug()
  602. {
  603. return (bool) $this->container->getParameter('kernel.debug');
  604. }
  605. }
  606. }
  607. namespace Symfony\Component\Templating
  608. {
  609. interface TemplateReferenceInterface
  610. {
  611. public function all();
  612. public function set($name$value);
  613. public function get($name);
  614. public function getPath();
  615. public function getLogicalName();
  616. public function __toString();
  617. }
  618. }
  619. namespace Symfony\Component\Templating
  620. {
  621. class TemplateReference implements TemplateReferenceInterface
  622. {
  623. protected $parameters;
  624. public function __construct($name null$engine null)
  625. {
  626. $this->parameters = array('name'=> $name,'engine'=> $engine,
  627. );
  628. }
  629. public function __toString()
  630. {
  631. return $this->getLogicalName();
  632. }
  633. public function set($name$value)
  634. {
  635. if (array_key_exists($name$this->parameters)) {
  636. $this->parameters[$name] = $value;
  637. } else {
  638. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.'$name));
  639. }
  640. return $this;
  641. }
  642. public function get($name)
  643. {
  644. if (array_key_exists($name$this->parameters)) {
  645. return $this->parameters[$name];
  646. }
  647. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.'$name));
  648. }
  649. public function all()
  650. {
  651. return $this->parameters;
  652. }
  653. public function getPath()
  654. {
  655. return $this->parameters['name'];
  656. }
  657. public function getLogicalName()
  658. {
  659. return $this->parameters['name'];
  660. }
  661. }
  662. }
  663. namespace Symfony\Bundle\FrameworkBundle\Templating
  664. {
  665. use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
  666. class TemplateReference extends BaseTemplateReference
  667. {
  668. public function __construct($bundle null$controller null$name null$format null$engine null)
  669. {
  670. $this->parameters = array('bundle'=> $bundle,'controller'=> $controller,'name'=> $name,'format'=> $format,'engine'=> $engine,
  671. );
  672. }
  673. public function getPath()
  674. {
  675. $controller str_replace('\\','/'$this->get('controller'));
  676. $path = (empty($controller) ?''$controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
  677. return empty($this->parameters['bundle']) ?'views/'.$path :'@'.$this->get('bundle').'/Resources/views/'.$path;
  678. }
  679. public function getLogicalName()
  680. {
  681. return sprintf('%s:%s:%s.%s.%s'$this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
  682. }
  683. }
  684. }
  685. namespace Symfony\Component\Templating
  686. {
  687. interface TemplateNameParserInterface
  688. {
  689. public function parse($name);
  690. }
  691. }
  692. namespace Symfony\Component\Templating
  693. {
  694. class TemplateNameParser implements TemplateNameParserInterface
  695. {
  696. public function parse($name)
  697. {
  698. if ($name instanceof TemplateReferenceInterface) {
  699. return $name;
  700. }
  701. $engine null;
  702. if (false !== $pos strrpos($name,'.')) {
  703. $engine substr($name$pos 1);
  704. }
  705. return new TemplateReference($name$engine);
  706. }
  707. }
  708. }
  709. namespace Symfony\Bundle\FrameworkBundle\Templating
  710. {
  711. use Symfony\Component\Templating\TemplateReferenceInterface;
  712. use Symfony\Component\HttpKernel\KernelInterface;
  713. use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;
  714. class TemplateNameParser extends BaseTemplateNameParser
  715. {
  716. protected $kernel;
  717. protected $cache = array();
  718. public function __construct(KernelInterface $kernel)
  719. {
  720. $this->kernel $kernel;
  721. }
  722. public function parse($name)
  723. {
  724. if ($name instanceof TemplateReferenceInterface) {
  725. return $name;
  726. } elseif (isset($this->cache[$name])) {
  727. return $this->cache[$name];
  728. }
  729. $name str_replace(':/',':'preg_replace('#/{2,}#','/'str_replace('\\','/'$name)));
  730. if (false !== strpos($name,'..')) {
  731. throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.'$name));
  732. }
  733. if ($this->isAbsolutePath($name) || !preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/'$name$matches) || === strpos($name,'@')) {
  734. return parent::parse($name);
  735. }
  736. $template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
  737. if ($template->get('bundle')) {
  738. try {
  739. $this->kernel->getBundle($template->get('bundle'));
  740. } catch (\Exception $e) {
  741. throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.'$name), 0$e);
  742. }
  743. }
  744. return $this->cache[$name] = $template;
  745. }
  746. private function isAbsolutePath($file)
  747. {
  748. $isAbsolute = (bool) preg_match('#^(?:/|[a-zA-Z]:)#'$file);
  749. if ($isAbsolute) {
  750. @trigger_error('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.'E_USER_DEPRECATED);
  751. }
  752. return $isAbsolute;
  753. }
  754. }
  755. }
  756. namespace Symfony\Component\Config
  757. {
  758. use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
  759. interface FileLocatorInterface
  760. {
  761. public function locate($name$currentPath null$first true);
  762. }
  763. }
  764. namespace Symfony\Bundle\FrameworkBundle\Templating\Loader
  765. {
  766. use Symfony\Component\Config\FileLocatorInterface;
  767. use Symfony\Component\Templating\TemplateReferenceInterface;
  768. class TemplateLocator implements FileLocatorInterface
  769. {
  770. protected $locator;
  771. protected $cache;
  772. private $cacheHits = array();
  773. public function __construct(FileLocatorInterface $locator$cacheDir null)
  774. {
  775. if (null !== $cacheDir && file_exists($cache $cacheDir.'/templates.php')) {
  776. $this->cache = require $cache;
  777. }
  778. $this->locator $locator;
  779. }
  780. protected function getCacheKey($template)
  781. {
  782. return $template->getLogicalName();
  783. }
  784. public function locate($template$currentPath null$first true)
  785. {
  786. if (!$template instanceof TemplateReferenceInterface) {
  787. throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
  788. }
  789. $key $this->getCacheKey($template);
  790. if (isset($this->cacheHits[$key])) {
  791. return $this->cacheHits[$key];
  792. }
  793. if (isset($this->cache[$key])) {
  794. return $this->cacheHits[$key] = realpath($this->cache[$key]) ?: $this->cache[$key];
  795. }
  796. try {
  797. return $this->cacheHits[$key] = $this->locator->locate($template->getPath(), $currentPath);
  798. } catch (\InvalidArgumentException $e) {
  799. throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".'$template$e->getMessage()), 0$e);
  800. }
  801. }
  802. }
  803. }
  804. namespace Psr\Log
  805. {
  806. interface LoggerAwareInterface
  807. {
  808. public function setLogger(LoggerInterface $logger);
  809. }
  810. }
  811. namespace Psr\Cache
  812. {
  813. interface CacheItemPoolInterface
  814. {
  815. public function getItem($key);
  816. public function getItems(array $keys = array());
  817. public function hasItem($key);
  818. public function clear();
  819. public function deleteItem($key);
  820. public function deleteItems(array $keys);
  821. public function save(CacheItemInterface $item);
  822. public function saveDeferred(CacheItemInterface $item);
  823. public function commit();
  824. }
  825. }
  826. namespace Symfony\Component\Cache\Adapter
  827. {
  828. use Psr\Cache\CacheItemPoolInterface;
  829. use Symfony\Component\Cache\CacheItem;
  830. interface AdapterInterface extends CacheItemPoolInterface
  831. {
  832. public function getItem($key);
  833. public function getItems(array $keys = array());
  834. }
  835. }
  836. namespace Psr\Log
  837. {
  838. trait LoggerAwareTrait
  839. {
  840. protected $logger;
  841. public function setLogger(LoggerInterface $logger)
  842. {
  843. $this->logger $logger;
  844. }
  845. }
  846. }
  847. namespace Symfony\Component\Cache\Traits
  848. {
  849. use Psr\Log\LoggerAwareTrait;
  850. use Symfony\Component\Cache\CacheItem;
  851. trait AbstractTrait
  852. {
  853. use LoggerAwareTrait;
  854. private $namespace;
  855. private $namespaceVersion ='';
  856. private $versioningIsEnabled false;
  857. private $deferred = array();
  858. protected $maxIdLength;
  859. abstract protected function doFetch(array $ids);
  860. abstract protected function doHave($id);
  861. abstract protected function doClear($namespace);
  862. abstract protected function doDelete(array $ids);
  863. abstract protected function doSave(array $values$lifetime);
  864. public function hasItem($key)
  865. {
  866. $id $this->getId($key);
  867. if (isset($this->deferred[$key])) {
  868. $this->commit();
  869. }
  870. try {
  871. return $this->doHave($id);
  872. } catch (\Exception $e) {
  873. CacheItem::log($this->logger,'Failed to check if key "{key}" is cached', array('key'=> $key,'exception'=> $e));
  874. return false;
  875. }
  876. }
  877. public function clear()
  878. {
  879. if ($cleared $this->versioningIsEnabled) {
  880. $this->namespaceVersion 2;
  881. foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
  882. $this->namespaceVersion + (int) $v;
  883. }
  884. $this->namespaceVersion .=':';
  885. $cleared $this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0);
  886. }
  887. $this->deferred = array();
  888. try {
  889. return $this->doClear($this->namespace) || $cleared;
  890. } catch (\Exception $e) {
  891. CacheItem::log($this->logger,'Failed to clear the cache', array('exception'=> $e));
  892. return false;
  893. }
  894. }
  895. public function deleteItem($key)
  896. {
  897. return $this->deleteItems(array($key));
  898. }
  899. public function deleteItems(array $keys)
  900. {
  901. $ids = array();
  902. foreach ($keys as $key) {
  903. $ids[$key] = $this->getId($key);
  904. unset($this->deferred[$key]);
  905. }
  906. try {
  907. if ($this->doDelete($ids)) {
  908. return true;
  909. }
  910. } catch (\Exception $e) {
  911. }
  912. $ok true;
  913. foreach ($ids as $key => $id) {
  914. try {
  915. $e null;
  916. if ($this->doDelete(array($id))) {
  917. continue;
  918. }
  919. } catch (\Exception $e) {
  920. }
  921. CacheItem::log($this->logger,'Failed to delete key "{key}"', array('key'=> $key,'exception'=> $e));
  922. $ok false;
  923. }
  924. return $ok;
  925. }
  926. public function enableVersioning($enable true)
  927. {
  928. $wasEnabled $this->versioningIsEnabled;
  929. $this->versioningIsEnabled = (bool) $enable;
  930. $this->namespaceVersion ='';
  931. return $wasEnabled;
  932. }
  933. protected static function unserialize($value)
  934. {
  935. if ('b:0;'=== $value) {
  936. return false;
  937. }
  938. $unserializeCallbackHandler ini_set('unserialize_callback_func'__CLASS__.'::handleUnserializeCallback');
  939. try {
  940. if (false !== $value unserialize($value)) {
  941. return $value;
  942. }
  943. throw new \DomainException('Failed to unserialize cached value');
  944. } catch (\Error $e) {
  945. throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR$e->getFile(), $e->getLine());
  946. } finally {
  947. ini_set('unserialize_callback_func'$unserializeCallbackHandler);
  948. }
  949. }
  950. private function getId($key)
  951. {
  952. CacheItem::validateKey($key);
  953. if ($this->versioningIsEnabled &&''=== $this->namespaceVersion) {
  954. $this->namespaceVersion ='1:';
  955. foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
  956. $this->namespaceVersion $v;
  957. }
  958. }
  959. if (null === $this->maxIdLength) {
  960. return $this->namespace.$this->namespaceVersion.$key;
  961. }
  962. if (strlen($id $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
  963. $id $this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256'$keytrue)),':', -22);
  964. }
  965. return $id;
  966. }
  967. public static function handleUnserializeCallback($class)
  968. {
  969. throw new \DomainException('Class not found: '.$class);
  970. }
  971. }
  972. }
  973. namespace Symfony\Component\Cache\Traits
  974. {
  975. use Symfony\Component\Cache\CacheItem;
  976. use Symfony\Component\Cache\Exception\CacheException;
  977. trait ApcuTrait
  978. {
  979. public static function isSupported()
  980. {
  981. return function_exists('apcu_fetch') && ini_get('apc.enabled');
  982. }
  983. private function init($namespace$defaultLifetime$version)
  984. {
  985. if (!static::isSupported()) {
  986. throw new CacheException('APCu is not enabled');
  987. }
  988. if ('cli'=== PHP_SAPI) {
  989. ini_set('apc.use_request_time'0);
  990. }
  991. parent::__construct($namespace$defaultLifetime);
  992. if (null !== $version) {
  993. CacheItem::validateKey($version);
  994. if (!apcu_exists($version.'@'.$namespace)) {
  995. $this->doClear($namespace);
  996. apcu_add($version.'@'.$namespacenull);
  997. }
  998. }
  999. }
  1000. protected function doFetch(array $ids)
  1001. {
  1002. try {
  1003. foreach (apcu_fetch($ids$ok) ?: array() as $k => $v) {
  1004. if (null !== $v || $ok) {
  1005. yield $k => $v;
  1006. }
  1007. }
  1008. } catch (\Error $e) {
  1009. throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR$e->getFile(), $e->getLine());
  1010. }
  1011. }
  1012. protected function doHave($id)
  1013. {
  1014. return apcu_exists($id);
  1015. }
  1016. protected function doClear($namespace)
  1017. {
  1018. return isset($namespace[0]) && class_exists('APCuIterator'false) && ('cli'!== PHP_SAPI || ini_get('apc.enable_cli'))
  1019. apcu_delete(new \APCuIterator(sprintf('/^%s/'preg_quote($namespace,'/')), APC_ITER_KEY))
  1020. apcu_clear_cache();
  1021. }
  1022. protected function doDelete(array $ids)
  1023. {
  1024. foreach ($ids as $id) {
  1025. apcu_delete($id);
  1026. }
  1027. return true;
  1028. }
  1029. protected function doSave(array $values$lifetime)
  1030. {
  1031. try {
  1032. if (false === $failures apcu_store($valuesnull$lifetime)) {
  1033. $failures $values;
  1034. }
  1035. return array_keys($failures);
  1036. } catch (\Error $e) {
  1037. } catch (\Exception $e) {
  1038. }
  1039. if (=== count($values)) {
  1040. apcu_delete(key($values));
  1041. }
  1042. throw $e;
  1043. }
  1044. }
  1045. }
  1046. namespace Symfony\Component\Cache\Adapter
  1047. {
  1048. use Psr\Cache\CacheItemInterface;
  1049. use Psr\Log\LoggerAwareInterface;
  1050. use Psr\Log\LoggerInterface;
  1051. use Psr\Log\NullLogger;
  1052. use Symfony\Component\Cache\CacheItem;
  1053. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  1054. use Symfony\Component\Cache\Traits\AbstractTrait;
  1055. abstract class AbstractAdapter implements AdapterInterfaceLoggerAwareInterface
  1056. {
  1057. use AbstractTrait;
  1058. private static $apcuSupported;
  1059. private static $phpFilesSupported;
  1060. private $createCacheItem;
  1061. private $mergeByLifetime;
  1062. protected function __construct($namespace =''$defaultLifetime 0)
  1063. {
  1064. $this->namespace =''=== $namespace ?''CacheItem::validateKey($namespace).':';
  1065. if (null !== $this->maxIdLength && strlen($namespace) > $this->maxIdLength 24) {
  1066. throw new InvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s")'$this->maxIdLength 24strlen($namespace), $namespace));
  1067. }
  1068. $this->createCacheItem = \Closure::bind(
  1069. function ($key$value$isHit) use ($defaultLifetime) {
  1070. $item = new CacheItem();
  1071. $item->key $key;
  1072. $item->value $value;
  1073. $item->isHit $isHit;
  1074. $item->defaultLifetime $defaultLifetime;
  1075. return $item;
  1076. },
  1077. null,
  1078. CacheItem::class
  1079. );
  1080. $getId = function ($key) { return $this->getId((string) $key); };
  1081. $this->mergeByLifetime = \Closure::bind(
  1082. function ($deferred$namespace, &$expiredIds) use ($getId) {
  1083. $byLifetime = array();
  1084. $now time();
  1085. $expiredIds = array();
  1086. foreach ($deferred as $key => $item) {
  1087. if (null === $item->expiry) {
  1088. $byLifetime[$item->defaultLifetime $item->defaultLifetime 0][$getId($key)] = $item->value;
  1089. } elseif ($item->expiry $now) {
  1090. $byLifetime[$item->expiry $now][$getId($key)] = $item->value;
  1091. } else {
  1092. $expiredIds[] = $getId($key);
  1093. }
  1094. }
  1095. return $byLifetime;
  1096. },
  1097. null,
  1098. CacheItem::class
  1099. );
  1100. }
  1101. public static function createSystemCache($namespace$defaultLifetime$version$directoryLoggerInterface $logger null)
  1102. {
  1103. if (null === self::$apcuSupported) {
  1104. self::$apcuSupported ApcuAdapter::isSupported();
  1105. }
  1106. if (!self::$apcuSupported && null === self::$phpFilesSupported) {
  1107. self::$phpFilesSupported PhpFilesAdapter::isSupported();
  1108. }
  1109. if (self::$phpFilesSupported) {
  1110. $opcache = new PhpFilesAdapter($namespace$defaultLifetime$directory);
  1111. if (null !== $logger) {
  1112. $opcache->setLogger($logger);
  1113. }
  1114. return $opcache;
  1115. }
  1116. $fs = new FilesystemAdapter($namespace$defaultLifetime$directory);
  1117. if (null !== $logger) {
  1118. $fs->setLogger($logger);
  1119. }
  1120. if (!self::$apcuSupported) {
  1121. return $fs;
  1122. }
  1123. $apcu = new ApcuAdapter($namespace, (int) $defaultLifetime 5$version);
  1124. if ('cli'=== \PHP_SAPI && !ini_get('apc.enable_cli')) {
  1125. $apcu->setLogger(new NullLogger());
  1126. } elseif (null !== $logger) {
  1127. $apcu->setLogger($logger);
  1128. }
  1129. return new ChainAdapter(array($apcu$fs));
  1130. }
  1131. public static function createConnection($dsn, array $options = array())
  1132. {
  1133. if (!is_string($dsn)) {
  1134. throw new InvalidArgumentException(sprintf('The %s() method expect argument #1 to be string, %s given.'__METHOD__gettype($dsn)));
  1135. }
  1136. if (=== strpos($dsn,'redis://')) {
  1137. return RedisAdapter::createConnection($dsn$options);
  1138. }
  1139. if (=== strpos($dsn,'memcached://')) {
  1140. return MemcachedAdapter::createConnection($dsn$options);
  1141. }
  1142. throw new InvalidArgumentException(sprintf('Unsupported DSN: %s.'$dsn));
  1143. }
  1144. public function getItem($key)
  1145. {
  1146. if ($this->deferred) {
  1147. $this->commit();
  1148. }
  1149. $id $this->getId($key);
  1150. $f $this->createCacheItem;
  1151. $isHit false;
  1152. $value null;
  1153. try {
  1154. foreach ($this->doFetch(array($id)) as $value) {
  1155. $isHit true;
  1156. }
  1157. } catch (\Exception $e) {
  1158. CacheItem::log($this->logger,'Failed to fetch key "{key}"', array('key'=> $key,'exception'=> $e));
  1159. }
  1160. return $f($key$value$isHit);
  1161. }
  1162. public function getItems(array $keys = array())
  1163. {
  1164. if ($this->deferred) {
  1165. $this->commit();
  1166. }
  1167. $ids = array();
  1168. foreach ($keys as $key) {
  1169. $ids[] = $this->getId($key);
  1170. }
  1171. try {
  1172. $items $this->doFetch($ids);
  1173. } catch (\Exception $e) {
  1174. CacheItem::log($this->logger,'Failed to fetch requested items', array('keys'=> $keys,'exception'=> $e));
  1175. $items = array();
  1176. }
  1177. $ids array_combine($ids$keys);
  1178. return $this->generateItems($items$ids);
  1179. }
  1180. public function save(CacheItemInterface $item)
  1181. {
  1182. if (!$item instanceof CacheItem) {
  1183. return false;
  1184. }
  1185. $this->deferred[$item->getKey()] = $item;
  1186. return $this->commit();
  1187. }
  1188. public function saveDeferred(CacheItemInterface $item)
  1189. {
  1190. if (!$item instanceof CacheItem) {
  1191. return false;
  1192. }
  1193. $this->deferred[$item->getKey()] = $item;
  1194. return true;
  1195. }
  1196. public function commit()
  1197. {
  1198. $ok true;
  1199. $byLifetime $this->mergeByLifetime;
  1200. $byLifetime $byLifetime($this->deferred$this->namespace$expiredIds);
  1201. $retry $this->deferred = array();
  1202. if ($expiredIds) {
  1203. $this->doDelete($expiredIds);
  1204. }
  1205. foreach ($byLifetime as $lifetime => $values) {
  1206. try {
  1207. $e $this->doSave($values$lifetime);
  1208. } catch (\Exception $e) {
  1209. }
  1210. if (true === $e || array() === $e) {
  1211. continue;
  1212. }
  1213. if (is_array($e) || === count($values)) {
  1214. foreach (is_array($e) ? $e array_keys($values) as $id) {
  1215. $ok false;
  1216. $v $values[$id];
  1217. $type is_object($v) ? get_class($v) : gettype($v);
  1218. CacheItem::log($this->logger,'Failed to save key "{key}" ({type})', array('key'=> substr($idstrlen($this->namespace)),'type'=> $type,'exception'=> $e instanceof \Exception $e null));
  1219. }
  1220. } else {
  1221. foreach ($values as $id => $v) {
  1222. $retry[$lifetime][] = $id;
  1223. }
  1224. }
  1225. }
  1226. foreach ($retry as $lifetime => $ids) {
  1227. foreach ($ids as $id) {
  1228. try {
  1229. $v $byLifetime[$lifetime][$id];
  1230. $e $this->doSave(array($id => $v), $lifetime);
  1231. } catch (\Exception $e) {
  1232. }
  1233. if (true === $e || array() === $e) {
  1234. continue;
  1235. }
  1236. $ok false;
  1237. $type is_object($v) ? get_class($v) : gettype($v);
  1238. CacheItem::log($this->logger,'Failed to save key "{key}" ({type})', array('key'=> substr($idstrlen($this->namespace)),'type'=> $type,'exception'=> $e instanceof \Exception $e null));
  1239. }
  1240. }
  1241. return $ok;
  1242. }
  1243. public function __destruct()
  1244. {
  1245. if ($this->deferred) {
  1246. $this->commit();
  1247. }
  1248. }
  1249. private function generateItems($items, &$keys)
  1250. {
  1251. $f $this->createCacheItem;
  1252. try {
  1253. foreach ($items as $id => $value) {
  1254. if (!isset($keys[$id])) {
  1255. $id key($keys);
  1256. }
  1257. $key $keys[$id];
  1258. unset($keys[$id]);
  1259. yield $key => $f($key$valuetrue);
  1260. }
  1261. } catch (\Exception $e) {
  1262. CacheItem::log($this->logger,'Failed to fetch requested items', array('keys'=> array_values($keys),'exception'=> $e));
  1263. }
  1264. foreach ($keys as $key) {
  1265. yield $key => $f($keynullfalse);
  1266. }
  1267. }
  1268. }
  1269. }
  1270. namespace Symfony\Component\Cache\Adapter
  1271. {
  1272. use Symfony\Component\Cache\Traits\ApcuTrait;
  1273. class ApcuAdapter extends AbstractAdapter
  1274. {
  1275. use ApcuTrait;
  1276. public function __construct($namespace =''$defaultLifetime 0$version null)
  1277. {
  1278. $this->init($namespace$defaultLifetime$version);
  1279. }
  1280. }
  1281. }
  1282. namespace Symfony\Component\Cache\Traits
  1283. {
  1284. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  1285. trait FilesystemCommonTrait
  1286. {
  1287. private $directory;
  1288. private $tmp;
  1289. private function init($namespace$directory)
  1290. {
  1291. if (!isset($directory[0])) {
  1292. $directory sys_get_temp_dir().'/symfony-cache';
  1293. } else {
  1294. $directory realpath($directory) ?: $directory;
  1295. }
  1296. if (isset($namespace[0])) {
  1297. if (preg_match('#[^-+_.A-Za-z0-9]#'$namespace$match)) {
  1298. throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.'$match[0]));
  1299. }
  1300. $directory .= DIRECTORY_SEPARATOR.$namespace;
  1301. }
  1302. if (!file_exists($directory)) {
  1303. @mkdir($directory0777true);
  1304. }
  1305. $directory .= DIRECTORY_SEPARATOR;
  1306. if ('\\'=== DIRECTORY_SEPARATOR && strlen($directory) > 234) {
  1307. throw new InvalidArgumentException(sprintf('Cache directory too long (%s)'$directory));
  1308. }
  1309. $this->directory $directory;
  1310. }
  1311. protected function doClear($namespace)
  1312. {
  1313. $ok true;
  1314. foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS)) as $file) {
  1315. $ok = ($file->isDir() || @unlink($file) || !file_exists($file)) && $ok;
  1316. }
  1317. return $ok;
  1318. }
  1319. protected function doDelete(array $ids)
  1320. {
  1321. $ok true;
  1322. foreach ($ids as $id) {
  1323. $file $this->getFile($id);
  1324. $ok = (!file_exists($file) || @unlink($file) || !file_exists($file)) && $ok;
  1325. }
  1326. return $ok;
  1327. }
  1328. private function write($file$data$expiresAt null)
  1329. {
  1330. set_error_handler(__CLASS__.'::throwError');
  1331. try {
  1332. if (null === $this->tmp) {
  1333. $this->tmp $this->directory.uniqid(''true);
  1334. }
  1335. file_put_contents($this->tmp$data);
  1336. if (null !== $expiresAt) {
  1337. touch($this->tmp$expiresAt);
  1338. }
  1339. return rename($this->tmp$file);
  1340. } finally {
  1341. restore_error_handler();
  1342. }
  1343. }
  1344. private function getFile($id$mkdir false)
  1345. {
  1346. $hash str_replace('/','-'base64_encode(hash('sha256', static::class.$idtrue)));
  1347. $dir $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR);
  1348. if ($mkdir && !file_exists($dir)) {
  1349. @mkdir($dir0777true);
  1350. }
  1351. return $dir.substr($hash220);
  1352. }
  1353. public static function throwError($type$message$file$line)
  1354. {
  1355. throw new \ErrorException($message0$type$file$line);
  1356. }
  1357. public function __destruct()
  1358. {
  1359. if (method_exists(parent::class,'__destruct')) {
  1360. parent::__destruct();
  1361. }
  1362. if (null !== $this->tmp && file_exists($this->tmp)) {
  1363. unlink($this->tmp);
  1364. }
  1365. }
  1366. }
  1367. }
  1368. namespace Symfony\Component\Cache\Traits
  1369. {
  1370. use Symfony\Component\Cache\Exception\CacheException;
  1371. trait FilesystemTrait
  1372. {
  1373. use FilesystemCommonTrait;
  1374. protected function doFetch(array $ids)
  1375. {
  1376. $values = array();
  1377. $now time();
  1378. foreach ($ids as $id) {
  1379. $file $this->getFile($id);
  1380. if (!file_exists($file) || !$h = @fopen($file,'rb')) {
  1381. continue;
  1382. }
  1383. if ($now >= (int) $expiresAt fgets($h)) {
  1384. fclose($h);
  1385. if (isset($expiresAt[0])) {
  1386. @unlink($file);
  1387. }
  1388. } else {
  1389. $i rawurldecode(rtrim(fgets($h)));
  1390. $value stream_get_contents($h);
  1391. fclose($h);
  1392. if ($i === $id) {
  1393. $values[$id] = parent::unserialize($value);
  1394. }
  1395. }
  1396. }
  1397. return $values;
  1398. }
  1399. protected function doHave($id)
  1400. {
  1401. $file $this->getFile($id);
  1402. return file_exists($file) && (@filemtime($file) > time() || $this->doFetch(array($id)));
  1403. }
  1404. protected function doSave(array $values$lifetime)
  1405. {
  1406. $ok true;
  1407. $expiresAt time() + ($lifetime ?: 31557600);
  1408. foreach ($values as $id => $value) {
  1409. $ok $this->write($this->getFile($idtrue), $expiresAt."\n".rawurlencode($id)."\n".serialize($value), $expiresAt) && $ok;
  1410. }
  1411. if (!$ok && !is_writable($this->directory)) {
  1412. throw new CacheException(sprintf('Cache directory is not writable (%s)'$this->directory));
  1413. }
  1414. return $ok;
  1415. }
  1416. }
  1417. }
  1418. namespace Symfony\Component\Cache\Adapter
  1419. {
  1420. use Symfony\Component\Cache\Traits\FilesystemTrait;
  1421. class FilesystemAdapter extends AbstractAdapter
  1422. {
  1423. use FilesystemTrait;
  1424. public function __construct($namespace =''$defaultLifetime 0$directory null)
  1425. {
  1426. parent::__construct(''$defaultLifetime);
  1427. $this->init($namespace$directory);
  1428. }
  1429. }
  1430. }
  1431. namespace Psr\Cache
  1432. {
  1433. interface CacheItemInterface
  1434. {
  1435. public function getKey();
  1436. public function get();
  1437. public function isHit();
  1438. public function set($value);
  1439. public function expiresAt($expiration);
  1440. public function expiresAfter($time);
  1441. }
  1442. }
  1443. namespace Symfony\Component\Cache
  1444. {
  1445. use Psr\Cache\CacheItemInterface;
  1446. use Psr\Log\LoggerInterface;
  1447. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  1448. final class CacheItem implements CacheItemInterface
  1449. {
  1450. protected $key;
  1451. protected $value;
  1452. protected $isHit false;
  1453. protected $expiry;
  1454. protected $defaultLifetime;
  1455. protected $tags = array();
  1456. protected $prevTags = array();
  1457. protected $innerItem;
  1458. protected $poolHash;
  1459. public function getKey()
  1460. {
  1461. return $this->key;
  1462. }
  1463. public function get()
  1464. {
  1465. return $this->value;
  1466. }
  1467. public function isHit()
  1468. {
  1469. return $this->isHit;
  1470. }
  1471. public function set($value)
  1472. {
  1473. $this->value $value;
  1474. return $this;
  1475. }
  1476. public function expiresAt($expiration)
  1477. {
  1478. if (null === $expiration) {
  1479. $this->expiry $this->defaultLifetime time() + $this->defaultLifetime null;
  1480. } elseif ($expiration instanceof \DateTimeInterface) {
  1481. $this->expiry = (int) $expiration->format('U');
  1482. } else {
  1483. throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given'is_object($expiration) ? get_class($expiration) : gettype($expiration)));
  1484. }
  1485. return $this;
  1486. }
  1487. public function expiresAfter($time)
  1488. {
  1489. if (null === $time) {
  1490. $this->expiry $this->defaultLifetime time() + $this->defaultLifetime null;
  1491. } elseif ($time instanceof \DateInterval) {
  1492. $this->expiry = (int) \DateTime::createFromFormat('U'time())->add($time)->format('U');
  1493. } elseif (is_int($time)) {
  1494. $this->expiry $time time();
  1495. } else {
  1496. throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given'is_object($time) ? get_class($time) : gettype($time)));
  1497. }
  1498. return $this;
  1499. }
  1500. public function tag($tags)
  1501. {
  1502. if (!is_array($tags)) {
  1503. $tags = array($tags);
  1504. }
  1505. foreach ($tags as $tag) {
  1506. if (!is_string($tag)) {
  1507. throw new InvalidArgumentException(sprintf('Cache tag must be string, "%s" given'is_object($tag) ? get_class($tag) : gettype($tag)));
  1508. }
  1509. if (isset($this->tags[$tag])) {
  1510. continue;
  1511. }
  1512. if (!isset($tag[0])) {
  1513. throw new InvalidArgumentException('Cache tag length must be greater than zero');
  1514. }
  1515. if (false !== strpbrk($tag,'{}()/\@:')) {
  1516. throw new InvalidArgumentException(sprintf('Cache tag "%s" contains reserved characters {}()/\@:'$tag));
  1517. }
  1518. $this->tags[$tag] = $tag;
  1519. }
  1520. return $this;
  1521. }
  1522. public function getPreviousTags()
  1523. {
  1524. return $this->prevTags;
  1525. }
  1526. public static function validateKey($key)
  1527. {
  1528. if (!is_string($key)) {
  1529. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given'is_object($key) ? get_class($key) : gettype($key)));
  1530. }
  1531. if (!isset($key[0])) {
  1532. throw new InvalidArgumentException('Cache key length must be greater than zero');
  1533. }
  1534. if (false !== strpbrk($key,'{}()/\@:')) {
  1535. throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:'$key));
  1536. }
  1537. return $key;
  1538. }
  1539. public static function log(LoggerInterface $logger null$message$context = array())
  1540. {
  1541. if ($logger) {
  1542. $logger->warning($message$context);
  1543. } else {
  1544. $replace = array();
  1545. foreach ($context as $k => $v) {
  1546. if (is_scalar($v)) {
  1547. $replace['{'.$k.'}'] = $v;
  1548. }
  1549. }
  1550. @trigger_error(strtr($message$replace), E_USER_WARNING);
  1551. }
  1552. }
  1553. }
  1554. }
  1555. namespace Symfony\Component\Routing
  1556. {
  1557. interface RequestContextAwareInterface
  1558. {
  1559. public function setContext(RequestContext $context);
  1560. public function getContext();
  1561. }
  1562. }
  1563. namespace Symfony\Component\Routing\Generator
  1564. {
  1565. use Symfony\Component\Routing\Exception\InvalidParameterException;
  1566. use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
  1567. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  1568. use Symfony\Component\Routing\RequestContextAwareInterface;
  1569. interface UrlGeneratorInterface extends RequestContextAwareInterface
  1570. {
  1571. const ABSOLUTE_URL 0;
  1572. const ABSOLUTE_PATH 1;
  1573. const RELATIVE_PATH 2;
  1574. const NETWORK_PATH 3;
  1575. public function generate($name$parameters = array(), $referenceType self::ABSOLUTE_PATH);
  1576. }
  1577. }
  1578. namespace Symfony\Component\Routing\Generator
  1579. {
  1580. interface ConfigurableRequirementsInterface
  1581. {
  1582. public function setStrictRequirements($enabled);
  1583. public function isStrictRequirements();
  1584. }
  1585. }
  1586. namespace Symfony\Component\Routing\Generator
  1587. {
  1588. use Symfony\Component\Routing\RouteCollection;
  1589. use Symfony\Component\Routing\RequestContext;
  1590. use Symfony\Component\Routing\Exception\InvalidParameterException;
  1591. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  1592. use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
  1593. use Psr\Log\LoggerInterface;
  1594. class UrlGenerator implements UrlGeneratorInterfaceConfigurableRequirementsInterface
  1595. {
  1596. protected $routes;
  1597. protected $context;
  1598. protected $strictRequirements true;
  1599. protected $logger;
  1600. protected $decodedChars = array('%2F'=>'/','%40'=>'@','%3A'=>':','%3B'=>';','%2C'=>',','%3D'=>'=','%2B'=>'+','%21'=>'!','%2A'=>'*','%7C'=>'|',
  1601. );
  1602. public function __construct(RouteCollection $routesRequestContext $contextLoggerInterface $logger null)
  1603. {
  1604. $this->routes $routes;
  1605. $this->context $context;
  1606. $this->logger $logger;
  1607. }
  1608. public function setContext(RequestContext $context)
  1609. {
  1610. $this->context $context;
  1611. }
  1612. public function getContext()
  1613. {
  1614. return $this->context;
  1615. }
  1616. public function setStrictRequirements($enabled)
  1617. {
  1618. $this->strictRequirements null === $enabled null : (bool) $enabled;
  1619. }
  1620. public function isStrictRequirements()
  1621. {
  1622. return $this->strictRequirements;
  1623. }
  1624. public function generate($name$parameters = array(), $referenceType self::ABSOLUTE_PATH)
  1625. {
  1626. if (null === $route $this->routes->get($name)) {
  1627. throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.'$name));
  1628. }
  1629. $compiledRoute $route->compile();
  1630. return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters$name$referenceType$compiledRoute->getHostTokens(), $route->getSchemes());
  1631. }
  1632. protected function doGenerate($variables$defaults$requirements$tokens$parameters$name$referenceType$hostTokens, array $requiredSchemes = array())
  1633. {
  1634. $variables array_flip($variables);
  1635. $mergedParams array_replace($defaults$this->context->getParameters(), $parameters);
  1636. if ($diff array_diff_key($variables$mergedParams)) {
  1637. throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".'implode('", "'array_keys($diff)), $name));
  1638. }
  1639. $url ='';
  1640. $optional true;
  1641. $message ='Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
  1642. foreach ($tokens as $token) {
  1643. if ('variable'=== $token[0]) {
  1644. if (!$optional || !array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
  1645. if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#'.(empty($token[4]) ?'':'u'), $mergedParams[$token[3]])) {
  1646. if ($this->strictRequirements) {
  1647. throw new InvalidParameterException(strtr($message, array('{parameter}'=> $token[3],'{route}'=> $name,'{expected}'=> $token[2],'{given}'=> $mergedParams[$token[3]])));
  1648. }
  1649. if ($this->logger) {
  1650. $this->logger->error($message, array('parameter'=> $token[3],'route'=> $name,'expected'=> $token[2],'given'=> $mergedParams[$token[3]]));
  1651. }
  1652. return;
  1653. }
  1654. $url $token[1].$mergedParams[$token[3]].$url;
  1655. $optional false;
  1656. }
  1657. } else {
  1658. $url $token[1].$url;
  1659. $optional false;
  1660. }
  1661. }
  1662. if (''=== $url) {
  1663. $url ='/';
  1664. }
  1665. $url strtr(rawurlencode($url), $this->decodedChars);
  1666. $url strtr($url, array('/../'=>'/%2E%2E/','/./'=>'/%2E/'));
  1667. if ('/..'=== substr($url, -3)) {
  1668. $url substr($url0, -2).'%2E%2E';
  1669. } elseif ('/.'=== substr($url, -2)) {
  1670. $url substr($url0, -1).'%2E';
  1671. }
  1672. $schemeAuthority ='';
  1673. $host $this->context->getHost();
  1674. $scheme $this->context->getScheme();
  1675. if ($requiredSchemes) {
  1676. if (!in_array($scheme$requiredSchemestrue)) {
  1677. $referenceType self::ABSOLUTE_URL;
  1678. $scheme current($requiredSchemes);
  1679. }
  1680. }
  1681. if ($hostTokens) {
  1682. $routeHost ='';
  1683. foreach ($hostTokens as $token) {
  1684. if ('variable'=== $token[0]) {
  1685. if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#i'.(empty($token[4]) ?'':'u'), $mergedParams[$token[3]])) {
  1686. if ($this->strictRequirements) {
  1687. throw new InvalidParameterException(strtr($message, array('{parameter}'=> $token[3],'{route}'=> $name,'{expected}'=> $token[2],'{given}'=> $mergedParams[$token[3]])));
  1688. }
  1689. if ($this->logger) {
  1690. $this->logger->error($message, array('parameter'=> $token[3],'route'=> $name,'expected'=> $token[2],'given'=> $mergedParams[$token[3]]));
  1691. }
  1692. return;
  1693. }
  1694. $routeHost $token[1].$mergedParams[$token[3]].$routeHost;
  1695. } else {
  1696. $routeHost $token[1].$routeHost;
  1697. }
  1698. }
  1699. if ($routeHost !== $host) {
  1700. $host $routeHost;
  1701. if (self::ABSOLUTE_URL !== $referenceType) {
  1702. $referenceType self::NETWORK_PATH;
  1703. }
  1704. }
  1705. }
  1706. if ((self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) && !empty($host)) {
  1707. $port ='';
  1708. if ('http'=== $scheme && 80 != $this->context->getHttpPort()) {
  1709. $port =':'.$this->context->getHttpPort();
  1710. } elseif ('https'=== $scheme && 443 != $this->context->getHttpsPort()) {
  1711. $port =':'.$this->context->getHttpsPort();
  1712. }
  1713. $schemeAuthority self::NETWORK_PATH === $referenceType ?'//'"$scheme://";
  1714. $schemeAuthority .= $host.$port;
  1715. }
  1716. if (self::RELATIVE_PATH === $referenceType) {
  1717. $url self::getRelativePath($this->context->getPathInfo(), $url);
  1718. } else {
  1719. $url $schemeAuthority.$this->context->getBaseUrl().$url;
  1720. }
  1721. $extra array_udiff_assoc(array_diff_key($parameters$variables), $defaults, function ($a$b) {
  1722. return $a == $b 1;
  1723. });
  1724. $fragment ='';
  1725. if (isset($defaults['_fragment'])) {
  1726. $fragment $defaults['_fragment'];
  1727. }
  1728. if (isset($extra['_fragment'])) {
  1729. $fragment $extra['_fragment'];
  1730. unset($extra['_fragment']);
  1731. }
  1732. if ($extra && $query http_build_query($extra,'','&'PHP_QUERY_RFC3986)) {
  1733. $url .='?'.strtr($query, array('%2F'=>'/'));
  1734. }
  1735. if (''!== $fragment) {
  1736. $url .='#'.strtr(rawurlencode($fragment), array('%2F'=>'/','%3F'=>'?'));
  1737. }
  1738. return $url;
  1739. }
  1740. public static function getRelativePath($basePath$targetPath)
  1741. {
  1742. if ($basePath === $targetPath) {
  1743. return'';
  1744. }
  1745. $sourceDirs explode('/', isset($basePath[0]) &&'/'=== $basePath[0] ? substr($basePath1) : $basePath);
  1746. $targetDirs explode('/', isset($targetPath[0]) &&'/'=== $targetPath[0] ? substr($targetPath1) : $targetPath);
  1747. array_pop($sourceDirs);
  1748. $targetFile array_pop($targetDirs);
  1749. foreach ($sourceDirs as $i => $dir) {
  1750. if (isset($targetDirs[$i]) && $dir === $targetDirs[$i]) {
  1751. unset($sourceDirs[$i], $targetDirs[$i]);
  1752. } else {
  1753. break;
  1754. }
  1755. }
  1756. $targetDirs[] = $targetFile;
  1757. $path str_repeat('../'count($sourceDirs)).implode('/'$targetDirs);
  1758. return''=== $path ||'/'=== $path[0]
  1759. || false !== ($colonPos strpos($path,':')) && ($colonPos < ($slashPos strpos($path,'/')) || false === $slashPos)
  1760. "./$path$path;
  1761. }
  1762. }
  1763. }
  1764. namespace Symfony\Component\Routing
  1765. {
  1766. use Symfony\Component\HttpFoundation\Request;
  1767. class RequestContext
  1768. {
  1769. private $baseUrl;
  1770. private $pathInfo;
  1771. private $method;
  1772. private $host;
  1773. private $scheme;
  1774. private $httpPort;
  1775. private $httpsPort;
  1776. private $queryString;
  1777. private $parameters = array();
  1778. public function __construct($baseUrl =''$method ='GET'$host ='localhost'$scheme ='http'$httpPort 80$httpsPort 443$path ='/'$queryString ='')
  1779. {
  1780. $this->setBaseUrl($baseUrl);
  1781. $this->setMethod($method);
  1782. $this->setHost($host);
  1783. $this->setScheme($scheme);
  1784. $this->setHttpPort($httpPort);
  1785. $this->setHttpsPort($httpsPort);
  1786. $this->setPathInfo($path);
  1787. $this->setQueryString($queryString);
  1788. }
  1789. public function fromRequest(Request $request)
  1790. {
  1791. $this->setBaseUrl($request->getBaseUrl());
  1792. $this->setPathInfo($request->getPathInfo());
  1793. $this->setMethod($request->getMethod());
  1794. $this->setHost($request->getHost());
  1795. $this->setScheme($request->getScheme());
  1796. $this->setHttpPort($request->isSecure() ? $this->httpPort $request->getPort());
  1797. $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
  1798. $this->setQueryString($request->server->get('QUERY_STRING',''));
  1799. return $this;
  1800. }
  1801. public function getBaseUrl()
  1802. {
  1803. return $this->baseUrl;
  1804. }
  1805. public function setBaseUrl($baseUrl)
  1806. {
  1807. $this->baseUrl $baseUrl;
  1808. return $this;
  1809. }
  1810. public function getPathInfo()
  1811. {
  1812. return $this->pathInfo;
  1813. }
  1814. public function setPathInfo($pathInfo)
  1815. {
  1816. $this->pathInfo $pathInfo;
  1817. return $this;
  1818. }
  1819. public function getMethod()
  1820. {
  1821. return $this->method;
  1822. }
  1823. public function setMethod($method)
  1824. {
  1825. $this->method strtoupper($method);
  1826. return $this;
  1827. }
  1828. public function getHost()
  1829. {
  1830. return $this->host;
  1831. }
  1832. public function setHost($host)
  1833. {
  1834. $this->host strtolower($host);
  1835. return $this;
  1836. }
  1837. public function getScheme()
  1838. {
  1839. return $this->scheme;
  1840. }
  1841. public function setScheme($scheme)
  1842. {
  1843. $this->scheme strtolower($scheme);
  1844. return $this;
  1845. }
  1846. public function getHttpPort()
  1847. {
  1848. return $this->httpPort;
  1849. }
  1850. public function setHttpPort($httpPort)
  1851. {
  1852. $this->httpPort = (int) $httpPort;
  1853. return $this;
  1854. }
  1855. public function getHttpsPort()
  1856. {
  1857. return $this->httpsPort;
  1858. }
  1859. public function setHttpsPort($httpsPort)
  1860. {
  1861. $this->httpsPort = (int) $httpsPort;
  1862. return $this;
  1863. }
  1864. public function getQueryString()
  1865. {
  1866. return $this->queryString;
  1867. }
  1868. public function setQueryString($queryString)
  1869. {
  1870. $this->queryString = (string) $queryString;
  1871. return $this;
  1872. }
  1873. public function getParameters()
  1874. {
  1875. return $this->parameters;
  1876. }
  1877. public function setParameters(array $parameters)
  1878. {
  1879. $this->parameters $parameters;
  1880. return $this;
  1881. }
  1882. public function getParameter($name)
  1883. {
  1884. return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
  1885. }
  1886. public function hasParameter($name)
  1887. {
  1888. return array_key_exists($name$this->parameters);
  1889. }
  1890. public function setParameter($name$parameter)
  1891. {
  1892. $this->parameters[$name] = $parameter;
  1893. return $this;
  1894. }
  1895. }
  1896. }
  1897. namespace Symfony\Component\Routing\Matcher
  1898. {
  1899. use Symfony\Component\Routing\RequestContextAwareInterface;
  1900. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1901. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  1902. interface UrlMatcherInterface extends RequestContextAwareInterface
  1903. {
  1904. public function match($pathinfo);
  1905. }
  1906. }
  1907. namespace Symfony\Component\Routing
  1908. {
  1909. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  1910. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  1911. interface RouterInterface extends UrlMatcherInterfaceUrlGeneratorInterface
  1912. {
  1913. public function getRouteCollection();
  1914. }
  1915. }
  1916. namespace Symfony\Component\Routing\Matcher
  1917. {
  1918. use Symfony\Component\HttpFoundation\Request;
  1919. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  1920. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  1921. interface RequestMatcherInterface
  1922. {
  1923. public function matchRequest(Request $request);
  1924. }
  1925. }
  1926. namespace Symfony\Component\Routing
  1927. {
  1928. use Symfony\Component\Config\Loader\LoaderInterface;
  1929. use Symfony\Component\Config\ConfigCacheInterface;
  1930. use Symfony\Component\Config\ConfigCacheFactoryInterface;
  1931. use Symfony\Component\Config\ConfigCacheFactory;
  1932. use Psr\Log\LoggerInterface;
  1933. use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
  1934. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  1935. use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
  1936. use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
  1937. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  1938. use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
  1939. use Symfony\Component\HttpFoundation\Request;
  1940. use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
  1941. class Router implements RouterInterfaceRequestMatcherInterface
  1942. {
  1943. protected $matcher;
  1944. protected $generator;
  1945. protected $context;
  1946. protected $loader;
  1947. protected $collection;
  1948. protected $resource;
  1949. protected $options = array();
  1950. protected $logger;
  1951. private $configCacheFactory;
  1952. private $expressionLanguageProviders = array();
  1953. public function __construct(LoaderInterface $loader$resource, array $options = array(), RequestContext $context nullLoggerInterface $logger null)
  1954. {
  1955. $this->loader $loader;
  1956. $this->resource $resource;
  1957. $this->logger $logger;
  1958. $this->context $context ?: new RequestContext();
  1959. $this->setOptions($options);
  1960. }
  1961. public function setOptions(array $options)
  1962. {
  1963. $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,
  1964. );
  1965. $invalid = array();
  1966. foreach ($options as $key => $value) {
  1967. if (array_key_exists($key$this->options)) {
  1968. $this->options[$key] = $value;
  1969. } else {
  1970. $invalid[] = $key;
  1971. }
  1972. }
  1973. if ($invalid) {
  1974. throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".'implode('", "'$invalid)));
  1975. }
  1976. }
  1977. public function setOption($key$value)
  1978. {
  1979. if (!array_key_exists($key$this->options)) {
  1980. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.'$key));
  1981. }
  1982. $this->options[$key] = $value;
  1983. }
  1984. public function getOption($key)
  1985. {
  1986. if (!array_key_exists($key$this->options)) {
  1987. throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.'$key));
  1988. }
  1989. return $this->options[$key];
  1990. }
  1991. public function getRouteCollection()
  1992. {
  1993. if (null === $this->collection) {
  1994. $this->collection $this->loader->load($this->resource$this->options['resource_type']);
  1995. }
  1996. return $this->collection;
  1997. }
  1998. public function setContext(RequestContext $context)
  1999. {
  2000. $this->context $context;
  2001. if (null !== $this->matcher) {
  2002. $this->getMatcher()->setContext($context);
  2003. }
  2004. if (null !== $this->generator) {
  2005. $this->getGenerator()->setContext($context);
  2006. }
  2007. }
  2008. public function getContext()
  2009. {
  2010. return $this->context;
  2011. }
  2012. public function setConfigCacheFactory(ConfigCacheFactoryInterface $configCacheFactory)
  2013. {
  2014. $this->configCacheFactory $configCacheFactory;
  2015. }
  2016. public function generate($name$parameters = array(), $referenceType self::ABSOLUTE_PATH)
  2017. {
  2018. return $this->getGenerator()->generate($name$parameters$referenceType);
  2019. }
  2020. public function match($pathinfo)
  2021. {
  2022. return $this->getMatcher()->match($pathinfo);
  2023. }
  2024. public function matchRequest(Request $request)
  2025. {
  2026. $matcher $this->getMatcher();
  2027. if (!$matcher instanceof RequestMatcherInterface) {
  2028. return $matcher->match($request->getPathInfo());
  2029. }
  2030. return $matcher->matchRequest($request);
  2031. }
  2032. public function getMatcher()
  2033. {
  2034. if (null !== $this->matcher) {
  2035. return $this->matcher;
  2036. }
  2037. if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
  2038. $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
  2039. if (method_exists($this->matcher,'addExpressionLanguageProvider')) {
  2040. foreach ($this->expressionLanguageProviders as $provider) {
  2041. $this->matcher->addExpressionLanguageProvider($provider);
  2042. }
  2043. }
  2044. return $this->matcher;
  2045. }
  2046. $cache $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['matcher_cache_class'].'.php',
  2047. function (ConfigCacheInterface $cache) {
  2048. $dumper $this->getMatcherDumperInstance();
  2049. if (method_exists($dumper,'addExpressionLanguageProvider')) {
  2050. foreach ($this->expressionLanguageProviders as $provider) {
  2051. $dumper->addExpressionLanguageProvider($provider);
  2052. }
  2053. }
  2054. $options = array('class'=> $this->options['matcher_cache_class'],'base_class'=> $this->options['matcher_base_class'],
  2055. );
  2056. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  2057. }
  2058. );
  2059. require_once $cache->getPath();
  2060. return $this->matcher = new $this->options['matcher_cache_class']($this->context);
  2061. }
  2062. public function getGenerator()
  2063. {
  2064. if (null !== $this->generator) {
  2065. return $this->generator;
  2066. }
  2067. if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
  2068. $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context$this->logger);
  2069. } else {
  2070. $cache $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/'.$this->options['generator_cache_class'].'.php',
  2071. function (ConfigCacheInterface $cache) {
  2072. $dumper $this->getGeneratorDumperInstance();
  2073. $options = array('class'=> $this->options['generator_cache_class'],'base_class'=> $this->options['generator_base_class'],
  2074. );
  2075. $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
  2076. }
  2077. );
  2078. require_once $cache->getPath();
  2079. $this->generator = new $this->options['generator_cache_class']($this->context$this->logger);
  2080. }
  2081. if ($this->generator instanceof ConfigurableRequirementsInterface) {
  2082. $this->generator->setStrictRequirements($this->options['strict_requirements']);
  2083. }
  2084. return $this->generator;
  2085. }
  2086. public function addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider)
  2087. {
  2088. $this->expressionLanguageProviders[] = $provider;
  2089. }
  2090. protected function getGeneratorDumperInstance()
  2091. {
  2092. return new $this->options['generator_dumper_class']($this->getRouteCollection());
  2093. }
  2094. protected function getMatcherDumperInstance()
  2095. {
  2096. return new $this->options['matcher_dumper_class']($this->getRouteCollection());
  2097. }
  2098. private function getConfigCacheFactory()
  2099. {
  2100. if (null === $this->configCacheFactory) {
  2101. $this->configCacheFactory = new ConfigCacheFactory($this->options['debug']);
  2102. }
  2103. return $this->configCacheFactory;
  2104. }
  2105. }
  2106. }
  2107. namespace Symfony\Component\Routing\Matcher
  2108. {
  2109. interface RedirectableUrlMatcherInterface
  2110. {
  2111. public function redirect($path$route$scheme null);
  2112. }
  2113. }
  2114. namespace Symfony\Component\Routing\Matcher
  2115. {
  2116. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  2117. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  2118. use Symfony\Component\Routing\RouteCollection;
  2119. use Symfony\Component\Routing\RequestContext;
  2120. use Symfony\Component\Routing\Route;
  2121. use Symfony\Component\HttpFoundation\Request;
  2122. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  2123. use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
  2124. class UrlMatcher implements UrlMatcherInterfaceRequestMatcherInterface
  2125. {
  2126. const REQUIREMENT_MATCH 0;
  2127. const REQUIREMENT_MISMATCH 1;
  2128. const ROUTE_MATCH 2;
  2129. protected $context;
  2130. protected $allow = array();
  2131. protected $routes;
  2132. protected $request;
  2133. protected $expressionLanguage;
  2134. protected $expressionLanguageProviders = array();
  2135. public function __construct(RouteCollection $routesRequestContext $context)
  2136. {
  2137. $this->routes $routes;
  2138. $this->context $context;
  2139. }
  2140. public function setContext(RequestContext $context)
  2141. {
  2142. $this->context $context;
  2143. }
  2144. public function getContext()
  2145. {
  2146. return $this->context;
  2147. }
  2148. public function match($pathinfo)
  2149. {
  2150. $this->allow = array();
  2151. if ($ret $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
  2152. return $ret;
  2153. }
  2154. throw count($this->allow)
  2155. ? new MethodNotAllowedException(array_unique($this->allow))
  2156. : new ResourceNotFoundException(sprintf('No routes found for "%s".'$pathinfo));
  2157. }
  2158. public function matchRequest(Request $request)
  2159. {
  2160. $this->request $request;
  2161. $ret $this->match($request->getPathInfo());
  2162. $this->request null;
  2163. return $ret;
  2164. }
  2165. public function addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider)
  2166. {
  2167. $this->expressionLanguageProviders[] = $provider;
  2168. }
  2169. protected function matchCollection($pathinfoRouteCollection $routes)
  2170. {
  2171. foreach ($routes as $name => $route) {
  2172. $compiledRoute $route->compile();
  2173. if (''!== $compiledRoute->getStaticPrefix() && !== strpos($pathinfo$compiledRoute->getStaticPrefix())) {
  2174. continue;
  2175. }
  2176. if (!preg_match($compiledRoute->getRegex(), $pathinfo$matches)) {
  2177. continue;
  2178. }
  2179. $hostMatches = array();
  2180. if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
  2181. continue;
  2182. }
  2183. if ($requiredMethods $route->getMethods()) {
  2184. if ('HEAD'=== $method $this->context->getMethod()) {
  2185. $method ='GET';
  2186. }
  2187. if (!in_array($method$requiredMethods)) {
  2188. $this->allow array_merge($this->allow$requiredMethods);
  2189. continue;
  2190. }
  2191. }
  2192. $status $this->handleRouteRequirements($pathinfo$name$route);
  2193. if (self::ROUTE_MATCH === $status[0]) {
  2194. return $status[1];
  2195. }
  2196. if (self::REQUIREMENT_MISMATCH === $status[0]) {
  2197. continue;
  2198. }
  2199. return $this->getAttributes($route$namearray_replace($matches$hostMatches));
  2200. }
  2201. }
  2202. protected function getAttributes(Route $route$name, array $attributes)
  2203. {
  2204. $attributes['_route'] = $name;
  2205. return $this->mergeDefaults($attributes$route->getDefaults());
  2206. }
  2207. protected function handleRouteRequirements($pathinfo$nameRoute $route)
  2208. {
  2209. if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context'=> $this->context,'request'=> $this->request ?: $this->createRequest($pathinfo)))) {
  2210. return array(self::REQUIREMENT_MISMATCHnull);
  2211. }
  2212. $scheme $this->context->getScheme();
  2213. $status $route->getSchemes() && !$route->hasScheme($scheme) ? self::REQUIREMENT_MISMATCH self::REQUIREMENT_MATCH;
  2214. return array($statusnull);
  2215. }
  2216. protected function mergeDefaults($params$defaults)
  2217. {
  2218. foreach ($params as $key => $value) {
  2219. if (!is_int($key)) {
  2220. $defaults[$key] = $value;
  2221. }
  2222. }
  2223. return $defaults;
  2224. }
  2225. protected function getExpressionLanguage()
  2226. {
  2227. if (null === $this->expressionLanguage) {
  2228. if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
  2229. throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
  2230. }
  2231. $this->expressionLanguage = new ExpressionLanguage(null$this->expressionLanguageProviders);
  2232. }
  2233. return $this->expressionLanguage;
  2234. }
  2235. protected function createRequest($pathinfo)
  2236. {
  2237. if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
  2238. return null;
  2239. }
  2240. return Request::create($this->context->getScheme().'://'.$this->context->getHost().$this->context->getBaseUrl().$pathinfo$this->context->getMethod(), $this->context->getParameters(), array(), array(), array('SCRIPT_FILENAME'=> $this->context->getBaseUrl(),'SCRIPT_NAME'=> $this->context->getBaseUrl(),
  2241. ));
  2242. }
  2243. }
  2244. }
  2245. namespace Symfony\Component\Routing\Matcher
  2246. {
  2247. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  2248. use Symfony\Component\Routing\Route;
  2249. abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
  2250. {
  2251. public function match($pathinfo)
  2252. {
  2253. try {
  2254. $parameters parent::match($pathinfo);
  2255. } catch (ResourceNotFoundException $e) {
  2256. if ('/'=== substr($pathinfo, -1) || !in_array($this->context->getMethod(), array('HEAD','GET'))) {
  2257. throw $e;
  2258. }
  2259. try {
  2260. parent::match($pathinfo.'/');
  2261. return $this->redirect($pathinfo.'/'null);
  2262. } catch (ResourceNotFoundException $e2) {
  2263. throw $e;
  2264. }
  2265. }
  2266. return $parameters;
  2267. }
  2268. protected function handleRouteRequirements($pathinfo$nameRoute $route)
  2269. {
  2270. if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context'=> $this->context,'request'=> $this->request ?: $this->createRequest($pathinfo)))) {
  2271. return array(self::REQUIREMENT_MISMATCHnull);
  2272. }
  2273. $scheme $this->context->getScheme();
  2274. $schemes $route->getSchemes();
  2275. if ($schemes && !$route->hasScheme($scheme)) {
  2276. return array(self::ROUTE_MATCH$this->redirect($pathinfo$namecurrent($schemes)));
  2277. }
  2278. return array(self::REQUIREMENT_MATCHnull);
  2279. }
  2280. }
  2281. }
  2282. namespace Symfony\Bundle\FrameworkBundle\Routing
  2283. {
  2284. use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
  2285. class RedirectableUrlMatcher extends BaseMatcher
  2286. {
  2287. public function redirect($path$route$scheme null)
  2288. {
  2289. 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,
  2290. );
  2291. }
  2292. }
  2293. }
  2294. namespace Symfony\Component\HttpKernel\CacheWarmer
  2295. {
  2296. interface WarmableInterface
  2297. {
  2298. public function warmUp($cacheDir);
  2299. }
  2300. }
  2301. namespace Symfony\Component\DependencyInjection
  2302. {
  2303. interface ServiceSubscriberInterface
  2304. {
  2305. public static function getSubscribedServices();
  2306. }
  2307. }
  2308. namespace Symfony\Bundle\FrameworkBundle\Routing
  2309. {
  2310. use Symfony\Component\Config\Loader\LoaderInterface;
  2311. use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
  2312. use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
  2313. use Symfony\Component\Routing\Router as BaseRouter;
  2314. use Symfony\Component\Routing\RequestContext;
  2315. use Symfony\Component\DependencyInjection\ContainerInterface;
  2316. use Symfony\Component\Routing\RouteCollection;
  2317. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  2318. use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
  2319. use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  2320. class Router extends BaseRouter implements WarmableInterfaceServiceSubscriberInterface
  2321. {
  2322. private $container;
  2323. private $collectedParameters = array();
  2324. public function __construct(ContainerInterface $container$resource, array $options = array(), RequestContext $context null)
  2325. {
  2326. $this->container $container;
  2327. $this->resource $resource;
  2328. $this->context $context ?: new RequestContext();
  2329. $this->setOptions($options);
  2330. }
  2331. public function getRouteCollection()
  2332. {
  2333. if (null === $this->collection) {
  2334. $this->collection $this->container->get('routing.loader')->load($this->resource$this->options['resource_type']);
  2335. $this->resolveParameters($this->collection);
  2336. $this->collection->addResource(new ContainerParametersResource($this->collectedParameters));
  2337. }
  2338. return $this->collection;
  2339. }
  2340. public function warmUp($cacheDir)
  2341. {
  2342. $currentDir $this->getOption('cache_dir');
  2343. $this->setOption('cache_dir'$cacheDir);
  2344. $this->getMatcher();
  2345. $this->getGenerator();
  2346. $this->setOption('cache_dir'$currentDir);
  2347. }
  2348. private function resolveParameters(RouteCollection $collection)
  2349. {
  2350. foreach ($collection as $route) {
  2351. foreach ($route->getDefaults() as $name => $value) {
  2352. $route->setDefault($name$this->resolve($value));
  2353. }
  2354. foreach ($route->getRequirements() as $name => $value) {
  2355. $route->setRequirement($name$this->resolve($value));
  2356. }
  2357. $route->setPath($this->resolve($route->getPath()));
  2358. $route->setHost($this->resolve($route->getHost()));
  2359. $schemes = array();
  2360. foreach ($route->getSchemes() as $scheme) {
  2361. $schemes array_merge($schemesexplode('|'$this->resolve($scheme)));
  2362. }
  2363. $route->setSchemes($schemes);
  2364. $methods = array();
  2365. foreach ($route->getMethods() as $method) {
  2366. $methods array_merge($methodsexplode('|'$this->resolve($method)));
  2367. }
  2368. $route->setMethods($methods);
  2369. $route->setCondition($this->resolve($route->getCondition()));
  2370. }
  2371. }
  2372. private function resolve($value)
  2373. {
  2374. if (is_array($value)) {
  2375. foreach ($value as $key => $val) {
  2376. $value[$key] = $this->resolve($val);
  2377. }
  2378. return $value;
  2379. }
  2380. if (!is_string($value)) {
  2381. return $value;
  2382. }
  2383. $container $this->container;
  2384. $escapedValue preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container$value) {
  2385. if (!isset($match[1])) {
  2386. return'%%';
  2387. }
  2388. if (preg_match('/^env\(\w+\)$/'$match[1])) {
  2389. throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.'$match[1]));
  2390. }
  2391. $resolved $container->getParameter($match[1]);
  2392. if (is_string($resolved) || is_numeric($resolved)) {
  2393. $this->collectedParameters[$match[1]] = $resolved;
  2394. return (string) $resolved;
  2395. }
  2396. throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", '.'must be a string or numeric, but it is of type %s.',
  2397. $match[1],
  2398. $value,
  2399. gettype($resolved)
  2400. )
  2401. );
  2402. }, $value);
  2403. return str_replace('%%','%'$escapedValue);
  2404. }
  2405. public static function getSubscribedServices()
  2406. {
  2407. return array('routing.loader'=> LoaderInterface::class,
  2408. );
  2409. }
  2410. }
  2411. }
  2412. namespace Symfony\Component\Cache\Traits
  2413. {
  2414. use Symfony\Component\Cache\CacheItem;
  2415. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  2416. trait PhpArrayTrait
  2417. {
  2418. private $file;
  2419. private $values;
  2420. private $fallbackPool;
  2421. private $zendDetectUnicode;
  2422. public function warmUp(array $values)
  2423. {
  2424. if (file_exists($this->file)) {
  2425. if (!is_file($this->file)) {
  2426. throw new InvalidArgumentException(sprintf('Cache path exists and is not a file: %s.'$this->file));
  2427. }
  2428. if (!is_writable($this->file)) {
  2429. throw new InvalidArgumentException(sprintf('Cache file is not writable: %s.'$this->file));
  2430. }
  2431. } else {
  2432. $directory dirname($this->file);
  2433. if (!is_dir($directory) && !@mkdir($directory0777true)) {
  2434. throw new InvalidArgumentException(sprintf('Cache directory does not exist and cannot be created: %s.'$directory));
  2435. }
  2436. if (!is_writable($directory)) {
  2437. throw new InvalidArgumentException(sprintf('Cache directory is not writable: %s.'$directory));
  2438. }
  2439. }
  2440. $dump =<<<'EOF'
  2441. <?php
  2442. // This file has been auto-generated by the Symfony Cache Component.
  2443. return array(
  2444. EOF
  2445. ;
  2446. foreach ($values as $key => $value) {
  2447. CacheItem::validateKey(is_int($key) ? (string) $key $key);
  2448. if (null === $value || is_object($value)) {
  2449. try {
  2450. $value serialize($value);
  2451. } catch (\Exception $e) {
  2452. throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.'$keyget_class($value)), 0$e);
  2453. }
  2454. } elseif (is_array($value)) {
  2455. try {
  2456. $serialized serialize($value);
  2457. $unserialized unserialize($serialized);
  2458. } catch (\Exception $e) {
  2459. throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable array value.'$key), 0$e);
  2460. }
  2461. if ($unserialized !== $value || (false !== strpos($serialized,';R:') && preg_match('/;R:[1-9]/'$serialized))) {
  2462. $value $serialized;
  2463. }
  2464. } elseif (is_string($value)) {
  2465. if ('N;'=== $value || (isset($value[2]) &&':'=== $value[1])) {
  2466. $value serialize($value);
  2467. }
  2468. } elseif (!is_scalar($value)) {
  2469. throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.'$keygettype($value)));
  2470. }
  2471. $dump .= var_export($keytrue).' => '.var_export($valuetrue).",\n";
  2472. }
  2473. $dump .="\n);\n";
  2474. $dump str_replace("' . \"\\0\" . '","\0"$dump);
  2475. $tmpFile uniqid($this->filetrue);
  2476. file_put_contents($tmpFile$dump);
  2477. @chmod($tmpFile0666 & ~umask());
  2478. unset($serialized$unserialized$value$dump);
  2479. @rename($tmpFile$this->file);
  2480. $this->initialize();
  2481. }
  2482. public function clear()
  2483. {
  2484. $this->values = array();
  2485. $cleared = @unlink($this->file) || !file_exists($this->file);
  2486. return $this->fallbackPool->clear() && $cleared;
  2487. }
  2488. private function initialize()
  2489. {
  2490. if ($this->zendDetectUnicode) {
  2491. $zmb ini_set('zend.detect_unicode'0);
  2492. }
  2493. try {
  2494. $this->values file_exists($this->file) ? (include $this->file ?: array()) : array();
  2495. } finally {
  2496. if ($this->zendDetectUnicode) {
  2497. ini_set('zend.detect_unicode'$zmb);
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. namespace Symfony\Component\Cache\Adapter
  2504. {
  2505. use Psr\Cache\CacheItemInterface;
  2506. use Psr\Cache\CacheItemPoolInterface;
  2507. use Symfony\Component\Cache\CacheItem;
  2508. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  2509. use Symfony\Component\Cache\Traits\PhpArrayTrait;
  2510. class PhpArrayAdapter implements AdapterInterface
  2511. {
  2512. use PhpArrayTrait;
  2513. private $createCacheItem;
  2514. public function __construct($fileAdapterInterface $fallbackPool)
  2515. {
  2516. $this->file $file;
  2517. $this->fallbackPool $fallbackPool;
  2518. $this->zendDetectUnicode ini_get('zend.detect_unicode');
  2519. $this->createCacheItem = \Closure::bind(
  2520. function ($key$value$isHit) {
  2521. $item = new CacheItem();
  2522. $item->key $key;
  2523. $item->value $value;
  2524. $item->isHit $isHit;
  2525. return $item;
  2526. },
  2527. null,
  2528. CacheItem::class
  2529. );
  2530. }
  2531. public static function create($fileCacheItemPoolInterface $fallbackPool)
  2532. {
  2533. if ((\PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
  2534. if (!$fallbackPool instanceof AdapterInterface) {
  2535. $fallbackPool = new ProxyAdapter($fallbackPool);
  2536. }
  2537. return new static($file$fallbackPool);
  2538. }
  2539. return $fallbackPool;
  2540. }
  2541. public function getItem($key)
  2542. {
  2543. if (!is_string($key)) {
  2544. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.'is_object($key) ? get_class($key) : gettype($key)));
  2545. }
  2546. if (null === $this->values) {
  2547. $this->initialize();
  2548. }
  2549. if (!isset($this->values[$key])) {
  2550. return $this->fallbackPool->getItem($key);
  2551. }
  2552. $value $this->values[$key];
  2553. $isHit true;
  2554. if ('N;'=== $value) {
  2555. $value null;
  2556. } elseif (is_string($value) && isset($value[2]) &&':'=== $value[1]) {
  2557. try {
  2558. $e null;
  2559. $value unserialize($value);
  2560. } catch (\Error $e) {
  2561. } catch (\Exception $e) {
  2562. }
  2563. if (null !== $e) {
  2564. $value null;
  2565. $isHit false;
  2566. }
  2567. }
  2568. $f $this->createCacheItem;
  2569. return $f($key$value$isHit);
  2570. }
  2571. public function getItems(array $keys = array())
  2572. {
  2573. foreach ($keys as $key) {
  2574. if (!is_string($key)) {
  2575. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.'is_object($key) ? get_class($key) : gettype($key)));
  2576. }
  2577. }
  2578. if (null === $this->values) {
  2579. $this->initialize();
  2580. }
  2581. return $this->generateItems($keys);
  2582. }
  2583. public function hasItem($key)
  2584. {
  2585. if (!is_string($key)) {
  2586. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.'is_object($key) ? get_class($key) : gettype($key)));
  2587. }
  2588. if (null === $this->values) {
  2589. $this->initialize();
  2590. }
  2591. return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
  2592. }
  2593. public function deleteItem($key)
  2594. {
  2595. if (!is_string($key)) {
  2596. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.'is_object($key) ? get_class($key) : gettype($key)));
  2597. }
  2598. if (null === $this->values) {
  2599. $this->initialize();
  2600. }
  2601. return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
  2602. }
  2603. public function deleteItems(array $keys)
  2604. {
  2605. $deleted true;
  2606. $fallbackKeys = array();
  2607. foreach ($keys as $key) {
  2608. if (!is_string($key)) {
  2609. throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.'is_object($key) ? get_class($key) : gettype($key)));
  2610. }
  2611. if (isset($this->values[$key])) {
  2612. $deleted false;
  2613. } else {
  2614. $fallbackKeys[] = $key;
  2615. }
  2616. }
  2617. if (null === $this->values) {
  2618. $this->initialize();
  2619. }
  2620. if ($fallbackKeys) {
  2621. $deleted $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
  2622. }
  2623. return $deleted;
  2624. }
  2625. public function save(CacheItemInterface $item)
  2626. {
  2627. if (null === $this->values) {
  2628. $this->initialize();
  2629. }
  2630. return !isset($this->values[$item->getKey()]) && $this->fallbackPool->save($item);
  2631. }
  2632. public function saveDeferred(CacheItemInterface $item)
  2633. {
  2634. if (null === $this->values) {
  2635. $this->initialize();
  2636. }
  2637. return !isset($this->values[$item->getKey()]) && $this->fallbackPool->saveDeferred($item);
  2638. }
  2639. public function commit()
  2640. {
  2641. return $this->fallbackPool->commit();
  2642. }
  2643. private function generateItems(array $keys)
  2644. {
  2645. $f $this->createCacheItem;
  2646. $fallbackKeys = array();
  2647. foreach ($keys as $key) {
  2648. if (isset($this->values[$key])) {
  2649. $value $this->values[$key];
  2650. if ('N;'=== $value) {
  2651. yield $key => $f($keynulltrue);
  2652. } elseif (is_string($value) && isset($value[2]) &&':'=== $value[1]) {
  2653. try {
  2654. yield $key => $f($keyunserialize($value), true);
  2655. } catch (\Error $e) {
  2656. yield $key => $f($keynullfalse);
  2657. } catch (\Exception $e) {
  2658. yield $key => $f($keynullfalse);
  2659. }
  2660. } else {
  2661. yield $key => $f($key$valuetrue);
  2662. }
  2663. } else {
  2664. $fallbackKeys[] = $key;
  2665. }
  2666. }
  2667. if ($fallbackKeys) {
  2668. foreach ($this->fallbackPool->getItems($fallbackKeys) as $key => $item) {
  2669. yield $key => $item;
  2670. }
  2671. }
  2672. }
  2673. public static function throwOnRequiredClass($class)
  2674. {
  2675. $e = new \ReflectionException("Class $class does not exist");
  2676. $trace $e->getTrace();
  2677. $autoloadFrame = array('function'=>'spl_autoload_call','args'=> array($class),
  2678. );
  2679. $i array_search($autoloadFrame$tracetrue);
  2680. if (isset($trace[$i]['function']) && !isset($trace[$i]['class'])) {
  2681. switch ($trace[$i]['function']) {
  2682. case'get_class_methods':
  2683. case'get_class_vars':
  2684. case'get_parent_class':
  2685. case'is_a':
  2686. case'is_subclass_of':
  2687. case'class_exists':
  2688. case'class_implements':
  2689. case'class_parents':
  2690. case'trait_exists':
  2691. case'defined':
  2692. case'interface_exists':
  2693. case'method_exists':
  2694. case'property_exists':
  2695. case'is_callable':
  2696. return;
  2697. }
  2698. }
  2699. throw $e;
  2700. }
  2701. }
  2702. }
  2703. namespace Doctrine\Common\Cache
  2704. {
  2705. interface MultiPutCache
  2706. {
  2707. function saveMultiple(array $keysAndValues$lifetime 0);
  2708. }
  2709. }
  2710. namespace Doctrine\Common\Cache
  2711. {
  2712. interface MultiGetCache
  2713. {
  2714. function fetchMultiple(array $keys);
  2715. }
  2716. }
  2717. namespace Doctrine\Common\Cache
  2718. {
  2719. interface ClearableCache
  2720. {
  2721. public function deleteAll();
  2722. }
  2723. }
  2724. namespace Doctrine\Common\Cache
  2725. {
  2726. interface FlushableCache
  2727. {
  2728. public function flushAll();
  2729. }
  2730. }
  2731. namespace Doctrine\Common\Cache
  2732. {
  2733. interface Cache
  2734. {
  2735. const STATS_HITS ='hits';
  2736. const STATS_MISSES ='misses';
  2737. const STATS_UPTIME ='uptime';
  2738. const STATS_MEMORY_USAGE ='memory_usage';
  2739. const STATS_MEMORY_AVAILABLE ='memory_available';
  2740. const STATS_MEMORY_AVAILIABLE ='memory_available';
  2741. public function fetch($id);
  2742. public function contains($id);
  2743. public function save($id$data$lifeTime 0);
  2744. public function delete($id);
  2745. public function getStats();
  2746. }
  2747. }
  2748. namespace Doctrine\Common\Cache
  2749. {
  2750. abstract class CacheProvider implements CacheFlushableCacheClearableCacheMultiGetCacheMultiPutCache
  2751. {
  2752. const DOCTRINE_NAMESPACE_CACHEKEY ='DoctrineNamespaceCacheKey[%s]';
  2753. private $namespace ='';
  2754. private $namespaceVersion;
  2755. public function setNamespace($namespace)
  2756. {
  2757. $this->namespace = (string) $namespace;
  2758. $this->namespaceVersion null;
  2759. }
  2760. public function getNamespace()
  2761. {
  2762. return $this->namespace;
  2763. }
  2764. public function fetch($id)
  2765. {
  2766. return $this->doFetch($this->getNamespacedId($id));
  2767. }
  2768. public function fetchMultiple(array $keys)
  2769. {
  2770. if (empty($keys)) {
  2771. return array();
  2772. }
  2773. $namespacedKeys array_combine($keysarray_map(array($this,'getNamespacedId'), $keys));
  2774. $items $this->doFetchMultiple($namespacedKeys);
  2775. $foundItems = array();
  2776. foreach ($namespacedKeys as $requestedKey => $namespacedKey) {
  2777. if (isset($items[$namespacedKey]) || array_key_exists($namespacedKey$items)) {
  2778. $foundItems[$requestedKey] = $items[$namespacedKey];
  2779. }
  2780. }
  2781. return $foundItems;
  2782. }
  2783. public function saveMultiple(array $keysAndValues$lifetime 0)
  2784. {
  2785. $namespacedKeysAndValues = array();
  2786. foreach ($keysAndValues as $key => $value) {
  2787. $namespacedKeysAndValues[$this->getNamespacedId($key)] = $value;
  2788. }
  2789. return $this->doSaveMultiple($namespacedKeysAndValues$lifetime);
  2790. }
  2791. public function contains($id)
  2792. {
  2793. return $this->doContains($this->getNamespacedId($id));
  2794. }
  2795. public function save($id$data$lifeTime 0)
  2796. {
  2797. return $this->doSave($this->getNamespacedId($id), $data$lifeTime);
  2798. }
  2799. public function delete($id)
  2800. {
  2801. return $this->doDelete($this->getNamespacedId($id));
  2802. }
  2803. public function getStats()
  2804. {
  2805. return $this->doGetStats();
  2806. }
  2807. public function flushAll()
  2808. {
  2809. return $this->doFlush();
  2810. }
  2811. public function deleteAll()
  2812. {
  2813. $namespaceCacheKey $this->getNamespaceCacheKey();
  2814. $namespaceVersion $this->getNamespaceVersion() + 1;
  2815. if ($this->doSave($namespaceCacheKey$namespaceVersion)) {
  2816. $this->namespaceVersion $namespaceVersion;
  2817. return true;
  2818. }
  2819. return false;
  2820. }
  2821. private function getNamespacedId($id)
  2822. {
  2823. $namespaceVersion $this->getNamespaceVersion();
  2824. return sprintf('%s[%s][%s]'$this->namespace$id$namespaceVersion);
  2825. }
  2826. private function getNamespaceCacheKey()
  2827. {
  2828. return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY$this->namespace);
  2829. }
  2830. private function getNamespaceVersion()
  2831. {
  2832. if (null !== $this->namespaceVersion) {
  2833. return $this->namespaceVersion;
  2834. }
  2835. $namespaceCacheKey $this->getNamespaceCacheKey();
  2836. $this->namespaceVersion $this->doFetch($namespaceCacheKey) ?: 1;
  2837. return $this->namespaceVersion;
  2838. }
  2839. protected function doFetchMultiple(array $keys)
  2840. {
  2841. $returnValues = array();
  2842. foreach ($keys as $key) {
  2843. if (false !== ($item $this->doFetch($key)) || $this->doContains($key)) {
  2844. $returnValues[$key] = $item;
  2845. }
  2846. }
  2847. return $returnValues;
  2848. }
  2849. abstract protected function doFetch($id);
  2850. abstract protected function doContains($id);
  2851. protected function doSaveMultiple(array $keysAndValues$lifetime 0)
  2852. {
  2853. $success true;
  2854. foreach ($keysAndValues as $key => $value) {
  2855. if (!$this->doSave($key$value$lifetime)) {
  2856. $success false;
  2857. }
  2858. }
  2859. return $success;
  2860. }
  2861. abstract protected function doSave($id$data$lifeTime 0);
  2862. abstract protected function doDelete($id);
  2863. abstract protected function doFlush();
  2864. abstract protected function doGetStats();
  2865. }
  2866. }
  2867. namespace Symfony\Component\Cache
  2868. {
  2869. use Doctrine\Common\Cache\CacheProvider;
  2870. use Psr\Cache\CacheItemPoolInterface;
  2871. class DoctrineProvider extends CacheProvider
  2872. {
  2873. private $pool;
  2874. public function __construct(CacheItemPoolInterface $pool)
  2875. {
  2876. $this->pool $pool;
  2877. }
  2878. protected function doFetch($id)
  2879. {
  2880. $item $this->pool->getItem(rawurlencode($id));
  2881. return $item->isHit() ? $item->get() : false;
  2882. }
  2883. protected function doContains($id)
  2884. {
  2885. return $this->pool->hasItem(rawurlencode($id));
  2886. }
  2887. protected function doSave($id$data$lifeTime 0)
  2888. {
  2889. $item $this->pool->getItem(rawurlencode($id));
  2890. if ($lifeTime) {
  2891. $item->expiresAfter($lifeTime);
  2892. }
  2893. return $this->pool->save($item->set($data));
  2894. }
  2895. protected function doDelete($id)
  2896. {
  2897. return $this->pool->deleteItem(rawurlencode($id));
  2898. }
  2899. protected function doFlush()
  2900. {
  2901. $this->pool->clear();
  2902. }
  2903. protected function doGetStats()
  2904. {
  2905. }
  2906. }
  2907. }
  2908. namespace Symfony\Component\Config
  2909. {
  2910. use Symfony\Component\Config\Resource\ResourceInterface;
  2911. interface ConfigCacheInterface
  2912. {
  2913. public function getPath();
  2914. public function isFresh();
  2915. public function write($content, array $metadata null);
  2916. }
  2917. }
  2918. namespace Symfony\Component\Config
  2919. {
  2920. use Symfony\Component\Config\Resource\ResourceInterface;
  2921. use Symfony\Component\Filesystem\Exception\IOException;
  2922. use Symfony\Component\Filesystem\Filesystem;
  2923. class ResourceCheckerConfigCache implements ConfigCacheInterface
  2924. {
  2925. private $file;
  2926. private $resourceCheckers;
  2927. public function __construct($file$resourceCheckers = array())
  2928. {
  2929. $this->file $file;
  2930. $this->resourceCheckers $resourceCheckers;
  2931. }
  2932. public function getPath()
  2933. {
  2934. return $this->file;
  2935. }
  2936. public function isFresh()
  2937. {
  2938. if (!is_file($this->file)) {
  2939. return false;
  2940. }
  2941. if (!$this->resourceCheckers) {
  2942. return true; }
  2943. $metadata $this->getMetaFile();
  2944. if (!is_file($metadata)) {
  2945. return false;
  2946. }
  2947. $e null;
  2948. $meta false;
  2949. $time filemtime($this->file);
  2950. $signalingException = new \UnexpectedValueException();
  2951. $prevUnserializeHandler ini_set('unserialize_callback_func','');
  2952. $prevErrorHandler set_error_handler(function ($type$msg$file$line$context = array()) use (&$prevErrorHandler$signalingException) {
  2953. if (E_WARNING === $type &&'Class __PHP_Incomplete_Class has no unserializer'=== $msg) {
  2954. throw $signalingException;
  2955. }
  2956. return $prevErrorHandler $prevErrorHandler($type$msg$file$line$context) : false;
  2957. });
  2958. try {
  2959. $meta unserialize(file_get_contents($metadata));
  2960. } catch (\Error $e) {
  2961. } catch (\Exception $e) {
  2962. }
  2963. restore_error_handler();
  2964. ini_set('unserialize_callback_func'$prevUnserializeHandler);
  2965. if (null !== $e && $e !== $signalingException) {
  2966. throw $e;
  2967. }
  2968. if (false === $meta) {
  2969. return false;
  2970. }
  2971. foreach ($meta as $resource) {
  2972. foreach ($this->resourceCheckers as $checker) {
  2973. if (!$checker->supports($resource)) {
  2974. continue; }
  2975. if ($checker->isFresh($resource$time)) {
  2976. break; }
  2977. return false; }
  2978. }
  2979. return true;
  2980. }
  2981. public function write($content, array $metadata null)
  2982. {
  2983. $mode 0666;
  2984. $umask umask();
  2985. $filesystem = new Filesystem();
  2986. $filesystem->dumpFile($this->file$content);
  2987. try {
  2988. $filesystem->chmod($this->file$mode$umask);
  2989. } catch (IOException $e) {
  2990. }
  2991. if (null !== $metadata) {
  2992. $filesystem->dumpFile($this->getMetaFile(), serialize($metadata));
  2993. try {
  2994. $filesystem->chmod($this->getMetaFile(), $mode$umask);
  2995. } catch (IOException $e) {
  2996. }
  2997. }
  2998. if (\function_exists('opcache_invalidate') && ini_get('opcache.enable')) {
  2999. @opcache_invalidate($this->filetrue);
  3000. }
  3001. }
  3002. private function getMetaFile()
  3003. {
  3004. return $this->file.'.meta';
  3005. }
  3006. }
  3007. }
  3008. namespace Symfony\Component\Config
  3009. {
  3010. use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
  3011. class ConfigCache extends ResourceCheckerConfigCache
  3012. {
  3013. private $debug;
  3014. public function __construct($file$debug)
  3015. {
  3016. $this->debug = (bool) $debug;
  3017. $checkers = array();
  3018. if (true === $this->debug) {
  3019. $checkers = array(new SelfCheckingResourceChecker());
  3020. }
  3021. parent::__construct($file$checkers);
  3022. }
  3023. public function isFresh()
  3024. {
  3025. if (!$this->debug && is_file($this->getPath())) {
  3026. return true;
  3027. }
  3028. return parent::isFresh();
  3029. }
  3030. }
  3031. }
  3032. namespace Symfony\Component\Config
  3033. {
  3034. use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
  3035. class FileLocator implements FileLocatorInterface
  3036. {
  3037. protected $paths;
  3038. public function __construct($paths = array())
  3039. {
  3040. $this->paths = (array) $paths;
  3041. }
  3042. public function locate($name$currentPath null$first true)
  3043. {
  3044. if (''== $name) {
  3045. throw new \InvalidArgumentException('An empty file name is not valid to be located.');
  3046. }
  3047. if ($this->isAbsolutePath($name)) {
  3048. if (!file_exists($name)) {
  3049. throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.'$name), 0null, array($name));
  3050. }
  3051. return $name;
  3052. }
  3053. $paths $this->paths;
  3054. if (null !== $currentPath) {
  3055. array_unshift($paths$currentPath);
  3056. }
  3057. $paths array_unique($paths);
  3058. $filepaths $notfound = array();
  3059. foreach ($paths as $path) {
  3060. if (@file_exists($file $path.DIRECTORY_SEPARATOR.$name)) {
  3061. if (true === $first) {
  3062. return $file;
  3063. }
  3064. $filepaths[] = $file;
  3065. } else {
  3066. $notfound[] = $file;
  3067. }
  3068. }
  3069. if (!$filepaths) {
  3070. throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist (in: %s).'$nameimplode(', '$paths)), 0null$notfound);
  3071. }
  3072. return $filepaths;
  3073. }
  3074. private function isAbsolutePath($file)
  3075. {
  3076. if ('/'=== $file[0] ||'\\'=== $file[0]
  3077. || (strlen($file) > && ctype_alpha($file[0])
  3078. &&':'=== $file[1]
  3079. && ('\\'=== $file[2] ||'/'=== $file[2])
  3080. )
  3081. || null !== parse_url($filePHP_URL_SCHEME)
  3082. ) {
  3083. return true;
  3084. }
  3085. return false;
  3086. }
  3087. }
  3088. }
  3089. namespace Symfony\Component\DependencyInjection
  3090. {
  3091. interface ContainerAwareInterface
  3092. {
  3093. public function setContainer(ContainerInterface $container null);
  3094. }
  3095. }
  3096. namespace Psr\Container
  3097. {
  3098. interface ContainerInterface
  3099. {
  3100. public function get($id);
  3101. public function has($id);
  3102. }
  3103. }
  3104. namespace Symfony\Component\DependencyInjection
  3105. {
  3106. use Psr\Container\ContainerInterface as PsrContainerInterface;
  3107. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  3108. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  3109. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  3110. interface ContainerInterface extends PsrContainerInterface
  3111. {
  3112. const EXCEPTION_ON_INVALID_REFERENCE 1;
  3113. const NULL_ON_INVALID_REFERENCE 2;
  3114. const IGNORE_ON_INVALID_REFERENCE 3;
  3115. public function set($id$service);
  3116. public function get($id$invalidBehavior self::EXCEPTION_ON_INVALID_REFERENCE);
  3117. public function has($id);
  3118. public function initialized($id);
  3119. public function getParameter($name);
  3120. public function hasParameter($name);
  3121. public function setParameter($name$value);
  3122. }
  3123. }
  3124. namespace Symfony\Component\DependencyInjection
  3125. {
  3126. interface ResettableContainerInterface extends ContainerInterface
  3127. {
  3128. public function reset();
  3129. }
  3130. }
  3131. namespace Symfony\Component\DependencyInjection
  3132. {
  3133. use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
  3134. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  3135. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  3136. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  3137. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  3138. use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
  3139. use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
  3140. class Container implements ResettableContainerInterface
  3141. {
  3142. protected $parameterBag;
  3143. protected $services = array();
  3144. protected $methodMap = array();
  3145. protected $aliases = array();
  3146. protected $loading = array();
  3147. protected $privates = array();
  3148. protected $normalizedIds = array();
  3149. private $underscoreMap = array('_'=>'','.'=>'_','\\'=>'_');
  3150. private $envCache = array();
  3151. private $compiled false;
  3152. public function __construct(ParameterBagInterface $parameterBag null)
  3153. {
  3154. $this->parameterBag $parameterBag ?: new EnvPlaceholderParameterBag();
  3155. }
  3156. public function compile()
  3157. {
  3158. $this->parameterBag->resolve();
  3159. $this->parameterBag = new FrozenParameterBag($this->parameterBag->all());
  3160. $this->compiled true;
  3161. }
  3162. public function isCompiled()
  3163. {
  3164. return $this->compiled;
  3165. }
  3166. public function isFrozen()
  3167. {
  3168. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.'__METHOD__), E_USER_DEPRECATED);
  3169. return $this->parameterBag instanceof FrozenParameterBag;
  3170. }
  3171. public function getParameterBag()
  3172. {
  3173. return $this->parameterBag;
  3174. }
  3175. public function getParameter($name)
  3176. {
  3177. return $this->parameterBag->get($name);
  3178. }
  3179. public function hasParameter($name)
  3180. {
  3181. return $this->parameterBag->has($name);
  3182. }
  3183. public function setParameter($name$value)
  3184. {
  3185. $this->parameterBag->set($name$value);
  3186. }
  3187. public function set($id$service)
  3188. {
  3189. $id $this->normalizeId($id);
  3190. if ('service_container'=== $id) {
  3191. throw new InvalidArgumentException('You cannot set service "service_container".');
  3192. }
  3193. if (isset($this->aliases[$id])) {
  3194. unset($this->aliases[$id]);
  3195. }
  3196. $wasSet = isset($this->services[$id]);
  3197. $this->services[$id] = $service;
  3198. if (null === $service) {
  3199. unset($this->services[$id]);
  3200. }
  3201. if (isset($this->privates[$id])) {
  3202. if (null === $service) {
  3203. @trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.'$id), E_USER_DEPRECATED);
  3204. unset($this->privates[$id]);
  3205. } else {
  3206. @trigger_error(sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.'$id), E_USER_DEPRECATED);
  3207. }
  3208. } elseif ($wasSet && isset($this->methodMap[$id])) {
  3209. if (null === $service) {
  3210. @trigger_error(sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.'$id), E_USER_DEPRECATED);
  3211. } else {
  3212. @trigger_error(sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.'$id), E_USER_DEPRECATED);
  3213. }
  3214. }
  3215. }
  3216. public function has($id)
  3217. {
  3218. for ($i 2;;) {
  3219. if (isset($this->privates[$id])) {
  3220. @trigger_error(sprintf('The "%s" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.'$id), E_USER_DEPRECATED);
  3221. }
  3222. if (isset($this->aliases[$id])) {
  3223. $id $this->aliases[$id];
  3224. }
  3225. if (isset($this->services[$id])) {
  3226. return true;
  3227. }
  3228. if ('service_container'=== $id) {
  3229. return true;
  3230. }
  3231. if (isset($this->methodMap[$id])) {
  3232. return true;
  3233. }
  3234. if (--$i && $id !== $normalizedId $this->normalizeId($id)) {
  3235. $id $normalizedId;
  3236. continue;
  3237. }
  3238. if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this,'get'.strtr($id$this->underscoreMap).'Service')) {
  3239. @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'E_USER_DEPRECATED);
  3240. return true;
  3241. }
  3242. return false;
  3243. }
  3244. }
  3245. public function get($id$invalidBehavior self::EXCEPTION_ON_INVALID_REFERENCE)
  3246. {
  3247. for ($i 2;;) {
  3248. if (isset($this->privates[$id])) {
  3249. @trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.'$id), E_USER_DEPRECATED);
  3250. }
  3251. if (isset($this->aliases[$id])) {
  3252. $id $this->aliases[$id];
  3253. }
  3254. if (isset($this->services[$id])) {
  3255. return $this->services[$id];
  3256. }
  3257. if ('service_container'=== $id) {
  3258. return $this;
  3259. }
  3260. if (isset($this->loading[$id])) {
  3261. throw new ServiceCircularReferenceException($idarray_keys($this->loading));
  3262. }
  3263. if (isset($this->methodMap[$id])) {
  3264. $method $this->methodMap[$id];
  3265. } elseif (--$i && $id !== $normalizedId $this->normalizeId($id)) {
  3266. $id $normalizedId;
  3267. continue;
  3268. } elseif (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class && method_exists($this$method ='get'.strtr($id$this->underscoreMap).'Service')) {
  3269. @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'E_USER_DEPRECATED);
  3270. } else {
  3271. if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
  3272. if (!$id) {
  3273. throw new ServiceNotFoundException($id);
  3274. }
  3275. $alternatives = array();
  3276. foreach ($this->getServiceIds() as $knownId) {
  3277. $lev levenshtein($id$knownId);
  3278. if ($lev <= strlen($id) / || false !== strpos($knownId$id)) {
  3279. $alternatives[] = $knownId;
  3280. }
  3281. }
  3282. throw new ServiceNotFoundException($idnullnull$alternatives);
  3283. }
  3284. return;
  3285. }
  3286. $this->loading[$id] = true;
  3287. try {
  3288. $service $this->$method();
  3289. } catch (\Exception $e) {
  3290. unset($this->services[$id]);
  3291. throw $e;
  3292. } finally {
  3293. unset($this->loading[$id]);
  3294. }
  3295. return $service;
  3296. }
  3297. }
  3298. public function initialized($id)
  3299. {
  3300. $id $this->normalizeId($id);
  3301. if (isset($this->aliases[$id])) {
  3302. $id $this->aliases[$id];
  3303. }
  3304. if ('service_container'=== $id) {
  3305. return false;
  3306. }
  3307. return isset($this->services[$id]);
  3308. }
  3309. public function reset()
  3310. {
  3311. $this->services = array();
  3312. }
  3313. public function getServiceIds()
  3314. {
  3315. $ids = array();
  3316. if (!$this->methodMap && !$this instanceof ContainerBuilder && __CLASS__ !== static::class) {
  3317. @trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.'E_USER_DEPRECATED);
  3318. foreach (get_class_methods($this) as $method) {
  3319. if (preg_match('/^get(.+)Service$/'$method$match)) {
  3320. $ids[] = self::underscore($match[1]);
  3321. }
  3322. }
  3323. }
  3324. $ids[] ='service_container';
  3325. return array_unique(array_merge($idsarray_keys($this->methodMap), array_keys($this->services)));
  3326. }
  3327. public static function camelize($id)
  3328. {
  3329. return strtr(ucwords(strtr($id, array('_'=>' ','.'=>'_ ','\\'=>'_ '))), array(' '=>''));
  3330. }
  3331. public static function underscore($id)
  3332. {
  3333. return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/','/([a-z\d])([A-Z])/'), array('\\1_\\2','\\1_\\2'), str_replace('_','.'$id)));
  3334. }
  3335. protected function getEnv($name)
  3336. {
  3337. if (isset($this->envCache[$name]) || array_key_exists($name$this->envCache)) {
  3338. return $this->envCache[$name];
  3339. }
  3340. if (isset($_ENV[$name])) {
  3341. return $this->envCache[$name] = $_ENV[$name];
  3342. }
  3343. if (isset($_SERVER[$name]) && !== strpos($name,'HTTP_')) {
  3344. return $this->envCache[$name] = $_SERVER[$name];
  3345. }
  3346. if (false !== ($env getenv($name)) && null !== $env) { return $this->envCache[$name] = $env;
  3347. }
  3348. if (!$this->hasParameter("env($name)")) {
  3349. throw new EnvNotFoundException($name);
  3350. }
  3351. return $this->envCache[$name] = $this->getParameter("env($name)");
  3352. }
  3353. public function normalizeId($id)
  3354. {
  3355. if (!is_string($id)) {
  3356. $id = (string) $id;
  3357. }
  3358. if (isset($this->normalizedIds[$normalizedId strtolower($id)])) {
  3359. $normalizedId $this->normalizedIds[$normalizedId];
  3360. if ($id !== $normalizedId) {
  3361. @trigger_error(sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.3.'$id$normalizedId), E_USER_DEPRECATED);
  3362. }
  3363. } else {
  3364. $normalizedId $this->normalizedIds[$normalizedId] = $id;
  3365. }
  3366. return $normalizedId;
  3367. }
  3368. private function __clone()
  3369. {
  3370. }
  3371. }
  3372. }
  3373. namespace Symfony\Component\EventDispatcher
  3374. {
  3375. class Event
  3376. {
  3377. private $propagationStopped false;
  3378. public function isPropagationStopped()
  3379. {
  3380. return $this->propagationStopped;
  3381. }
  3382. public function stopPropagation()
  3383. {
  3384. $this->propagationStopped true;
  3385. }
  3386. }
  3387. }
  3388. namespace Symfony\Component\EventDispatcher
  3389. {
  3390. interface EventDispatcherInterface
  3391. {
  3392. public function dispatch($eventNameEvent $event null);
  3393. public function addListener($eventName$listener$priority 0);
  3394. public function addSubscriber(EventSubscriberInterface $subscriber);
  3395. public function removeListener($eventName$listener);
  3396. public function removeSubscriber(EventSubscriberInterface $subscriber);
  3397. public function getListeners($eventName null);
  3398. public function getListenerPriority($eventName$listener);
  3399. public function hasListeners($eventName null);
  3400. }
  3401. }
  3402. namespace Symfony\Component\EventDispatcher
  3403. {
  3404. class EventDispatcher implements EventDispatcherInterface
  3405. {
  3406. private $listeners = array();
  3407. private $sorted = array();
  3408. public function dispatch($eventNameEvent $event null)
  3409. {
  3410. if (null === $event) {
  3411. $event = new Event();
  3412. }
  3413. if ($listeners $this->getListeners($eventName)) {
  3414. $this->doDispatch($listeners$eventName$event);
  3415. }
  3416. return $event;
  3417. }
  3418. public function getListeners($eventName null)
  3419. {
  3420. if (null !== $eventName) {
  3421. if (empty($this->listeners[$eventName])) {
  3422. return array();
  3423. }
  3424. if (!isset($this->sorted[$eventName])) {
  3425. $this->sortListeners($eventName);
  3426. }
  3427. return $this->sorted[$eventName];
  3428. }
  3429. foreach ($this->listeners as $eventName => $eventListeners) {
  3430. if (!isset($this->sorted[$eventName])) {
  3431. $this->sortListeners($eventName);
  3432. }
  3433. }
  3434. return array_filter($this->sorted);
  3435. }
  3436. public function getListenerPriority($eventName$listener)
  3437. {
  3438. if (empty($this->listeners[$eventName])) {
  3439. return;
  3440. }
  3441. if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  3442. $listener[0] = $listener[0]();
  3443. }
  3444. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  3445. foreach ($listeners as $k => $v) {
  3446. if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
  3447. $v[0] = $v[0]();
  3448. $this->listeners[$eventName][$priority][$k] = $v;
  3449. }
  3450. if ($v === $listener) {
  3451. return $priority;
  3452. }
  3453. }
  3454. }
  3455. }
  3456. public function hasListeners($eventName null)
  3457. {
  3458. if (null !== $eventName) {
  3459. return !empty($this->listeners[$eventName]);
  3460. }
  3461. foreach ($this->listeners as $eventListeners) {
  3462. if ($eventListeners) {
  3463. return true;
  3464. }
  3465. }
  3466. return false;
  3467. }
  3468. public function addListener($eventName$listener$priority 0)
  3469. {
  3470. $this->listeners[$eventName][$priority][] = $listener;
  3471. unset($this->sorted[$eventName]);
  3472. }
  3473. public function removeListener($eventName$listener)
  3474. {
  3475. if (empty($this->listeners[$eventName])) {
  3476. return;
  3477. }
  3478. if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  3479. $listener[0] = $listener[0]();
  3480. }
  3481. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  3482. foreach ($listeners as $k => $v) {
  3483. if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
  3484. $v[0] = $v[0]();
  3485. }
  3486. if ($v === $listener) {
  3487. unset($listeners[$k], $this->sorted[$eventName]);
  3488. } else {
  3489. $listeners[$k] = $v;
  3490. }
  3491. }
  3492. if ($listeners) {
  3493. $this->listeners[$eventName][$priority] = $listeners;
  3494. } else {
  3495. unset($this->listeners[$eventName][$priority]);
  3496. }
  3497. }
  3498. }
  3499. public function addSubscriber(EventSubscriberInterface $subscriber)
  3500. {
  3501. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  3502. if (is_string($params)) {
  3503. $this->addListener($eventName, array($subscriber$params));
  3504. } elseif (is_string($params[0])) {
  3505. $this->addListener($eventName, array($subscriber$params[0]), isset($params[1]) ? $params[1] : 0);
  3506. } else {
  3507. foreach ($params as $listener) {
  3508. $this->addListener($eventName, array($subscriber$listener[0]), isset($listener[1]) ? $listener[1] : 0);
  3509. }
  3510. }
  3511. }
  3512. }
  3513. public function removeSubscriber(EventSubscriberInterface $subscriber)
  3514. {
  3515. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  3516. if (is_array($params) && is_array($params[0])) {
  3517. foreach ($params as $listener) {
  3518. $this->removeListener($eventName, array($subscriber$listener[0]));
  3519. }
  3520. } else {
  3521. $this->removeListener($eventName, array($subscriberis_string($params) ? $params $params[0]));
  3522. }
  3523. }
  3524. }
  3525. protected function doDispatch($listeners$eventNameEvent $event)
  3526. {
  3527. foreach ($listeners as $listener) {
  3528. if ($event->isPropagationStopped()) {
  3529. break;
  3530. }
  3531. call_user_func($listener$event$eventName$this);
  3532. }
  3533. }
  3534. private function sortListeners($eventName)
  3535. {
  3536. krsort($this->listeners[$eventName]);
  3537. $this->sorted[$eventName] = array();
  3538. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  3539. foreach ($listeners as $k => $listener) {
  3540. if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  3541. $listener[0] = $listener[0]();
  3542. $this->listeners[$eventName][$priority][$k] = $listener;
  3543. }
  3544. $this->sorted[$eventName][] = $listener;
  3545. }
  3546. }
  3547. }
  3548. }
  3549. }
  3550. namespace Symfony\Component\EventDispatcher
  3551. {
  3552. use Symfony\Component\DependencyInjection\ContainerInterface;
  3553. class ContainerAwareEventDispatcher extends EventDispatcher
  3554. {
  3555. private $container;
  3556. private $listenerIds = array();
  3557. private $listeners = array();
  3558. public function __construct(ContainerInterface $container)
  3559. {
  3560. $this->container $container;
  3561. $class get_class($this);
  3562. if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) {
  3563. $class get_parent_class($class);
  3564. }
  3565. if (__CLASS__ !== $class) {
  3566. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.'__CLASS__), E_USER_DEPRECATED);
  3567. }
  3568. }
  3569. public function addListenerService($eventName$callback$priority 0)
  3570. {
  3571. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.'__CLASS__), E_USER_DEPRECATED);
  3572. if (!is_array($callback) || !== count($callback)) {
  3573. throw new \InvalidArgumentException('Expected an array("service", "method") argument');
  3574. }
  3575. $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
  3576. }
  3577. public function removeListener($eventName$listener)
  3578. {
  3579. $this->lazyLoad($eventName);
  3580. if (isset($this->listenerIds[$eventName])) {
  3581. foreach ($this->listenerIds[$eventName] as $i => list($serviceId$method)) {
  3582. $key $serviceId.'.'.$method;
  3583. if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
  3584. unset($this->listeners[$eventName][$key]);
  3585. if (empty($this->listeners[$eventName])) {
  3586. unset($this->listeners[$eventName]);
  3587. }
  3588. unset($this->listenerIds[$eventName][$i]);
  3589. if (empty($this->listenerIds[$eventName])) {
  3590. unset($this->listenerIds[$eventName]);
  3591. }
  3592. }
  3593. }
  3594. }
  3595. parent::removeListener($eventName$listener);
  3596. }
  3597. public function hasListeners($eventName null)
  3598. {
  3599. if (null === $eventName) {
  3600. return $this->listenerIds || $this->listeners || parent::hasListeners();
  3601. }
  3602. if (isset($this->listenerIds[$eventName])) {
  3603. return true;
  3604. }
  3605. return parent::hasListeners($eventName);
  3606. }
  3607. public function getListeners($eventName null)
  3608. {
  3609. if (null === $eventName) {
  3610. foreach ($this->listenerIds as $serviceEventName => $args) {
  3611. $this->lazyLoad($serviceEventName);
  3612. }
  3613. } else {
  3614. $this->lazyLoad($eventName);
  3615. }
  3616. return parent::getListeners($eventName);
  3617. }
  3618. public function getListenerPriority($eventName$listener)
  3619. {
  3620. $this->lazyLoad($eventName);
  3621. return parent::getListenerPriority($eventName$listener);
  3622. }
  3623. public function addSubscriberService($serviceId$class)
  3624. {
  3625. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.'__CLASS__), E_USER_DEPRECATED);
  3626. foreach ($class::getSubscribedEvents() as $eventName => $params) {
  3627. if (is_string($params)) {
  3628. $this->listenerIds[$eventName][] = array($serviceId$params0);
  3629. } elseif (is_string($params[0])) {
  3630. $this->listenerIds[$eventName][] = array($serviceId$params[0], isset($params[1]) ? $params[1] : 0);
  3631. } else {
  3632. foreach ($params as $listener) {
  3633. $this->listenerIds[$eventName][] = array($serviceId$listener[0], isset($listener[1]) ? $listener[1] : 0);
  3634. }
  3635. }
  3636. }
  3637. }
  3638. public function getContainer()
  3639. {
  3640. @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 as its class will be removed in 4.0. Inject the container or the services you need in your listeners/subscribers instead.'E_USER_DEPRECATED);
  3641. return $this->container;
  3642. }
  3643. protected function lazyLoad($eventName)
  3644. {
  3645. if (isset($this->listenerIds[$eventName])) {
  3646. foreach ($this->listenerIds[$eventName] as list($serviceId$method$priority)) {
  3647. $listener $this->container->get($serviceId);
  3648. $key $serviceId.'.'.$method;
  3649. if (!isset($this->listeners[$eventName][$key])) {
  3650. $this->addListener($eventName, array($listener$method), $priority);
  3651. } elseif ($this->listeners[$eventName][$key] !== $listener) {
  3652. parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
  3653. $this->addListener($eventName, array($listener$method), $priority);
  3654. }
  3655. $this->listeners[$eventName][$key] = $listener;
  3656. }
  3657. }
  3658. }
  3659. }
  3660. }
  3661. namespace Symfony\Component\HttpKernel\EventListener
  3662. {
  3663. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  3664. use Symfony\Component\HttpKernel\KernelEvents;
  3665. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  3666. class ResponseListener implements EventSubscriberInterface
  3667. {
  3668. private $charset;
  3669. public function __construct($charset)
  3670. {
  3671. $this->charset $charset;
  3672. }
  3673. public function onKernelResponse(FilterResponseEvent $event)
  3674. {
  3675. if (!$event->isMasterRequest()) {
  3676. return;
  3677. }
  3678. $response $event->getResponse();
  3679. if (null === $response->getCharset()) {
  3680. $response->setCharset($this->charset);
  3681. }
  3682. $response->prepare($event->getRequest());
  3683. }
  3684. public static function getSubscribedEvents()
  3685. {
  3686. return array(
  3687. KernelEvents::RESPONSE =>'onKernelResponse',
  3688. );
  3689. }
  3690. }
  3691. }
  3692. namespace Symfony\Component\HttpKernel\EventListener
  3693. {
  3694. use Psr\Log\LoggerInterface;
  3695. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  3696. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  3697. use Symfony\Component\HttpKernel\KernelEvents;
  3698. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  3699. use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
  3700. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  3701. use Symfony\Component\HttpFoundation\RequestStack;
  3702. use Symfony\Component\Routing\Exception\MethodNotAllowedException;
  3703. use Symfony\Component\Routing\Exception\ResourceNotFoundException;
  3704. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  3705. use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
  3706. use Symfony\Component\Routing\RequestContext;
  3707. use Symfony\Component\Routing\RequestContextAwareInterface;
  3708. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  3709. use Symfony\Component\HttpFoundation\Request;
  3710. class RouterListener implements EventSubscriberInterface
  3711. {
  3712. private $matcher;
  3713. private $context;
  3714. private $logger;
  3715. private $requestStack;
  3716. public function __construct($matcherRequestStack $requestStackRequestContext $context nullLoggerInterface $logger null)
  3717. {
  3718. if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
  3719. throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
  3720. }
  3721. if (null === $context && !$matcher instanceof RequestContextAwareInterface) {
  3722. throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
  3723. }
  3724. $this->matcher $matcher;
  3725. $this->context $context ?: $matcher->getContext();
  3726. $this->requestStack $requestStack;
  3727. $this->logger $logger;
  3728. }
  3729. private function setCurrentRequest(Request $request null)
  3730. {
  3731. if (null !== $request) {
  3732. try {
  3733. $this->context->fromRequest($request);
  3734. } catch (\UnexpectedValueException $e) {
  3735. throw new BadRequestHttpException($e->getMessage(), $e$e->getCode());
  3736. }
  3737. }
  3738. }
  3739. public function onKernelFinishRequest(FinishRequestEvent $event)
  3740. {
  3741. $this->setCurrentRequest($this->requestStack->getParentRequest());
  3742. }
  3743. public function onKernelRequest(GetResponseEvent $event)
  3744. {
  3745. $request $event->getRequest();
  3746. $this->setCurrentRequest($request);
  3747. if ($request->attributes->has('_controller')) {
  3748. return;
  3749. }
  3750. try {
  3751. if ($this->matcher instanceof RequestMatcherInterface) {
  3752. $parameters $this->matcher->matchRequest($request);
  3753. } else {
  3754. $parameters $this->matcher->match($request->getPathInfo());
  3755. }
  3756. if (null !== $this->logger) {
  3757. $this->logger->info('Matched route "{route}".', array('route'=> isset($parameters['_route']) ? $parameters['_route'] :'n/a','route_parameters'=> $parameters,'request_uri'=> $request->getUri(),'method'=> $request->getMethod(),
  3758. ));
  3759. }
  3760. $request->attributes->add($parameters);
  3761. unset($parameters['_route'], $parameters['_controller']);
  3762. $request->attributes->set('_route_params'$parameters);
  3763. } catch (ResourceNotFoundException $e) {
  3764. $message sprintf('No route found for "%s %s"'$request->getMethod(), $request->getPathInfo());
  3765. if ($referer $request->headers->get('referer')) {
  3766. $message .= sprintf(' (from "%s")'$referer);
  3767. }
  3768. throw new NotFoundHttpException($message$e);
  3769. } catch (MethodNotAllowedException $e) {
  3770. $message sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)'$request->getMethod(), $request->getPathInfo(), implode(', '$e->getAllowedMethods()));
  3771. throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message$e);
  3772. }
  3773. }
  3774. public static function getSubscribedEvents()
  3775. {
  3776. return array(
  3777. KernelEvents::REQUEST => array(array('onKernelRequest'32)),
  3778. KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest'0)),
  3779. );
  3780. }
  3781. }
  3782. }
  3783. namespace Symfony\Component\HttpKernel\Bundle
  3784. {
  3785. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  3786. use Symfony\Component\DependencyInjection\ContainerBuilder;
  3787. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  3788. interface BundleInterface extends ContainerAwareInterface
  3789. {
  3790. public function boot();
  3791. public function shutdown();
  3792. public function build(ContainerBuilder $container);
  3793. public function getContainerExtension();
  3794. public function getParent();
  3795. public function getName();
  3796. public function getNamespace();
  3797. public function getPath();
  3798. }
  3799. }
  3800. namespace Symfony\Component\DependencyInjection
  3801. {
  3802. trait ContainerAwareTrait
  3803. {
  3804. protected $container;
  3805. public function setContainer(ContainerInterface $container null)
  3806. {
  3807. $this->container $container;
  3808. }
  3809. }
  3810. }
  3811. namespace Symfony\Component\HttpKernel\Bundle
  3812. {
  3813. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  3814. use Symfony\Component\DependencyInjection\ContainerBuilder;
  3815. use Symfony\Component\DependencyInjection\Container;
  3816. use Symfony\Component\Console\Application;
  3817. use Symfony\Component\Finder\Finder;
  3818. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  3819. abstract class Bundle implements BundleInterface
  3820. {
  3821. use ContainerAwareTrait;
  3822. protected $name;
  3823. protected $extension;
  3824. protected $path;
  3825. private $namespace;
  3826. public function boot()
  3827. {
  3828. }
  3829. public function shutdown()
  3830. {
  3831. }
  3832. public function build(ContainerBuilder $container)
  3833. {
  3834. }
  3835. public function getContainerExtension()
  3836. {
  3837. if (null === $this->extension) {
  3838. $extension $this->createContainerExtension();
  3839. if (null !== $extension) {
  3840. if (!$extension instanceof ExtensionInterface) {
  3841. throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.'get_class($extension)));
  3842. }
  3843. $basename preg_replace('/Bundle$/',''$this->getName());
  3844. $expectedAlias Container::underscore($basename);
  3845. if ($expectedAlias != $extension->getAlias()) {
  3846. throw new \LogicException(sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
  3847. $expectedAlias$extension->getAlias()
  3848. ));
  3849. }
  3850. $this->extension $extension;
  3851. } else {
  3852. $this->extension false;
  3853. }
  3854. }
  3855. if ($this->extension) {
  3856. return $this->extension;
  3857. }
  3858. }
  3859. public function getNamespace()
  3860. {
  3861. if (null === $this->namespace) {
  3862. $this->parseClassName();
  3863. }
  3864. return $this->namespace;
  3865. }
  3866. public function getPath()
  3867. {
  3868. if (null === $this->path) {
  3869. $reflected = new \ReflectionObject($this);
  3870. $this->path dirname($reflected->getFileName());
  3871. }
  3872. return $this->path;
  3873. }
  3874. public function getParent()
  3875. {
  3876. }
  3877. final public function getName()
  3878. {
  3879. if (null === $this->name) {
  3880. $this->parseClassName();
  3881. }
  3882. return $this->name;
  3883. }
  3884. public function registerCommands(Application $application)
  3885. {
  3886. if (!is_dir($dir $this->getPath().'/Command')) {
  3887. return;
  3888. }
  3889. if (!class_exists('Symfony\Component\Finder\Finder')) {
  3890. throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
  3891. }
  3892. $finder = new Finder();
  3893. $finder->files()->name('*Command.php')->in($dir);
  3894. $prefix $this->getNamespace().'\\Command';
  3895. foreach ($finder as $file) {
  3896. $ns $prefix;
  3897. if ($relativePath $file->getRelativePath()) {
  3898. $ns .='\\'.str_replace('/','\\'$relativePath);
  3899. }
  3900. $class $ns.'\\'.$file->getBasename('.php');
  3901. if ($this->container) {
  3902. $commandIds $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array();
  3903. $alias ='console.command.'.strtolower(str_replace('\\','_'$class));
  3904. if (isset($commandIds[$alias]) || $this->container->has($alias)) {
  3905. continue;
  3906. }
  3907. }
  3908. $r = new \ReflectionClass($class);
  3909. if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
  3910. $application->add($r->newInstance());
  3911. }
  3912. }
  3913. }
  3914. protected function getContainerExtensionClass()
  3915. {
  3916. $basename preg_replace('/Bundle$/',''$this->getName());
  3917. return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
  3918. }
  3919. protected function createContainerExtension()
  3920. {
  3921. if (class_exists($class $this->getContainerExtensionClass())) {
  3922. return new $class();
  3923. }
  3924. }
  3925. private function parseClassName()
  3926. {
  3927. $pos strrpos(static::class,'\\');
  3928. $this->namespace false === $pos ?''substr(static::class, 0$pos);
  3929. if (null === $this->name) {
  3930. $this->name false === $pos ? static::class : substr(static::class, $pos 1);
  3931. }
  3932. }
  3933. }
  3934. }
  3935. namespace Symfony\Component\HttpKernel\Controller
  3936. {
  3937. use Symfony\Component\HttpFoundation\Request;
  3938. interface ArgumentResolverInterface
  3939. {
  3940. public function getArguments(Request $request$controller);
  3941. }
  3942. }
  3943. namespace Symfony\Component\HttpKernel\Controller
  3944. {
  3945. use Symfony\Component\HttpFoundation\Request;
  3946. interface ControllerResolverInterface
  3947. {
  3948. public function getController(Request $request);
  3949. public function getArguments(Request $request$controller);
  3950. }
  3951. }
  3952. namespace Symfony\Component\HttpKernel\Controller
  3953. {
  3954. use Psr\Log\LoggerInterface;
  3955. use Symfony\Component\HttpFoundation\Request;
  3956. class ControllerResolver implements ArgumentResolverInterfaceControllerResolverInterface
  3957. {
  3958. private $logger;
  3959. private $supportsVariadic;
  3960. private $supportsScalarTypes;
  3961. public function __construct(LoggerInterface $logger null)
  3962. {
  3963. $this->logger $logger;
  3964. $this->supportsVariadic method_exists('ReflectionParameter','isVariadic');
  3965. $this->supportsScalarTypes method_exists('ReflectionParameter','getType');
  3966. }
  3967. public function getController(Request $request)
  3968. {
  3969. if (!$controller $request->attributes->get('_controller')) {
  3970. if (null !== $this->logger) {
  3971. $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
  3972. }
  3973. return false;
  3974. }
  3975. if (is_array($controller)) {
  3976. return $controller;
  3977. }
  3978. if (is_object($controller)) {
  3979. if (method_exists($controller,'__invoke')) {
  3980. return $controller;
  3981. }
  3982. throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.'get_class($controller), $request->getPathInfo()));
  3983. }
  3984. if (false === strpos($controller,':')) {
  3985. if (method_exists($controller,'__invoke')) {
  3986. return $this->instantiateController($controller);
  3987. } elseif (function_exists($controller)) {
  3988. return $controller;
  3989. }
  3990. }
  3991. $callable $this->createController($controller);
  3992. if (!is_callable($callable)) {
  3993. throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s'$request->getPathInfo(), $this->getControllerError($callable)));
  3994. }
  3995. return $callable;
  3996. }
  3997. public function getArguments(Request $request$controller)
  3998. {
  3999. @trigger_error(sprintf('%s is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.'__METHOD__ArgumentResolverInterface::class), E_USER_DEPRECATED);
  4000. if (is_array($controller)) {
  4001. $r = new \ReflectionMethod($controller[0], $controller[1]);
  4002. } elseif (is_object($controller) && !$controller instanceof \Closure) {
  4003. $r = new \ReflectionObject($controller);
  4004. $r $r->getMethod('__invoke');
  4005. } else {
  4006. $r = new \ReflectionFunction($controller);
  4007. }
  4008. return $this->doGetArguments($request$controller$r->getParameters());
  4009. }
  4010. protected function doGetArguments(Request $request$controller, array $parameters)
  4011. {
  4012. @trigger_error(sprintf('%s is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.'__METHOD__ArgumentResolverInterface::class), E_USER_DEPRECATED);
  4013. $attributes $request->attributes->all();
  4014. $arguments = array();
  4015. foreach ($parameters as $param) {
  4016. if (array_key_exists($param->name$attributes)) {
  4017. if ($this->supportsVariadic && $param->isVariadic() && is_array($attributes[$param->name])) {
  4018. $arguments array_merge($argumentsarray_values($attributes[$param->name]));
  4019. } else {
  4020. $arguments[] = $attributes[$param->name];
  4021. }
  4022. } elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
  4023. $arguments[] = $request;
  4024. } elseif ($param->isDefaultValueAvailable()) {
  4025. $arguments[] = $param->getDefaultValue();
  4026. } elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
  4027. $arguments[] = null;
  4028. } else {
  4029. if (is_array($controller)) {
  4030. $repr sprintf('%s::%s()'get_class($controller[0]), $controller[1]);
  4031. } elseif (is_object($controller)) {
  4032. $repr get_class($controller);
  4033. } else {
  4034. $repr $controller;
  4035. }
  4036. throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).'$repr$param->name));
  4037. }
  4038. }
  4039. return $arguments;
  4040. }
  4041. protected function createController($controller)
  4042. {
  4043. if (false === strpos($controller,'::')) {
  4044. throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".'$controller));
  4045. }
  4046. list($class$method) = explode('::'$controller2);
  4047. if (!class_exists($class)) {
  4048. throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.'$class));
  4049. }
  4050. return array($this->instantiateController($class), $method);
  4051. }
  4052. protected function instantiateController($class)
  4053. {
  4054. return new $class();
  4055. }
  4056. private function getControllerError($callable)
  4057. {
  4058. if (is_string($callable)) {
  4059. if (false !== strpos($callable,'::')) {
  4060. $callable explode('::'$callable);
  4061. }
  4062. if (class_exists($callable) && !method_exists($callable,'__invoke')) {
  4063. return sprintf('Class "%s" does not have a method "__invoke".'$callable);
  4064. }
  4065. if (!function_exists($callable)) {
  4066. return sprintf('Function "%s" does not exist.'$callable);
  4067. }
  4068. }
  4069. if (!is_array($callable)) {
  4070. return sprintf('Invalid type for controller given, expected string or array, got "%s".'gettype($callable));
  4071. }
  4072. if (!== count($callable)) {
  4073. return'Invalid format for controller, expected array(controller, method) or controller::method.';
  4074. }
  4075. list($controller$method) = $callable;
  4076. if (is_string($controller) && !class_exists($controller)) {
  4077. return sprintf('Class "%s" does not exist.'$controller);
  4078. }
  4079. $className is_object($controller) ? get_class($controller) : $controller;
  4080. if (method_exists($controller$method)) {
  4081. return sprintf('Method "%s" on class "%s" should be public and non-abstract.'$method$className);
  4082. }
  4083. $collection get_class_methods($controller);
  4084. $alternatives = array();
  4085. foreach ($collection as $item) {
  4086. $lev levenshtein($method$item);
  4087. if ($lev <= strlen($method) / || false !== strpos($item$method)) {
  4088. $alternatives[] = $item;
  4089. }
  4090. }
  4091. asort($alternatives);
  4092. $message sprintf('Expected method "%s" on class "%s"'$method$className);
  4093. if (count($alternatives) > 0) {
  4094. $message .= sprintf(', did you mean "%s"?'implode('", "'$alternatives));
  4095. } else {
  4096. $message .= sprintf('. Available methods: "%s".'implode('", "'$collection));
  4097. }
  4098. return $message;
  4099. }
  4100. }
  4101. }
  4102. namespace Symfony\Component\HttpKernel\Controller
  4103. {
  4104. use Symfony\Component\HttpFoundation\Request;
  4105. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver;
  4106. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver;
  4107. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver;
  4108. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\SessionValueResolver;
  4109. use Symfony\Component\HttpKernel\Controller\ArgumentResolver\VariadicValueResolver;
  4110. use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
  4111. use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactoryInterface;
  4112. final class ArgumentResolver implements ArgumentResolverInterface
  4113. {
  4114. private $argumentMetadataFactory;
  4115. private $argumentValueResolvers;
  4116. public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory null$argumentValueResolvers = array())
  4117. {
  4118. $this->argumentMetadataFactory $argumentMetadataFactory ?: new ArgumentMetadataFactory();
  4119. $this->argumentValueResolvers $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
  4120. }
  4121. public function getArguments(Request $request$controller)
  4122. {
  4123. $arguments = array();
  4124. foreach ($this->argumentMetadataFactory->createArgumentMetadata($controller) as $metadata) {
  4125. foreach ($this->argumentValueResolvers as $resolver) {
  4126. if (!$resolver->supports($request$metadata)) {
  4127. continue;
  4128. }
  4129. $resolved $resolver->resolve($request$metadata);
  4130. if (!$resolved instanceof \Generator) {
  4131. throw new \InvalidArgumentException(sprintf('%s::resolve() must yield at least one value.'get_class($resolver)));
  4132. }
  4133. foreach ($resolved as $append) {
  4134. $arguments[] = $append;
  4135. }
  4136. continue 2;
  4137. }
  4138. $representative $controller;
  4139. if (is_array($representative)) {
  4140. $representative sprintf('%s::%s()'get_class($representative[0]), $representative[1]);
  4141. } elseif (is_object($representative)) {
  4142. $representative get_class($representative);
  4143. }
  4144. throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.'$representative$metadata->getName()));
  4145. }
  4146. return $arguments;
  4147. }
  4148. public static function getDefaultArgumentValueResolvers()
  4149. {
  4150. return array(
  4151. new RequestAttributeValueResolver(),
  4152. new RequestValueResolver(),
  4153. new SessionValueResolver(),
  4154. new DefaultValueResolver(),
  4155. new VariadicValueResolver(),
  4156. );
  4157. }
  4158. }
  4159. }
  4160. namespace Symfony\Component\HttpKernel\ControllerMetadata
  4161. {
  4162. class ArgumentMetadata
  4163. {
  4164. private $name;
  4165. private $type;
  4166. private $isVariadic;
  4167. private $hasDefaultValue;
  4168. private $defaultValue;
  4169. private $isNullable;
  4170. public function __construct($name$type$isVariadic$hasDefaultValue$defaultValue$isNullable false)
  4171. {
  4172. $this->name $name;
  4173. $this->type $type;
  4174. $this->isVariadic $isVariadic;
  4175. $this->hasDefaultValue $hasDefaultValue;
  4176. $this->defaultValue $defaultValue;
  4177. $this->isNullable $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue);
  4178. }
  4179. public function getName()
  4180. {
  4181. return $this->name;
  4182. }
  4183. public function getType()
  4184. {
  4185. return $this->type;
  4186. }
  4187. public function isVariadic()
  4188. {
  4189. return $this->isVariadic;
  4190. }
  4191. public function hasDefaultValue()
  4192. {
  4193. return $this->hasDefaultValue;
  4194. }
  4195. public function isNullable()
  4196. {
  4197. return $this->isNullable;
  4198. }
  4199. public function getDefaultValue()
  4200. {
  4201. if (!$this->hasDefaultValue) {
  4202. throw new \LogicException(sprintf('Argument $%s does not have a default value. Use %s::hasDefaultValue() to avoid this exception.'$this->name__CLASS__));
  4203. }
  4204. return $this->defaultValue;
  4205. }
  4206. }
  4207. }
  4208. namespace Symfony\Component\HttpKernel\ControllerMetadata
  4209. {
  4210. interface ArgumentMetadataFactoryInterface
  4211. {
  4212. public function createArgumentMetadata($controller);
  4213. }
  4214. }
  4215. namespace Symfony\Component\HttpKernel\ControllerMetadata
  4216. {
  4217. final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
  4218. {
  4219. private $supportsVariadic;
  4220. private $supportsParameterType;
  4221. public function __construct()
  4222. {
  4223. $this->supportsVariadic method_exists('ReflectionParameter','isVariadic');
  4224. $this->supportsParameterType method_exists('ReflectionParameter','getType');
  4225. }
  4226. public function createArgumentMetadata($controller)
  4227. {
  4228. $arguments = array();
  4229. if (is_array($controller)) {
  4230. $reflection = new \ReflectionMethod($controller[0], $controller[1]);
  4231. } elseif (is_object($controller) && !$controller instanceof \Closure) {
  4232. $reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
  4233. } else {
  4234. $reflection = new \ReflectionFunction($controller);
  4235. }
  4236. foreach ($reflection->getParameters() as $param) {
  4237. $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
  4238. }
  4239. return $arguments;
  4240. }
  4241. private function isVariadic(\ReflectionParameter $parameter)
  4242. {
  4243. return $this->supportsVariadic && $parameter->isVariadic();
  4244. }
  4245. private function hasDefaultValue(\ReflectionParameter $parameter)
  4246. {
  4247. return $parameter->isDefaultValueAvailable();
  4248. }
  4249. private function getDefaultValue(\ReflectionParameter $parameter)
  4250. {
  4251. return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null;
  4252. }
  4253. private function getType(\ReflectionParameter $parameter)
  4254. {
  4255. if ($this->supportsParameterType) {
  4256. if (!$type $parameter->getType()) {
  4257. return;
  4258. }
  4259. $typeName $type instanceof \ReflectionNamedType $type->getName() : $type->__toString();
  4260. if ('array'=== $typeName && !$type->isBuiltin()) {
  4261. return;
  4262. }
  4263. return $typeName;
  4264. }
  4265. if (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/'$parameter$info)) {
  4266. return $info[1];
  4267. }
  4268. }
  4269. }
  4270. }
  4271. namespace Symfony\Component\HttpKernel\Event
  4272. {
  4273. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4274. use Symfony\Component\HttpFoundation\Request;
  4275. use Symfony\Component\EventDispatcher\Event;
  4276. class KernelEvent extends Event
  4277. {
  4278. private $kernel;
  4279. private $request;
  4280. private $requestType;
  4281. public function __construct(HttpKernelInterface $kernelRequest $request$requestType)
  4282. {
  4283. $this->kernel $kernel;
  4284. $this->request $request;
  4285. $this->requestType $requestType;
  4286. }
  4287. public function getKernel()
  4288. {
  4289. return $this->kernel;
  4290. }
  4291. public function getRequest()
  4292. {
  4293. return $this->request;
  4294. }
  4295. public function getRequestType()
  4296. {
  4297. return $this->requestType;
  4298. }
  4299. public function isMasterRequest()
  4300. {
  4301. return HttpKernelInterface::MASTER_REQUEST === $this->requestType;
  4302. }
  4303. }
  4304. }
  4305. namespace Symfony\Component\HttpKernel\Event
  4306. {
  4307. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4308. use Symfony\Component\HttpFoundation\Request;
  4309. class FilterControllerEvent extends KernelEvent
  4310. {
  4311. private $controller;
  4312. public function __construct(HttpKernelInterface $kernel, callable $controllerRequest $request$requestType)
  4313. {
  4314. parent::__construct($kernel$request$requestType);
  4315. $this->setController($controller);
  4316. }
  4317. public function getController()
  4318. {
  4319. return $this->controller;
  4320. }
  4321. public function setController(callable $controller)
  4322. {
  4323. $this->controller $controller;
  4324. }
  4325. }
  4326. }
  4327. namespace Symfony\Component\HttpKernel\Event
  4328. {
  4329. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4330. use Symfony\Component\HttpFoundation\Request;
  4331. use Symfony\Component\HttpFoundation\Response;
  4332. class FilterResponseEvent extends KernelEvent
  4333. {
  4334. private $response;
  4335. public function __construct(HttpKernelInterface $kernelRequest $request$requestTypeResponse $response)
  4336. {
  4337. parent::__construct($kernel$request$requestType);
  4338. $this->setResponse($response);
  4339. }
  4340. public function getResponse()
  4341. {
  4342. return $this->response;
  4343. }
  4344. public function setResponse(Response $response)
  4345. {
  4346. $this->response $response;
  4347. }
  4348. }
  4349. }
  4350. namespace Symfony\Component\HttpKernel\Event
  4351. {
  4352. use Symfony\Component\HttpFoundation\Response;
  4353. class GetResponseEvent extends KernelEvent
  4354. {
  4355. private $response;
  4356. public function getResponse()
  4357. {
  4358. return $this->response;
  4359. }
  4360. public function setResponse(Response $response)
  4361. {
  4362. $this->response $response;
  4363. $this->stopPropagation();
  4364. }
  4365. public function hasResponse()
  4366. {
  4367. return null !== $this->response;
  4368. }
  4369. }
  4370. }
  4371. namespace Symfony\Component\HttpKernel\Event
  4372. {
  4373. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4374. use Symfony\Component\HttpFoundation\Request;
  4375. class GetResponseForControllerResultEvent extends GetResponseEvent
  4376. {
  4377. private $controllerResult;
  4378. public function __construct(HttpKernelInterface $kernelRequest $request$requestType$controllerResult)
  4379. {
  4380. parent::__construct($kernel$request$requestType);
  4381. $this->controllerResult $controllerResult;
  4382. }
  4383. public function getControllerResult()
  4384. {
  4385. return $this->controllerResult;
  4386. }
  4387. public function setControllerResult($controllerResult)
  4388. {
  4389. $this->controllerResult $controllerResult;
  4390. }
  4391. }
  4392. }
  4393. namespace Symfony\Component\HttpKernel\Event
  4394. {
  4395. use Symfony\Component\HttpKernel\HttpKernelInterface;
  4396. use Symfony\Component\HttpFoundation\Request;
  4397. class GetResponseForExceptionEvent extends GetResponseEvent
  4398. {
  4399. private $exception;
  4400. private $allowCustomResponseCode false;
  4401. public function __construct(HttpKernelInterface $kernelRequest $request$requestType, \Exception $e)
  4402. {
  4403. parent::__construct($kernel$request$requestType);
  4404. $this->setException($e);
  4405. }
  4406. public function getException()
  4407. {
  4408. return $this->exception;
  4409. }
  4410. public function setException(\Exception $exception)
  4411. {
  4412. $this->exception $exception;
  4413. }
  4414. public function allowCustomResponseCode()
  4415. {
  4416. $this->allowCustomResponseCode true;
  4417. }
  4418. public function isAllowingCustomResponseCode()
  4419. {
  4420. return $this->allowCustomResponseCode;
  4421. }
  4422. }
  4423. }
  4424. namespace Symfony\Component\HttpKernel
  4425. {
  4426. use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
  4427. use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
  4428. use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
  4429. use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
  4430. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  4431. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  4432. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  4433. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  4434. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  4435. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  4436. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  4437. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  4438. use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  4439. use Symfony\Component\HttpKernel\Event\PostResponseEvent;
  4440. use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
  4441. use Symfony\Component\HttpFoundation\Request;
  4442. use Symfony\Component\HttpFoundation\RequestStack;
  4443. use Symfony\Component\HttpFoundation\Response;
  4444. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  4445. class HttpKernel implements HttpKernelInterfaceTerminableInterface
  4446. {
  4447. protected $dispatcher;
  4448. protected $resolver;
  4449. protected $requestStack;
  4450. private $argumentResolver;
  4451. public function __construct(EventDispatcherInterface $dispatcherControllerResolverInterface $resolverRequestStack $requestStack nullArgumentResolverInterface $argumentResolver null)
  4452. {
  4453. $this->dispatcher $dispatcher;
  4454. $this->resolver $resolver;
  4455. $this->requestStack $requestStack ?: new RequestStack();
  4456. $this->argumentResolver $argumentResolver;
  4457. if (null === $this->argumentResolver) {
  4458. @trigger_error(sprintf('As of 3.1 an %s is used to resolve arguments. In 4.0 the $argumentResolver becomes the %s if no other is provided instead of using the $resolver argument.'ArgumentResolverInterface::class, ArgumentResolver::class), E_USER_DEPRECATED);
  4459. $this->argumentResolver $resolver;
  4460. }
  4461. }
  4462. public function handle(Request $request$type HttpKernelInterface::MASTER_REQUEST$catch true)
  4463. {
  4464. $request->headers->set('X-Php-Ob-Level'ob_get_level());
  4465. try {
  4466. return $this->handleRaw($request$type);
  4467. } catch (\Exception $e) {
  4468. if ($e instanceof RequestExceptionInterface) {
  4469. $e = new BadRequestHttpException($e->getMessage(), $e);
  4470. }
  4471. if (false === $catch) {
  4472. $this->finishRequest($request$type);
  4473. throw $e;
  4474. }
  4475. return $this->handleException($e$request$type);
  4476. }
  4477. }
  4478. public function terminate(Request $requestResponse $response)
  4479. {
  4480. $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this$request$response));
  4481. }
  4482. public function terminateWithException(\Exception $exceptionRequest $request null)
  4483. {
  4484. if (!$request $request ?: $this->requestStack->getMasterRequest()) {
  4485. throw $exception;
  4486. }
  4487. $response $this->handleException($exception$requestself::MASTER_REQUEST);
  4488. $response->sendHeaders();
  4489. $response->sendContent();
  4490. $this->terminate($request$response);
  4491. }
  4492. private function handleRaw(Request $request$type self::MASTER_REQUEST)
  4493. {
  4494. $this->requestStack->push($request);
  4495. $event = new GetResponseEvent($this$request$type);
  4496. $this->dispatcher->dispatch(KernelEvents::REQUEST$event);
  4497. if ($event->hasResponse()) {
  4498. return $this->filterResponse($event->getResponse(), $request$type);
  4499. }
  4500. if (false === $controller $this->resolver->getController($request)) {
  4501. throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.'$request->getPathInfo()));
  4502. }
  4503. $event = new FilterControllerEvent($this$controller$request$type);
  4504. $this->dispatcher->dispatch(KernelEvents::CONTROLLER$event);
  4505. $controller $event->getController();
  4506. $arguments $this->argumentResolver->getArguments($request$controller);
  4507. $event = new FilterControllerArgumentsEvent($this$controller$arguments$request$type);
  4508. $this->dispatcher->dispatch(KernelEvents::CONTROLLER_ARGUMENTS$event);
  4509. $controller $event->getController();
  4510. $arguments $event->getArguments();
  4511. $response = \call_user_func_array($controller$arguments);
  4512. if (!$response instanceof Response) {
  4513. $event = new GetResponseForControllerResultEvent($this$request$type$response);
  4514. $this->dispatcher->dispatch(KernelEvents::VIEW$event);
  4515. if ($event->hasResponse()) {
  4516. $response $event->getResponse();
  4517. }
  4518. if (!$response instanceof Response) {
  4519. $msg sprintf('The controller must return a response (%s given).'$this->varToString($response));
  4520. if (null === $response) {
  4521. $msg .=' Did you forget to add a return statement somewhere in your controller?';
  4522. }
  4523. throw new \LogicException($msg);
  4524. }
  4525. }
  4526. return $this->filterResponse($response$request$type);
  4527. }
  4528. private function filterResponse(Response $responseRequest $request$type)
  4529. {
  4530. $event = new FilterResponseEvent($this$request$type$response);
  4531. $this->dispatcher->dispatch(KernelEvents::RESPONSE$event);
  4532. $this->finishRequest($request$type);
  4533. return $event->getResponse();
  4534. }
  4535. private function finishRequest(Request $request$type)
  4536. {
  4537. $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this$request$type));
  4538. $this->requestStack->pop();
  4539. }
  4540. private function handleException(\Exception $e$request$type)
  4541. {
  4542. $event = new GetResponseForExceptionEvent($this$request$type$e);
  4543. $this->dispatcher->dispatch(KernelEvents::EXCEPTION$event);
  4544. $e $event->getException();
  4545. if (!$event->hasResponse()) {
  4546. $this->finishRequest($request$type);
  4547. throw $e;
  4548. }
  4549. $response $event->getResponse();
  4550. if ($response->headers->has('X-Status-Code')) {
  4551. @trigger_error(sprintf('Using the X-Status-Code header is deprecated since Symfony 3.3 and will be removed in 4.0. Use %s::allowCustomResponseCode() instead.'GetResponseForExceptionEvent::class), E_USER_DEPRECATED);
  4552. $response->setStatusCode($response->headers->get('X-Status-Code'));
  4553. $response->headers->remove('X-Status-Code');
  4554. } elseif (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
  4555. if ($e instanceof HttpExceptionInterface) {
  4556. $response->setStatusCode($e->getStatusCode());
  4557. $response->headers->add($e->getHeaders());
  4558. } else {
  4559. $response->setStatusCode(500);
  4560. }
  4561. }
  4562. try {
  4563. return $this->filterResponse($response$request$type);
  4564. } catch (\Exception $e) {
  4565. return $response;
  4566. }
  4567. }
  4568. private function varToString($var)
  4569. {
  4570. if (is_object($var)) {
  4571. return sprintf('Object(%s)'get_class($var));
  4572. }
  4573. if (is_array($var)) {
  4574. $a = array();
  4575. foreach ($var as $k => $v) {
  4576. $a[] = sprintf('%s => %s'$k$this->varToString($v));
  4577. }
  4578. return sprintf('Array(%s)'implode(', '$a));
  4579. }
  4580. if (is_resource($var)) {
  4581. return sprintf('Resource(%s)'get_resource_type($var));
  4582. }
  4583. if (null === $var) {
  4584. return'null';
  4585. }
  4586. if (false === $var) {
  4587. return'false';
  4588. }
  4589. if (true === $var) {
  4590. return'true';
  4591. }
  4592. return (string) $var;
  4593. }
  4594. }
  4595. }
  4596. namespace Symfony\Component\HttpKernel
  4597. {
  4598. final class KernelEvents
  4599. {
  4600. const REQUEST ='kernel.request';
  4601. const EXCEPTION ='kernel.exception';
  4602. const VIEW ='kernel.view';
  4603. const CONTROLLER ='kernel.controller';
  4604. const CONTROLLER_ARGUMENTS ='kernel.controller_arguments';
  4605. const RESPONSE ='kernel.response';
  4606. const TERMINATE ='kernel.terminate';
  4607. const FINISH_REQUEST ='kernel.finish_request';
  4608. }
  4609. }
  4610. namespace Symfony\Component\HttpKernel\Config
  4611. {
  4612. use Symfony\Component\Config\FileLocator as BaseFileLocator;
  4613. use Symfony\Component\HttpKernel\KernelInterface;
  4614. class FileLocator extends BaseFileLocator
  4615. {
  4616. private $kernel;
  4617. private $path;
  4618. public function __construct(KernelInterface $kernel$path null, array $paths = array())
  4619. {
  4620. $this->kernel $kernel;
  4621. if (null !== $path) {
  4622. $this->path $path;
  4623. $paths[] = $path;
  4624. }
  4625. parent::__construct($paths);
  4626. }
  4627. public function locate($file$currentPath null$first true)
  4628. {
  4629. if (isset($file[0]) &&'@'=== $file[0]) {
  4630. return $this->kernel->locateResource($file$this->path$first);
  4631. }
  4632. return parent::locate($file$currentPath$first);
  4633. }
  4634. }
  4635. }
  4636. namespace Symfony\Bundle\FrameworkBundle\Controller
  4637. {
  4638. use Symfony\Component\HttpKernel\KernelInterface;
  4639. class ControllerNameParser
  4640. {
  4641. protected $kernel;
  4642. public function __construct(KernelInterface $kernel)
  4643. {
  4644. $this->kernel $kernel;
  4645. }
  4646. public function parse($controller)
  4647. {
  4648. $parts explode(':'$controller);
  4649. if (!== count($parts) || in_array(''$partstrue)) {
  4650. throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.'$controller));
  4651. }
  4652. $originalController $controller;
  4653. list($bundle$controller$action) = $parts;
  4654. $controller str_replace('/','\\'$controller);
  4655. $bundles = array();
  4656. try {
  4657. $allBundles $this->kernel->getBundle($bundlefalse);
  4658. } catch (\InvalidArgumentException $e) {
  4659. $message sprintf('The "%s" (from the _controller value "%s") does not exist or is not enabled in your kernel!',
  4660. $bundle,
  4661. $originalController
  4662. );
  4663. if ($alternative $this->findAlternative($bundle)) {
  4664. $message .= sprintf(' Did you mean "%s:%s:%s"?'$alternative$controller$action);
  4665. }
  4666. throw new \InvalidArgumentException($message0$e);
  4667. }
  4668. foreach ($allBundles as $b) {
  4669. $try $b->getNamespace().'\\Controller\\'.$controller.'Controller';
  4670. if (class_exists($try)) {
  4671. return $try.'::'.$action.'Action';
  4672. }
  4673. $bundles[] = $b->getName();
  4674. $msg sprintf('The _controller value "%s:%s:%s" maps to a "%s" class, but this class was not found. Create this class or check the spelling of the class and its namespace.'$bundle$controller$action$try);
  4675. }
  4676. if (count($bundles) > 1) {
  4677. $msg sprintf('Unable to find controller "%s:%s" in bundles %s.'$bundle$controllerimplode(', '$bundles));
  4678. }
  4679. throw new \InvalidArgumentException($msg);
  4680. }
  4681. public function build($controller)
  4682. {
  4683. if (=== preg_match('#^(.*?\\\\Controller\\\\(.+)Controller)::(.+)Action$#'$controller$match)) {
  4684. throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "class::method" string.'$controller));
  4685. }
  4686. $className $match[1];
  4687. $controllerName $match[2];
  4688. $actionName $match[3];
  4689. foreach ($this->kernel->getBundles() as $name => $bundle) {
  4690. if (!== strpos($className$bundle->getNamespace())) {
  4691. continue;
  4692. }
  4693. return sprintf('%s:%s:%s'$name$controllerName$actionName);
  4694. }
  4695. throw new \InvalidArgumentException(sprintf('Unable to find a bundle that defines controller "%s".'$controller));
  4696. }
  4697. private function findAlternative($nonExistentBundleName)
  4698. {
  4699. $bundleNames array_map(function ($b) {
  4700. return $b->getName();
  4701. }, $this->kernel->getBundles());
  4702. $alternative null;
  4703. $shortest null;
  4704. foreach ($bundleNames as $bundleName) {
  4705. if (false !== strpos($bundleName$nonExistentBundleName)) {
  4706. return $bundleName;
  4707. }
  4708. $lev levenshtein($nonExistentBundleName$bundleName);
  4709. if ($lev <= strlen($nonExistentBundleName) / && (null === $alternative || $lev $shortest)) {
  4710. $alternative $bundleName;
  4711. $shortest $lev;
  4712. }
  4713. }
  4714. return $alternative;
  4715. }
  4716. }
  4717. }
  4718. namespace Symfony\Component\HttpKernel\Controller
  4719. {
  4720. use Psr\Container\ContainerInterface;
  4721. use Psr\Log\LoggerInterface;
  4722. use Symfony\Component\HttpFoundation\Request;
  4723. class ContainerControllerResolver extends ControllerResolver
  4724. {
  4725. protected $container;
  4726. public function __construct(ContainerInterface $containerLoggerInterface $logger null)
  4727. {
  4728. $this->container $container;
  4729. parent::__construct($logger);
  4730. }
  4731. public function getController(Request $request)
  4732. {
  4733. $controller parent::getController($request);
  4734. if (is_array($controller) && isset($controller[0]) && is_string($controller[0]) && $this->container->has($controller[0])) {
  4735. $controller[0] = $this->instantiateController($controller[0]);
  4736. }
  4737. return $controller;
  4738. }
  4739. protected function createController($controller)
  4740. {
  4741. if (false !== strpos($controller,'::')) {
  4742. return parent::createController($controller);
  4743. }
  4744. if (== substr_count($controller,':')) {
  4745. list($service$method) = explode(':'$controller2);
  4746. return array($this->container->get($service), $method);
  4747. }
  4748. if ($this->container->has($controller) && method_exists($service $this->container->get($controller),'__invoke')) {
  4749. return $service;
  4750. }
  4751. throw new \LogicException(sprintf('Unable to parse the controller name "%s".'$controller));
  4752. }
  4753. protected function instantiateController($class)
  4754. {
  4755. if ($this->container->has($class)) {
  4756. return $this->container->get($class);
  4757. }
  4758. return parent::instantiateController($class);
  4759. }
  4760. }
  4761. }
  4762. namespace Symfony\Bundle\FrameworkBundle\Controller
  4763. {
  4764. use Psr\Log\LoggerInterface;
  4765. use Symfony\Component\DependencyInjection\ContainerInterface;
  4766. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  4767. use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
  4768. class ControllerResolver extends ContainerControllerResolver
  4769. {
  4770. protected $parser;
  4771. public function __construct(ContainerInterface $containerControllerNameParser $parserLoggerInterface $logger null)
  4772. {
  4773. $this->parser $parser;
  4774. parent::__construct($container$logger);
  4775. }
  4776. protected function createController($controller)
  4777. {
  4778. if (false === strpos($controller,'::') && === substr_count($controller,':')) {
  4779. $controller $this->parser->parse($controller);
  4780. }
  4781. $resolvedController parent::createController($controller);
  4782. if (=== substr_count($controller,':') && is_array($resolvedController)) {
  4783. if ($resolvedController[0] instanceof ContainerAwareInterface) {
  4784. $resolvedController[0]->setContainer($this->container);
  4785. }
  4786. if ($resolvedController[0] instanceof AbstractController && null !== $previousContainer $resolvedController[0]->setContainer($this->container)) {
  4787. $resolvedController[0]->setContainer($previousContainer);
  4788. }
  4789. }
  4790. return $resolvedController;
  4791. }
  4792. protected function instantiateController($class)
  4793. {
  4794. $controller parent::instantiateController($class);
  4795. if ($controller instanceof ContainerAwareInterface) {
  4796. $controller->setContainer($this->container);
  4797. }
  4798. if ($controller instanceof AbstractController && null !== $previousContainer $controller->setContainer($this->container)) {
  4799. $controller->setContainer($previousContainer);
  4800. }
  4801. return $controller;
  4802. }
  4803. }
  4804. }
  4805. namespace Symfony\Component\Security\Http
  4806. {
  4807. use Symfony\Component\HttpFoundation\Request;
  4808. interface AccessMapInterface
  4809. {
  4810. public function getPatterns(Request $request);
  4811. }
  4812. }
  4813. namespace Symfony\Component\Security\Http
  4814. {
  4815. use Symfony\Component\HttpFoundation\RequestMatcherInterface;
  4816. use Symfony\Component\HttpFoundation\Request;
  4817. class AccessMap implements AccessMapInterface
  4818. {
  4819. private $map = array();
  4820. public function add(RequestMatcherInterface $requestMatcher, array $attributes = array(), $channel null)
  4821. {
  4822. $this->map[] = array($requestMatcher$attributes$channel);
  4823. }
  4824. public function getPatterns(Request $request)
  4825. {
  4826. foreach ($this->map as $elements) {
  4827. if (null === $elements[0] || $elements[0]->matches($request)) {
  4828. return array($elements[1], $elements[2]);
  4829. }
  4830. }
  4831. return array(nullnull);
  4832. }
  4833. }
  4834. }
  4835. namespace Symfony\Component\Security\Http
  4836. {
  4837. use Symfony\Component\HttpKernel\KernelEvents;
  4838. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  4839. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  4840. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  4841. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4842. class Firewall implements EventSubscriberInterface
  4843. {
  4844. private $map;
  4845. private $dispatcher;
  4846. private $exceptionListeners;
  4847. public function __construct(FirewallMapInterface $mapEventDispatcherInterface $dispatcher)
  4848. {
  4849. $this->map $map;
  4850. $this->dispatcher $dispatcher;
  4851. $this->exceptionListeners = new \SplObjectStorage();
  4852. }
  4853. public function onKernelRequest(GetResponseEvent $event)
  4854. {
  4855. if (!$event->isMasterRequest()) {
  4856. return;
  4857. }
  4858. list($listeners$exceptionListener) = $this->map->getListeners($event->getRequest());
  4859. if (null !== $exceptionListener) {
  4860. $this->exceptionListeners[$event->getRequest()] = $exceptionListener;
  4861. $exceptionListener->register($this->dispatcher);
  4862. }
  4863. foreach ($listeners as $listener) {
  4864. $listener->handle($event);
  4865. if ($event->hasResponse()) {
  4866. break;
  4867. }
  4868. }
  4869. }
  4870. public function onKernelFinishRequest(FinishRequestEvent $event)
  4871. {
  4872. $request $event->getRequest();
  4873. if (isset($this->exceptionListeners[$request])) {
  4874. $this->exceptionListeners[$request]->unregister($this->dispatcher);
  4875. unset($this->exceptionListeners[$request]);
  4876. }
  4877. }
  4878. public static function getSubscribedEvents()
  4879. {
  4880. return array(
  4881. KernelEvents::REQUEST => array('onKernelRequest'8),
  4882. KernelEvents::FINISH_REQUEST =>'onKernelFinishRequest',
  4883. );
  4884. }
  4885. }
  4886. }
  4887. namespace Symfony\Component\Security\Core\User
  4888. {
  4889. use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
  4890. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  4891. interface UserProviderInterface
  4892. {
  4893. public function loadUserByUsername($username);
  4894. public function refreshUser(UserInterface $user);
  4895. public function supportsClass($class);
  4896. }
  4897. }
  4898. namespace Symfony\Component\Security\Core\Authentication
  4899. {
  4900. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4901. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  4902. interface AuthenticationManagerInterface
  4903. {
  4904. public function authenticate(TokenInterface $token);
  4905. }
  4906. }
  4907. namespace Symfony\Component\Security\Core\Authentication
  4908. {
  4909. use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
  4910. use Symfony\Component\Security\Core\Event\AuthenticationEvent;
  4911. use Symfony\Component\Security\Core\AuthenticationEvents;
  4912. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  4913. use Symfony\Component\Security\Core\Exception\AccountStatusException;
  4914. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  4915. use Symfony\Component\Security\Core\Exception\ProviderNotFoundException;
  4916. use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
  4917. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4918. class AuthenticationProviderManager implements AuthenticationManagerInterface
  4919. {
  4920. private $providers;
  4921. private $eraseCredentials;
  4922. private $eventDispatcher;
  4923. public function __construct($providers$eraseCredentials true)
  4924. {
  4925. if (!$providers) {
  4926. throw new \InvalidArgumentException('You must at least add one authentication provider.');
  4927. }
  4928. $this->providers $providers;
  4929. $this->eraseCredentials = (bool) $eraseCredentials;
  4930. }
  4931. public function setEventDispatcher(EventDispatcherInterface $dispatcher)
  4932. {
  4933. $this->eventDispatcher $dispatcher;
  4934. }
  4935. public function authenticate(TokenInterface $token)
  4936. {
  4937. $lastException null;
  4938. $result null;
  4939. foreach ($this->providers as $provider) {
  4940. if (!$provider instanceof AuthenticationProviderInterface) {
  4941. throw new \InvalidArgumentException(sprintf('Provider "%s" must implement the AuthenticationProviderInterface.'get_class($provider)));
  4942. }
  4943. if (!$provider->supports($token)) {
  4944. continue;
  4945. }
  4946. try {
  4947. $result $provider->authenticate($token);
  4948. if (null !== $result) {
  4949. break;
  4950. }
  4951. } catch (AccountStatusException $e) {
  4952. $lastException $e;
  4953. break;
  4954. } catch (AuthenticationException $e) {
  4955. $lastException $e;
  4956. }
  4957. }
  4958. if (null !== $result) {
  4959. if (true === $this->eraseCredentials) {
  4960. $result->eraseCredentials();
  4961. }
  4962. if (null !== $this->eventDispatcher) {
  4963. $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($result));
  4964. }
  4965. return $result;
  4966. }
  4967. if (null === $lastException) {
  4968. $lastException = new ProviderNotFoundException(sprintf('No Authentication Provider found for token of class "%s".'get_class($token)));
  4969. }
  4970. if (null !== $this->eventDispatcher) {
  4971. $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token$lastException));
  4972. }
  4973. $lastException->setToken($token);
  4974. throw $lastException;
  4975. }
  4976. }
  4977. }
  4978. namespace Symfony\Component\Security\Core\Authentication\Token\Storage
  4979. {
  4980. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4981. interface TokenStorageInterface
  4982. {
  4983. public function getToken();
  4984. public function setToken(TokenInterface $token null);
  4985. }
  4986. }
  4987. namespace Symfony\Component\Security\Core\Authentication\Token\Storage
  4988. {
  4989. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4990. class TokenStorage implements TokenStorageInterface
  4991. {
  4992. private $token;
  4993. public function getToken()
  4994. {
  4995. return $this->token;
  4996. }
  4997. public function setToken(TokenInterface $token null)
  4998. {
  4999. $this->token $token;
  5000. }
  5001. }
  5002. }
  5003. namespace Symfony\Component\Security\Core\Authorization
  5004. {
  5005. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5006. interface AccessDecisionManagerInterface
  5007. {
  5008. public function decide(TokenInterface $token, array $attributes$object null);
  5009. }
  5010. }
  5011. namespace Symfony\Component\Security\Core\Authorization
  5012. {
  5013. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  5014. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5015. class AccessDecisionManager implements AccessDecisionManagerInterface
  5016. {
  5017. const STRATEGY_AFFIRMATIVE ='affirmative';
  5018. const STRATEGY_CONSENSUS ='consensus';
  5019. const STRATEGY_UNANIMOUS ='unanimous';
  5020. private $voters;
  5021. private $strategy;
  5022. private $allowIfAllAbstainDecisions;
  5023. private $allowIfEqualGrantedDeniedDecisions;
  5024. public function __construct($voters = array(), $strategy self::STRATEGY_AFFIRMATIVE$allowIfAllAbstainDecisions false$allowIfEqualGrantedDeniedDecisions true)
  5025. {
  5026. $strategyMethod ='decide'.ucfirst($strategy);
  5027. if (!is_callable(array($this$strategyMethod))) {
  5028. throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.'$strategy));
  5029. }
  5030. $this->voters $voters;
  5031. $this->strategy $strategyMethod;
  5032. $this->allowIfAllAbstainDecisions = (bool) $allowIfAllAbstainDecisions;
  5033. $this->allowIfEqualGrantedDeniedDecisions = (bool) $allowIfEqualGrantedDeniedDecisions;
  5034. }
  5035. public function setVoters(array $voters)
  5036. {
  5037. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Pass the voters to the constructor instead.'__METHOD__), E_USER_DEPRECATED);
  5038. $this->voters $voters;
  5039. }
  5040. public function decide(TokenInterface $token, array $attributes$object null)
  5041. {
  5042. return $this->{$this->strategy}($token$attributes$object);
  5043. }
  5044. private function decideAffirmative(TokenInterface $token, array $attributes$object null)
  5045. {
  5046. $deny 0;
  5047. foreach ($this->voters as $voter) {
  5048. $result $voter->vote($token$object$attributes);
  5049. switch ($result) {
  5050. case VoterInterface::ACCESS_GRANTED:
  5051. return true;
  5052. case VoterInterface::ACCESS_DENIED:
  5053. ++$deny;
  5054. break;
  5055. default:
  5056. break;
  5057. }
  5058. }
  5059. if ($deny 0) {
  5060. return false;
  5061. }
  5062. return $this->allowIfAllAbstainDecisions;
  5063. }
  5064. private function decideConsensus(TokenInterface $token, array $attributes$object null)
  5065. {
  5066. $grant 0;
  5067. $deny 0;
  5068. foreach ($this->voters as $voter) {
  5069. $result $voter->vote($token$object$attributes);
  5070. switch ($result) {
  5071. case VoterInterface::ACCESS_GRANTED:
  5072. ++$grant;
  5073. break;
  5074. case VoterInterface::ACCESS_DENIED:
  5075. ++$deny;
  5076. break;
  5077. }
  5078. }
  5079. if ($grant $deny) {
  5080. return true;
  5081. }
  5082. if ($deny $grant) {
  5083. return false;
  5084. }
  5085. if ($grant 0) {
  5086. return $this->allowIfEqualGrantedDeniedDecisions;
  5087. }
  5088. return $this->allowIfAllAbstainDecisions;
  5089. }
  5090. private function decideUnanimous(TokenInterface $token, array $attributes$object null)
  5091. {
  5092. $grant 0;
  5093. foreach ($this->voters as $voter) {
  5094. foreach ($attributes as $attribute) {
  5095. $result $voter->vote($token$object, array($attribute));
  5096. switch ($result) {
  5097. case VoterInterface::ACCESS_GRANTED:
  5098. ++$grant;
  5099. break;
  5100. case VoterInterface::ACCESS_DENIED:
  5101. return false;
  5102. default:
  5103. break;
  5104. }
  5105. }
  5106. }
  5107. if ($grant 0) {
  5108. return true;
  5109. }
  5110. return $this->allowIfAllAbstainDecisions;
  5111. }
  5112. }
  5113. }
  5114. namespace Symfony\Component\Security\Core\Authorization
  5115. {
  5116. interface AuthorizationCheckerInterface
  5117. {
  5118. public function isGranted($attributes$object null);
  5119. }
  5120. }
  5121. namespace Symfony\Component\Security\Core\Authorization
  5122. {
  5123. use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
  5124. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  5125. use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
  5126. class AuthorizationChecker implements AuthorizationCheckerInterface
  5127. {
  5128. private $tokenStorage;
  5129. private $accessDecisionManager;
  5130. private $authenticationManager;
  5131. private $alwaysAuthenticate;
  5132. public function __construct(TokenStorageInterface $tokenStorageAuthenticationManagerInterface $authenticationManagerAccessDecisionManagerInterface $accessDecisionManager$alwaysAuthenticate false)
  5133. {
  5134. $this->tokenStorage $tokenStorage;
  5135. $this->authenticationManager $authenticationManager;
  5136. $this->accessDecisionManager $accessDecisionManager;
  5137. $this->alwaysAuthenticate $alwaysAuthenticate;
  5138. }
  5139. final public function isGranted($attributes$object null)
  5140. {
  5141. if (null === ($token $this->tokenStorage->getToken())) {
  5142. throw new AuthenticationCredentialsNotFoundException('The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');
  5143. }
  5144. if ($this->alwaysAuthenticate || !$token->isAuthenticated()) {
  5145. $this->tokenStorage->setToken($token $this->authenticationManager->authenticate($token));
  5146. }
  5147. if (!is_array($attributes)) {
  5148. $attributes = array($attributes);
  5149. }
  5150. return $this->accessDecisionManager->decide($token$attributes$object);
  5151. }
  5152. }
  5153. }
  5154. namespace Symfony\Component\Security\Core\Authorization\Voter
  5155. {
  5156. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5157. interface VoterInterface
  5158. {
  5159. const ACCESS_GRANTED 1;
  5160. const ACCESS_ABSTAIN 0;
  5161. const ACCESS_DENIED = -1;
  5162. public function vote(TokenInterface $token$subject, array $attributes);
  5163. }
  5164. }
  5165. namespace Symfony\Bundle\SecurityBundle\Security
  5166. {
  5167. final class FirewallConfig
  5168. {
  5169. private $name;
  5170. private $userChecker;
  5171. private $requestMatcher;
  5172. private $securityEnabled;
  5173. private $stateless;
  5174. private $provider;
  5175. private $context;
  5176. private $entryPoint;
  5177. private $accessDeniedHandler;
  5178. private $accessDeniedUrl;
  5179. private $listeners;
  5180. public function __construct($name$userChecker$requestMatcher null$securityEnabled true$stateless false$provider null$context null$entryPoint null$accessDeniedHandler null$accessDeniedUrl null$listeners = array())
  5181. {
  5182. $this->name $name;
  5183. $this->userChecker $userChecker;
  5184. $this->requestMatcher $requestMatcher;
  5185. $this->securityEnabled $securityEnabled;
  5186. $this->stateless $stateless;
  5187. $this->provider $provider;
  5188. $this->context $context;
  5189. $this->entryPoint $entryPoint;
  5190. $this->accessDeniedHandler $accessDeniedHandler;
  5191. $this->accessDeniedUrl $accessDeniedUrl;
  5192. $this->listeners $listeners;
  5193. }
  5194. public function getName()
  5195. {
  5196. return $this->name;
  5197. }
  5198. public function getRequestMatcher()
  5199. {
  5200. return $this->requestMatcher;
  5201. }
  5202. public function isSecurityEnabled()
  5203. {
  5204. return $this->securityEnabled;
  5205. }
  5206. public function allowsAnonymous()
  5207. {
  5208. return in_array('anonymous'$this->listenerstrue);
  5209. }
  5210. public function isStateless()
  5211. {
  5212. return $this->stateless;
  5213. }
  5214. public function getProvider()
  5215. {
  5216. return $this->provider;
  5217. }
  5218. public function getContext()
  5219. {
  5220. return $this->context;
  5221. }
  5222. public function getEntryPoint()
  5223. {
  5224. return $this->entryPoint;
  5225. }
  5226. public function getUserChecker()
  5227. {
  5228. return $this->userChecker;
  5229. }
  5230. public function getAccessDeniedHandler()
  5231. {
  5232. return $this->accessDeniedHandler;
  5233. }
  5234. public function getAccessDeniedUrl()
  5235. {
  5236. return $this->accessDeniedUrl;
  5237. }
  5238. public function getListeners()
  5239. {
  5240. return $this->listeners;
  5241. }
  5242. }
  5243. }
  5244. namespace Symfony\Bundle\SecurityBundle\Security
  5245. {
  5246. use Symfony\Component\Security\Http\Firewall\ExceptionListener;
  5247. class FirewallContext
  5248. {
  5249. private $listeners;
  5250. private $exceptionListener;
  5251. private $config;
  5252. public function __construct(array $listenersExceptionListener $exceptionListener nullFirewallConfig $config null)
  5253. {
  5254. $this->listeners $listeners;
  5255. $this->exceptionListener $exceptionListener;
  5256. $this->config $config;
  5257. }
  5258. public function getConfig()
  5259. {
  5260. return $this->config;
  5261. }
  5262. public function getContext()
  5263. {
  5264. @trigger_error(sprintf('Method %s() is deprecated since Symfony 3.3 and will be removed in 4.0. Use %s::getListeners/getExceptionListener() instead.'__METHOD____CLASS__), E_USER_DEPRECATED);
  5265. return array($this->getListeners(), $this->getExceptionListener());
  5266. }
  5267. public function getListeners()
  5268. {
  5269. return $this->listeners;
  5270. }
  5271. public function getExceptionListener()
  5272. {
  5273. return $this->exceptionListener;
  5274. }
  5275. }
  5276. }
  5277. namespace Symfony\Component\HttpFoundation
  5278. {
  5279. interface RequestMatcherInterface
  5280. {
  5281. public function matches(Request $request);
  5282. }
  5283. }
  5284. namespace Symfony\Component\HttpFoundation
  5285. {
  5286. class RequestMatcher implements RequestMatcherInterface
  5287. {
  5288. private $path;
  5289. private $host;
  5290. private $methods = array();
  5291. private $ips = array();
  5292. private $attributes = array();
  5293. private $schemes = array();
  5294. public function __construct($path null$host null$methods null$ips null, array $attributes = array(), $schemes null)
  5295. {
  5296. $this->matchPath($path);
  5297. $this->matchHost($host);
  5298. $this->matchMethod($methods);
  5299. $this->matchIps($ips);
  5300. $this->matchScheme($schemes);
  5301. foreach ($attributes as $k => $v) {
  5302. $this->matchAttribute($k$v);
  5303. }
  5304. }
  5305. public function matchScheme($scheme)
  5306. {
  5307. $this->schemes null !== $scheme array_map('strtolower', (array) $scheme) : array();
  5308. }
  5309. public function matchHost($regexp)
  5310. {
  5311. $this->host $regexp;
  5312. }
  5313. public function matchPath($regexp)
  5314. {
  5315. $this->path $regexp;
  5316. }
  5317. public function matchIp($ip)
  5318. {
  5319. $this->matchIps($ip);
  5320. }
  5321. public function matchIps($ips)
  5322. {
  5323. $this->ips null !== $ips ? (array) $ips : array();
  5324. }
  5325. public function matchMethod($method)
  5326. {
  5327. $this->methods null !== $method array_map('strtoupper', (array) $method) : array();
  5328. }
  5329. public function matchAttribute($key$regexp)
  5330. {
  5331. $this->attributes[$key] = $regexp;
  5332. }
  5333. public function matches(Request $request)
  5334. {
  5335. if ($this->schemes && !in_array($request->getScheme(), $this->schemestrue)) {
  5336. return false;
  5337. }
  5338. if ($this->methods && !in_array($request->getMethod(), $this->methodstrue)) {
  5339. return false;
  5340. }
  5341. foreach ($this->attributes as $key => $pattern) {
  5342. if (!preg_match('{'.$pattern.'}'$request->attributes->get($key))) {
  5343. return false;
  5344. }
  5345. }
  5346. if (null !== $this->path && !preg_match('{'.$this->path.'}'rawurldecode($request->getPathInfo()))) {
  5347. return false;
  5348. }
  5349. if (null !== $this->host && !preg_match('{'.$this->host.'}i'$request->getHost())) {
  5350. return false;
  5351. }
  5352. if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
  5353. return true;
  5354. }
  5355. return === count($this->ips);
  5356. }
  5357. }
  5358. }
  5359. namespace Twig
  5360. {
  5361. use Twig\Cache\CacheInterface;
  5362. use Twig\Cache\FilesystemCache;
  5363. use Twig\Cache\NullCache;
  5364. use Twig\Error\Error;
  5365. use Twig\Error\LoaderError;
  5366. use Twig\Error\RuntimeError;
  5367. use Twig\Error\SyntaxError;
  5368. use Twig\Extension\CoreExtension;
  5369. use Twig\Extension\EscaperExtension;
  5370. use Twig\Extension\ExtensionInterface;
  5371. use Twig\Extension\GlobalsInterface;
  5372. use Twig\Extension\InitRuntimeInterface;
  5373. use Twig\Extension\OptimizerExtension;
  5374. use Twig\Extension\StagingExtension;
  5375. use Twig\Loader\ArrayLoader;
  5376. use Twig\Loader\ChainLoader;
  5377. use Twig\Loader\LoaderInterface;
  5378. use Twig\Loader\SourceContextLoaderInterface;
  5379. use Twig\Node\ModuleNode;
  5380. use Twig\NodeVisitor\NodeVisitorInterface;
  5381. use Twig\RuntimeLoader\RuntimeLoaderInterface;
  5382. use Twig\TokenParser\TokenParserInterface;
  5383. class Environment
  5384. {
  5385. const VERSION ='1.42.5';
  5386. const VERSION_ID 14205;
  5387. const MAJOR_VERSION 1;
  5388. const MINOR_VERSION 42;
  5389. const RELEASE_VERSION 5;
  5390. const EXTRA_VERSION ='';
  5391. protected $charset;
  5392. protected $loader;
  5393. protected $debug;
  5394. protected $autoReload;
  5395. protected $cache;
  5396. protected $lexer;
  5397. protected $parser;
  5398. protected $compiler;
  5399. protected $baseTemplateClass;
  5400. protected $extensions;
  5401. protected $parsers;
  5402. protected $visitors;
  5403. protected $filters;
  5404. protected $tests;
  5405. protected $functions;
  5406. protected $globals;
  5407. protected $runtimeInitialized false;
  5408. protected $extensionInitialized false;
  5409. protected $loadedTemplates;
  5410. protected $strictVariables;
  5411. protected $unaryOperators;
  5412. protected $binaryOperators;
  5413. protected $templateClassPrefix ='__TwigTemplate_';
  5414. protected $functionCallbacks = [];
  5415. protected $filterCallbacks = [];
  5416. protected $staging;
  5417. private $originalCache;
  5418. private $bcWriteCacheFile false;
  5419. private $bcGetCacheFilename false;
  5420. private $lastModifiedExtension 0;
  5421. private $extensionsByClass = [];
  5422. private $runtimeLoaders = [];
  5423. private $runtimes = [];
  5424. private $optionsHash;
  5425. public function __construct(LoaderInterface $loader null$options = [])
  5426. {
  5427. if (null !== $loader) {
  5428. $this->setLoader($loader);
  5429. } else {
  5430. @trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.'E_USER_DEPRECATED);
  5431. }
  5432. $options array_merge(['debug'=> false,'charset'=>'UTF-8','base_template_class'=>'\Twig\Template','strict_variables'=> false,'autoescape'=>'html','cache'=> false,'auto_reload'=> null,'optimizations'=> -1,
  5433. ], $options);
  5434. $this->debug = (bool) $options['debug'];
  5435. $this->charset strtoupper($options['charset']);
  5436. $this->baseTemplateClass $options['base_template_class'];
  5437. $this->autoReload null === $options['auto_reload'] ? $this->debug : (bool) $options['auto_reload'];
  5438. $this->strictVariables = (bool) $options['strict_variables'];
  5439. $this->setCache($options['cache']);
  5440. $this->addExtension(new CoreExtension());
  5441. $this->addExtension(new EscaperExtension($options['autoescape']));
  5442. $this->addExtension(new OptimizerExtension($options['optimizations']));
  5443. $this->staging = new StagingExtension();
  5444. if (\is_string($this->originalCache)) {
  5445. $r = new \ReflectionMethod($this,'writeCacheFile');
  5446. if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
  5447. @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.'E_USER_DEPRECATED);
  5448. $this->bcWriteCacheFile true;
  5449. }
  5450. $r = new \ReflectionMethod($this,'getCacheFilename');
  5451. if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
  5452. @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.'E_USER_DEPRECATED);
  5453. $this->bcGetCacheFilename true;
  5454. }
  5455. }
  5456. }
  5457. public function getBaseTemplateClass()
  5458. {
  5459. return $this->baseTemplateClass;
  5460. }
  5461. public function setBaseTemplateClass($class)
  5462. {
  5463. $this->baseTemplateClass $class;
  5464. $this->updateOptionsHash();
  5465. }
  5466. public function enableDebug()
  5467. {
  5468. $this->debug true;
  5469. $this->updateOptionsHash();
  5470. }
  5471. public function disableDebug()
  5472. {
  5473. $this->debug false;
  5474. $this->updateOptionsHash();
  5475. }
  5476. public function isDebug()
  5477. {
  5478. return $this->debug;
  5479. }
  5480. public function enableAutoReload()
  5481. {
  5482. $this->autoReload true;
  5483. }
  5484. public function disableAutoReload()
  5485. {
  5486. $this->autoReload false;
  5487. }
  5488. public function isAutoReload()
  5489. {
  5490. return $this->autoReload;
  5491. }
  5492. public function enableStrictVariables()
  5493. {
  5494. $this->strictVariables true;
  5495. $this->updateOptionsHash();
  5496. }
  5497. public function disableStrictVariables()
  5498. {
  5499. $this->strictVariables false;
  5500. $this->updateOptionsHash();
  5501. }
  5502. public function isStrictVariables()
  5503. {
  5504. return $this->strictVariables;
  5505. }
  5506. public function getCache($original true)
  5507. {
  5508. return $original $this->originalCache $this->cache;
  5509. }
  5510. public function setCache($cache)
  5511. {
  5512. if (\is_string($cache)) {
  5513. $this->originalCache $cache;
  5514. $this->cache = new FilesystemCache($cache);
  5515. } elseif (false === $cache) {
  5516. $this->originalCache $cache;
  5517. $this->cache = new NullCache();
  5518. } elseif (null === $cache) {
  5519. @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.'E_USER_DEPRECATED);
  5520. $this->originalCache false;
  5521. $this->cache = new NullCache();
  5522. } elseif ($cache instanceof CacheInterface) {
  5523. $this->originalCache $this->cache $cache;
  5524. } else {
  5525. throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'));
  5526. }
  5527. }
  5528. public function getCacheFilename($name)
  5529. {
  5530. @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  5531. $key $this->cache->generateKey($name$this->getTemplateClass($name));
  5532. return !$key false $key;
  5533. }
  5534. public function getTemplateClass($name$index null)
  5535. {
  5536. $key $this->getLoader()->getCacheKey($name).$this->optionsHash;
  5537. return $this->templateClassPrefix.hash('sha256'$key).(null === $index ?'':'___'.$index);
  5538. }
  5539. public function getTemplateClassPrefix()
  5540. {
  5541. @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  5542. return $this->templateClassPrefix;
  5543. }
  5544. public function render($name, array $context = [])
  5545. {
  5546. return $this->load($name)->render($context);
  5547. }
  5548. public function display($name, array $context = [])
  5549. {
  5550. $this->load($name)->display($context);
  5551. }
  5552. public function load($name)
  5553. {
  5554. if ($name instanceof TemplateWrapper) {
  5555. return $name;
  5556. }
  5557. if ($name instanceof Template) {
  5558. return new TemplateWrapper($this$name);
  5559. }
  5560. return new TemplateWrapper($this$this->loadTemplate($name));
  5561. }
  5562. public function loadTemplate($name$index null)
  5563. {
  5564. return $this->loadClass($this->getTemplateClass($name), $name$index);
  5565. }
  5566. public function loadClass($cls$name$index null)
  5567. {
  5568. $mainCls $cls;
  5569. if (null !== $index) {
  5570. $cls .='___'.$index;
  5571. }
  5572. if (isset($this->loadedTemplates[$cls])) {
  5573. return $this->loadedTemplates[$cls];
  5574. }
  5575. if (!class_exists($clsfalse)) {
  5576. if ($this->bcGetCacheFilename) {
  5577. $key $this->getCacheFilename($name);
  5578. } else {
  5579. $key $this->cache->generateKey($name$mainCls);
  5580. }
  5581. if (!$this->isAutoReload() || $this->isTemplateFresh($name$this->cache->getTimestamp($key))) {
  5582. $this->cache->load($key);
  5583. }
  5584. $source null;
  5585. if (!class_exists($clsfalse)) {
  5586. $loader $this->getLoader();
  5587. if (!$loader instanceof SourceContextLoaderInterface) {
  5588. $source = new Source($loader->getSource($name), $name);
  5589. } else {
  5590. $source $loader->getSourceContext($name);
  5591. }
  5592. $content $this->compileSource($source);
  5593. if ($this->bcWriteCacheFile) {
  5594. $this->writeCacheFile($key$content);
  5595. } else {
  5596. $this->cache->write($key$content);
  5597. $this->cache->load($key);
  5598. }
  5599. if (!class_exists($mainClsfalse)) {
  5600. eval('?>'.$content);
  5601. }
  5602. }
  5603. if (!class_exists($clsfalse)) {
  5604. throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.'$name$index), -1$source);
  5605. }
  5606. }
  5607. if (!$this->runtimeInitialized) {
  5608. $this->initRuntime();
  5609. }
  5610. return $this->loadedTemplates[$cls] = new $cls($this);
  5611. }
  5612. public function createTemplate($template$name null)
  5613. {
  5614. $hash hash('sha256'$templatefalse);
  5615. if (null !== $name) {
  5616. $name sprintf('%s (string template %s)'$name$hash);
  5617. } else {
  5618. $name sprintf('__string_template__%s'$hash);
  5619. }
  5620. $loader = new ChainLoader([
  5621. new ArrayLoader([$name => $template]),
  5622. $current $this->getLoader(),
  5623. ]);
  5624. $this->setLoader($loader);
  5625. try {
  5626. $template = new TemplateWrapper($this$this->loadTemplate($name));
  5627. } catch (\Exception $e) {
  5628. $this->setLoader($current);
  5629. throw $e;
  5630. } catch (\Throwable $e) {
  5631. $this->setLoader($current);
  5632. throw $e;
  5633. }
  5634. $this->setLoader($current);
  5635. return $template;
  5636. }
  5637. public function isTemplateFresh($name$time)
  5638. {
  5639. if (=== $this->lastModifiedExtension) {
  5640. foreach ($this->extensions as $extension) {
  5641. $r = new \ReflectionObject($extension);
  5642. if (file_exists($r->getFileName()) && ($extensionTime filemtime($r->getFileName())) > $this->lastModifiedExtension) {
  5643. $this->lastModifiedExtension $extensionTime;
  5644. }
  5645. }
  5646. }
  5647. return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name$time);
  5648. }
  5649. public function resolveTemplate($names)
  5650. {
  5651. if (!\is_array($names)) {
  5652. $names = [$names];
  5653. }
  5654. foreach ($names as $name) {
  5655. if ($name instanceof Template) {
  5656. return $name;
  5657. }
  5658. if ($name instanceof TemplateWrapper) {
  5659. return $name;
  5660. }
  5661. try {
  5662. return $this->loadTemplate($name);
  5663. } catch (LoaderError $e) {
  5664. if (=== \count($names)) {
  5665. throw $e;
  5666. }
  5667. }
  5668. }
  5669. throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".'implode('", "'$names)));
  5670. }
  5671. public function clearTemplateCache()
  5672. {
  5673. @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  5674. $this->loadedTemplates = [];
  5675. }
  5676. public function clearCacheFiles()
  5677. {
  5678. @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  5679. if (\is_string($this->originalCache)) {
  5680. foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
  5681. if ($file->isFile()) {
  5682. @unlink($file->getPathname());
  5683. }
  5684. }
  5685. }
  5686. }
  5687. public function getLexer()
  5688. {
  5689. @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.'__FUNCTION__), E_USER_DEPRECATED);
  5690. if (null === $this->lexer) {
  5691. $this->lexer = new Lexer($this);
  5692. }
  5693. return $this->lexer;
  5694. }
  5695. public function setLexer(\Twig_LexerInterface $lexer)
  5696. {
  5697. $this->lexer $lexer;
  5698. }
  5699. public function tokenize($source$name null)
  5700. {
  5701. if (!$source instanceof Source) {
  5702. @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.'__METHOD__), E_USER_DEPRECATED);
  5703. $source = new Source($source$name);
  5704. }
  5705. if (null === $this->lexer) {
  5706. $this->lexer = new Lexer($this);
  5707. }
  5708. return $this->lexer->tokenize($source);
  5709. }
  5710. public function getParser()
  5711. {
  5712. @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.'__FUNCTION__), E_USER_DEPRECATED);
  5713. if (null === $this->parser) {
  5714. $this->parser = new Parser($this);
  5715. }
  5716. return $this->parser;
  5717. }
  5718. public function setParser(\Twig_ParserInterface $parser)
  5719. {
  5720. $this->parser $parser;
  5721. }
  5722. public function parse(TokenStream $stream)
  5723. {
  5724. if (null === $this->parser) {
  5725. $this->parser = new Parser($this);
  5726. }
  5727. return $this->parser->parse($stream);
  5728. }
  5729. public function getCompiler()
  5730. {
  5731. @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.'__FUNCTION__), E_USER_DEPRECATED);
  5732. if (null === $this->compiler) {
  5733. $this->compiler = new Compiler($this);
  5734. }
  5735. return $this->compiler;
  5736. }
  5737. public function setCompiler(\Twig_CompilerInterface $compiler)
  5738. {
  5739. $this->compiler $compiler;
  5740. }
  5741. public function compile(\Twig_NodeInterface $node)
  5742. {
  5743. if (null === $this->compiler) {
  5744. $this->compiler = new Compiler($this);
  5745. }
  5746. return $this->compiler->compile($node)->getSource();
  5747. }
  5748. public function compileSource($source$name null)
  5749. {
  5750. if (!$source instanceof Source) {
  5751. @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.'__METHOD__), E_USER_DEPRECATED);
  5752. $source = new Source($source$name);
  5753. }
  5754. try {
  5755. return $this->compile($this->parse($this->tokenize($source)));
  5756. } catch (Error $e) {
  5757. $e->setSourceContext($source);
  5758. throw $e;
  5759. } catch (\Exception $e) {
  5760. throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").'$e->getMessage()), -1$source$e);
  5761. }
  5762. }
  5763. public function setLoader(LoaderInterface $loader)
  5764. {
  5765. if (!$loader instanceof SourceContextLoaderInterface && !== strpos(\get_class($loader),'Mock_')) {
  5766. @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED);
  5767. }
  5768. $this->loader $loader;
  5769. }
  5770. public function getLoader()
  5771. {
  5772. if (null === $this->loader) {
  5773. throw new \LogicException('You must set a loader first.');
  5774. }
  5775. return $this->loader;
  5776. }
  5777. public function setCharset($charset)
  5778. {
  5779. $this->charset strtoupper($charset);
  5780. }
  5781. public function getCharset()
  5782. {
  5783. return $this->charset;
  5784. }
  5785. public function initRuntime()
  5786. {
  5787. $this->runtimeInitialized true;
  5788. foreach ($this->getExtensions() as $name => $extension) {
  5789. if (!$extension instanceof InitRuntimeInterface) {
  5790. $m = new \ReflectionMethod($extension,'initRuntime');
  5791. $parentClass $m->getDeclaringClass()->getName();
  5792. if ('Twig_Extension'!== $parentClass &&'Twig\Extension\AbstractExtension'!== $parentClass) {
  5793. @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the \Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).'$name), E_USER_DEPRECATED);
  5794. }
  5795. }
  5796. $extension->initRuntime($this);
  5797. }
  5798. }
  5799. public function hasExtension($class)
  5800. {
  5801. $class ltrim($class,'\\');
  5802. if (!isset($this->extensionsByClass[$class]) && class_exists($classfalse)) {
  5803. $class = new \ReflectionClass($class);
  5804. $class $class->name;
  5805. }
  5806. if (isset($this->extensions[$class])) {
  5807. if ($class !== \get_class($this->extensions[$class])) {
  5808. @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.'$class), E_USER_DEPRECATED);
  5809. }
  5810. return true;
  5811. }
  5812. return isset($this->extensionsByClass[$class]);
  5813. }
  5814. public function addRuntimeLoader(RuntimeLoaderInterface $loader)
  5815. {
  5816. $this->runtimeLoaders[] = $loader;
  5817. }
  5818. public function getExtension($class)
  5819. {
  5820. $class ltrim($class,'\\');
  5821. if (!isset($this->extensionsByClass[$class]) && class_exists($classfalse)) {
  5822. $class = new \ReflectionClass($class);
  5823. $class $class->name;
  5824. }
  5825. if (isset($this->extensions[$class])) {
  5826. if ($class !== \get_class($this->extensions[$class])) {
  5827. @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.'$class), E_USER_DEPRECATED);
  5828. }
  5829. return $this->extensions[$class];
  5830. }
  5831. if (!isset($this->extensionsByClass[$class])) {
  5832. throw new RuntimeError(sprintf('The "%s" extension is not enabled.'$class));
  5833. }
  5834. return $this->extensionsByClass[$class];
  5835. }
  5836. public function getRuntime($class)
  5837. {
  5838. if (isset($this->runtimes[$class])) {
  5839. return $this->runtimes[$class];
  5840. }
  5841. foreach ($this->runtimeLoaders as $loader) {
  5842. if (null !== $runtime $loader->load($class)) {
  5843. return $this->runtimes[$class] = $runtime;
  5844. }
  5845. }
  5846. throw new RuntimeError(sprintf('Unable to load the "%s" runtime.'$class));
  5847. }
  5848. public function addExtension(ExtensionInterface $extension)
  5849. {
  5850. if ($this->extensionInitialized) {
  5851. throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.'$extension->getName()));
  5852. }
  5853. $class = \get_class($extension);
  5854. if ($class !== $extension->getName()) {
  5855. if (isset($this->extensions[$extension->getName()])) {
  5856. unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]);
  5857. @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.'$extension->getName()), E_USER_DEPRECATED);
  5858. }
  5859. }
  5860. $this->lastModifiedExtension 0;
  5861. $this->extensionsByClass[$class] = $extension;
  5862. $this->extensions[$extension->getName()] = $extension;
  5863. $this->updateOptionsHash();
  5864. }
  5865. public function removeExtension($name)
  5866. {
  5867. @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  5868. if ($this->extensionInitialized) {
  5869. throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.'$name));
  5870. }
  5871. $class ltrim($name,'\\');
  5872. if (!isset($this->extensionsByClass[$class]) && class_exists($classfalse)) {
  5873. $class = new \ReflectionClass($class);
  5874. $class $class->name;
  5875. }
  5876. if (isset($this->extensions[$class])) {
  5877. if ($class !== \get_class($this->extensions[$class])) {
  5878. @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.'$class), E_USER_DEPRECATED);
  5879. }
  5880. unset($this->extensions[$class]);
  5881. }
  5882. unset($this->extensions[$class]);
  5883. $this->updateOptionsHash();
  5884. }
  5885. public function setExtensions(array $extensions)
  5886. {
  5887. foreach ($extensions as $extension) {
  5888. $this->addExtension($extension);
  5889. }
  5890. }
  5891. public function getExtensions()
  5892. {
  5893. return $this->extensions;
  5894. }
  5895. public function addTokenParser(TokenParserInterface $parser)
  5896. {
  5897. if ($this->extensionInitialized) {
  5898. throw new \LogicException('Unable to add a token parser as extensions have already been initialized.');
  5899. }
  5900. $this->staging->addTokenParser($parser);
  5901. }
  5902. public function getTokenParsers()
  5903. {
  5904. if (!$this->extensionInitialized) {
  5905. $this->initExtensions();
  5906. }
  5907. return $this->parsers;
  5908. }
  5909. public function getTags()
  5910. {
  5911. $tags = [];
  5912. foreach ($this->getTokenParsers()->getParsers() as $parser) {
  5913. if ($parser instanceof TokenParserInterface) {
  5914. $tags[$parser->getTag()] = $parser;
  5915. }
  5916. }
  5917. return $tags;
  5918. }
  5919. public function addNodeVisitor(NodeVisitorInterface $visitor)
  5920. {
  5921. if ($this->extensionInitialized) {
  5922. throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.');
  5923. }
  5924. $this->staging->addNodeVisitor($visitor);
  5925. }
  5926. public function getNodeVisitors()
  5927. {
  5928. if (!$this->extensionInitialized) {
  5929. $this->initExtensions();
  5930. }
  5931. return $this->visitors;
  5932. }
  5933. public function addFilter($name$filter null)
  5934. {
  5935. if (!$name instanceof TwigFilter && !($filter instanceof TwigFilter || $filter instanceof \Twig_FilterInterface)) {
  5936. throw new \LogicException('A filter must be an instance of \Twig_FilterInterface or \Twig_SimpleFilter.');
  5937. }
  5938. if ($name instanceof TwigFilter) {
  5939. $filter $name;
  5940. $name $filter->getName();
  5941. } else {
  5942. @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".'__METHOD__$name), E_USER_DEPRECATED);
  5943. }
  5944. if ($this->extensionInitialized) {
  5945. throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.'$name));
  5946. }
  5947. $this->staging->addFilter($name$filter);
  5948. }
  5949. public function getFilter($name)
  5950. {
  5951. if (!$this->extensionInitialized) {
  5952. $this->initExtensions();
  5953. }
  5954. if (isset($this->filters[$name])) {
  5955. return $this->filters[$name];
  5956. }
  5957. foreach ($this->filters as $pattern => $filter) {
  5958. $pattern str_replace('\\*','(.*?)'preg_quote($pattern,'#'), $count);
  5959. if ($count) {
  5960. if (preg_match('#^'.$pattern.'$#'$name$matches)) {
  5961. array_shift($matches);
  5962. $filter->setArguments($matches);
  5963. return $filter;
  5964. }
  5965. }
  5966. }
  5967. foreach ($this->filterCallbacks as $callback) {
  5968. if (false !== $filter = \call_user_func($callback$name)) {
  5969. return $filter;
  5970. }
  5971. }
  5972. return false;
  5973. }
  5974. public function registerUndefinedFilterCallback($callable)
  5975. {
  5976. $this->filterCallbacks[] = $callable;
  5977. }
  5978. public function getFilters()
  5979. {
  5980. if (!$this->extensionInitialized) {
  5981. $this->initExtensions();
  5982. }
  5983. return $this->filters;
  5984. }
  5985. public function addTest($name$test null)
  5986. {
  5987. if (!$name instanceof TwigTest && !($test instanceof TwigTest || $test instanceof \Twig_TestInterface)) {
  5988. throw new \LogicException('A test must be an instance of \Twig_TestInterface or \Twig_SimpleTest.');
  5989. }
  5990. if ($name instanceof TwigTest) {
  5991. $test $name;
  5992. $name $test->getName();
  5993. } else {
  5994. @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".'__METHOD__$name), E_USER_DEPRECATED);
  5995. }
  5996. if ($this->extensionInitialized) {
  5997. throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.'$name));
  5998. }
  5999. $this->staging->addTest($name$test);
  6000. }
  6001. public function getTests()
  6002. {
  6003. if (!$this->extensionInitialized) {
  6004. $this->initExtensions();
  6005. }
  6006. return $this->tests;
  6007. }
  6008. public function getTest($name)
  6009. {
  6010. if (!$this->extensionInitialized) {
  6011. $this->initExtensions();
  6012. }
  6013. if (isset($this->tests[$name])) {
  6014. return $this->tests[$name];
  6015. }
  6016. foreach ($this->tests as $pattern => $test) {
  6017. $pattern str_replace('\\*','(.*?)'preg_quote($pattern,'#'), $count);
  6018. if ($count) {
  6019. if (preg_match('#^'.$pattern.'$#'$name$matches)) {
  6020. array_shift($matches);
  6021. $test->setArguments($matches);
  6022. return $test;
  6023. }
  6024. }
  6025. }
  6026. return false;
  6027. }
  6028. public function addFunction($name$function null)
  6029. {
  6030. if (!$name instanceof TwigFunction && !($function instanceof TwigFunction || $function instanceof \Twig_FunctionInterface)) {
  6031. throw new \LogicException('A function must be an instance of \Twig_FunctionInterface or \Twig_SimpleFunction.');
  6032. }
  6033. if ($name instanceof TwigFunction) {
  6034. $function $name;
  6035. $name $function->getName();
  6036. } else {
  6037. @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".'__METHOD__$name), E_USER_DEPRECATED);
  6038. }
  6039. if ($this->extensionInitialized) {
  6040. throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.'$name));
  6041. }
  6042. $this->staging->addFunction($name$function);
  6043. }
  6044. public function getFunction($name)
  6045. {
  6046. if (!$this->extensionInitialized) {
  6047. $this->initExtensions();
  6048. }
  6049. if (isset($this->functions[$name])) {
  6050. return $this->functions[$name];
  6051. }
  6052. foreach ($this->functions as $pattern => $function) {
  6053. $pattern str_replace('\\*','(.*?)'preg_quote($pattern,'#'), $count);
  6054. if ($count) {
  6055. if (preg_match('#^'.$pattern.'$#'$name$matches)) {
  6056. array_shift($matches);
  6057. $function->setArguments($matches);
  6058. return $function;
  6059. }
  6060. }
  6061. }
  6062. foreach ($this->functionCallbacks as $callback) {
  6063. if (false !== $function = \call_user_func($callback$name)) {
  6064. return $function;
  6065. }
  6066. }
  6067. return false;
  6068. }
  6069. public function registerUndefinedFunctionCallback($callable)
  6070. {
  6071. $this->functionCallbacks[] = $callable;
  6072. }
  6073. public function getFunctions()
  6074. {
  6075. if (!$this->extensionInitialized) {
  6076. $this->initExtensions();
  6077. }
  6078. return $this->functions;
  6079. }
  6080. public function addGlobal($name$value)
  6081. {
  6082. if ($this->extensionInitialized || $this->runtimeInitialized) {
  6083. if (null === $this->globals) {
  6084. $this->globals $this->initGlobals();
  6085. }
  6086. if (!\array_key_exists($name$this->globals)) {
  6087. @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.'$name), E_USER_DEPRECATED);
  6088. }
  6089. }
  6090. if ($this->extensionInitialized || $this->runtimeInitialized) {
  6091. $this->globals[$name] = $value;
  6092. } else {
  6093. $this->staging->addGlobal($name$value);
  6094. }
  6095. }
  6096. public function getGlobals()
  6097. {
  6098. if (!$this->runtimeInitialized && !$this->extensionInitialized) {
  6099. return $this->initGlobals();
  6100. }
  6101. if (null === $this->globals) {
  6102. $this->globals $this->initGlobals();
  6103. }
  6104. return $this->globals;
  6105. }
  6106. public function mergeGlobals(array $context)
  6107. {
  6108. foreach ($this->getGlobals() as $key => $value) {
  6109. if (!\array_key_exists($key$context)) {
  6110. $context[$key] = $value;
  6111. }
  6112. }
  6113. return $context;
  6114. }
  6115. public function getUnaryOperators()
  6116. {
  6117. if (!$this->extensionInitialized) {
  6118. $this->initExtensions();
  6119. }
  6120. return $this->unaryOperators;
  6121. }
  6122. public function getBinaryOperators()
  6123. {
  6124. if (!$this->extensionInitialized) {
  6125. $this->initExtensions();
  6126. }
  6127. return $this->binaryOperators;
  6128. }
  6129. public function computeAlternatives($name$items)
  6130. {
  6131. @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.'__METHOD__), E_USER_DEPRECATED);
  6132. return SyntaxError::computeAlternatives($name$items);
  6133. }
  6134. protected function initGlobals()
  6135. {
  6136. $globals = [];
  6137. foreach ($this->extensions as $name => $extension) {
  6138. if (!$extension instanceof GlobalsInterface) {
  6139. $m = new \ReflectionMethod($extension,'getGlobals');
  6140. $parentClass $m->getDeclaringClass()->getName();
  6141. if ('Twig_Extension'!== $parentClass &&'Twig\Extension\AbstractExtension'!== $parentClass) {
  6142. @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.'$name), E_USER_DEPRECATED);
  6143. }
  6144. }
  6145. $extGlob $extension->getGlobals();
  6146. if (!\is_array($extGlob)) {
  6147. throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension)));
  6148. }
  6149. $globals[] = $extGlob;
  6150. }
  6151. $globals[] = $this->staging->getGlobals();
  6152. return \call_user_func_array('array_merge'$globals);
  6153. }
  6154. protected function initExtensions()
  6155. {
  6156. if ($this->extensionInitialized) {
  6157. return;
  6158. }
  6159. $this->parsers = new \Twig_TokenParserBroker([], [], false);
  6160. $this->filters = [];
  6161. $this->functions = [];
  6162. $this->tests = [];
  6163. $this->visitors = [];
  6164. $this->unaryOperators = [];
  6165. $this->binaryOperators = [];
  6166. foreach ($this->extensions as $extension) {
  6167. $this->initExtension($extension);
  6168. }
  6169. $this->initExtension($this->staging);
  6170. $this->extensionInitialized true;
  6171. }
  6172. protected function initExtension(ExtensionInterface $extension)
  6173. {
  6174. foreach ($extension->getFilters() as $name => $filter) {
  6175. if ($filter instanceof TwigFilter) {
  6176. $name $filter->getName();
  6177. } else {
  6178. @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use \Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED);
  6179. }
  6180. $this->filters[$name] = $filter;
  6181. }
  6182. foreach ($extension->getFunctions() as $name => $function) {
  6183. if ($function instanceof TwigFunction) {
  6184. $name $function->getName();
  6185. } else {
  6186. @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use \Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED);
  6187. }
  6188. $this->functions[$name] = $function;
  6189. }
  6190. foreach ($extension->getTests() as $name => $test) {
  6191. if ($test instanceof TwigTest) {
  6192. $name $test->getName();
  6193. } else {
  6194. @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use \Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED);
  6195. }
  6196. $this->tests[$name] = $test;
  6197. }
  6198. foreach ($extension->getTokenParsers() as $parser) {
  6199. if ($parser instanceof TokenParserInterface) {
  6200. $this->parsers->addTokenParser($parser);
  6201. } elseif ($parser instanceof \Twig_TokenParserBrokerInterface) {
  6202. @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.'E_USER_DEPRECATED);
  6203. $this->parsers->addTokenParserBroker($parser);
  6204. } else {
  6205. throw new \LogicException('getTokenParsers() must return an array of \Twig_TokenParserInterface or \Twig_TokenParserBrokerInterface instances.');
  6206. }
  6207. }
  6208. foreach ($extension->getNodeVisitors() as $visitor) {
  6209. $this->visitors[] = $visitor;
  6210. }
  6211. if ($operators $extension->getOperators()) {
  6212. if (!\is_array($operators)) {
  6213. throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), \is_object($operators) ? \get_class($operators) : \gettype($operators).(\is_resource($operators) ?'':'#'.$operators)));
  6214. }
  6215. if (!== \count($operators)) {
  6216. throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
  6217. }
  6218. $this->unaryOperators array_merge($this->unaryOperators$operators[0]);
  6219. $this->binaryOperators array_merge($this->binaryOperators$operators[1]);
  6220. }
  6221. }
  6222. protected function writeCacheFile($file$content)
  6223. {
  6224. $this->cache->write($file$content);
  6225. }
  6226. private function updateOptionsHash()
  6227. {
  6228. $hashParts array_merge(
  6229. array_keys($this->extensions),
  6230. [
  6231. (int) \function_exists('twig_template_get_attributes'),
  6232. PHP_MAJOR_VERSION,
  6233. PHP_MINOR_VERSION,
  6234. self::VERSION,
  6235. (int) $this->debug,
  6236. $this->baseTemplateClass,
  6237. (int) $this->strictVariables,
  6238. ]
  6239. );
  6240. $this->optionsHash implode(':'$hashParts);
  6241. }
  6242. }
  6243. class_alias('Twig\Environment','Twig_Environment');
  6244. }
  6245. namespace Twig\Extension
  6246. {
  6247. use Twig\Environment;
  6248. use Twig\NodeVisitor\NodeVisitorInterface;
  6249. use Twig\TokenParser\TokenParserInterface;
  6250. use Twig\TwigFilter;
  6251. use Twig\TwigFunction;
  6252. use Twig\TwigTest;
  6253. interface ExtensionInterface
  6254. {
  6255. public function initRuntime(Environment $environment);
  6256. public function getTokenParsers();
  6257. public function getNodeVisitors();
  6258. public function getFilters();
  6259. public function getTests();
  6260. public function getFunctions();
  6261. public function getOperators();
  6262. public function getGlobals();
  6263. public function getName();
  6264. }
  6265. class_alias('Twig\Extension\ExtensionInterface','Twig_ExtensionInterface');
  6266. class_exists('Twig\Environment');
  6267. }
  6268. namespace Twig\Extension
  6269. {
  6270. use Twig\Environment;
  6271. abstract class AbstractExtension implements ExtensionInterface
  6272. {
  6273. public function initRuntime(Environment $environment)
  6274. {
  6275. }
  6276. public function getTokenParsers()
  6277. {
  6278. return [];
  6279. }
  6280. public function getNodeVisitors()
  6281. {
  6282. return [];
  6283. }
  6284. public function getFilters()
  6285. {
  6286. return [];
  6287. }
  6288. public function getTests()
  6289. {
  6290. return [];
  6291. }
  6292. public function getFunctions()
  6293. {
  6294. return [];
  6295. }
  6296. public function getOperators()
  6297. {
  6298. return [];
  6299. }
  6300. public function getGlobals()
  6301. {
  6302. return [];
  6303. }
  6304. public function getName()
  6305. {
  6306. return \get_class($this);
  6307. }
  6308. }
  6309. class_alias('Twig\Extension\AbstractExtension','Twig_Extension');
  6310. }
  6311. namespace Twig\Extension {
  6312. use Twig\ExpressionParser;
  6313. use Twig\TokenParser\ApplyTokenParser;
  6314. use Twig\TokenParser\BlockTokenParser;
  6315. use Twig\TokenParser\DeprecatedTokenParser;
  6316. use Twig\TokenParser\DoTokenParser;
  6317. use Twig\TokenParser\EmbedTokenParser;
  6318. use Twig\TokenParser\ExtendsTokenParser;
  6319. use Twig\TokenParser\FilterTokenParser;
  6320. use Twig\TokenParser\FlushTokenParser;
  6321. use Twig\TokenParser\ForTokenParser;
  6322. use Twig\TokenParser\FromTokenParser;
  6323. use Twig\TokenParser\IfTokenParser;
  6324. use Twig\TokenParser\ImportTokenParser;
  6325. use Twig\TokenParser\IncludeTokenParser;
  6326. use Twig\TokenParser\MacroTokenParser;
  6327. use Twig\TokenParser\SetTokenParser;
  6328. use Twig\TokenParser\SpacelessTokenParser;
  6329. use Twig\TokenParser\UseTokenParser;
  6330. use Twig\TokenParser\WithTokenParser;
  6331. use Twig\TwigFilter;
  6332. use Twig\TwigFunction;
  6333. use Twig\TwigTest;
  6334. class CoreExtension extends AbstractExtension
  6335. {
  6336. protected $dateFormats = ['F j, Y H:i','%d days'];
  6337. protected $numberFormat = [0,'.',','];
  6338. protected $timezone null;
  6339. protected $escapers = [];
  6340. public function setEscaper($strategy$callable)
  6341. {
  6342. $this->escapers[$strategy] = $callable;
  6343. }
  6344. public function getEscapers()
  6345. {
  6346. return $this->escapers;
  6347. }
  6348. public function setDateFormat($format null$dateIntervalFormat null)
  6349. {
  6350. if (null !== $format) {
  6351. $this->dateFormats[0] = $format;
  6352. }
  6353. if (null !== $dateIntervalFormat) {
  6354. $this->dateFormats[1] = $dateIntervalFormat;
  6355. }
  6356. }
  6357. public function getDateFormat()
  6358. {
  6359. return $this->dateFormats;
  6360. }
  6361. public function setTimezone($timezone)
  6362. {
  6363. $this->timezone $timezone instanceof \DateTimeZone $timezone : new \DateTimeZone($timezone);
  6364. }
  6365. public function getTimezone()
  6366. {
  6367. if (null === $this->timezone) {
  6368. $this->timezone = new \DateTimeZone(date_default_timezone_get());
  6369. }
  6370. return $this->timezone;
  6371. }
  6372. public function setNumberFormat($decimal$decimalPoint$thousandSep)
  6373. {
  6374. $this->numberFormat = [$decimal$decimalPoint$thousandSep];
  6375. }
  6376. public function getNumberFormat()
  6377. {
  6378. return $this->numberFormat;
  6379. }
  6380. public function getTokenParsers()
  6381. {
  6382. return [
  6383. new ApplyTokenParser(),
  6384. new ForTokenParser(),
  6385. new IfTokenParser(),
  6386. new ExtendsTokenParser(),
  6387. new IncludeTokenParser(),
  6388. new BlockTokenParser(),
  6389. new UseTokenParser(),
  6390. new FilterTokenParser(),
  6391. new MacroTokenParser(),
  6392. new ImportTokenParser(),
  6393. new FromTokenParser(),
  6394. new SetTokenParser(),
  6395. new SpacelessTokenParser(),
  6396. new FlushTokenParser(),
  6397. new DoTokenParser(),
  6398. new EmbedTokenParser(),
  6399. new WithTokenParser(),
  6400. new DeprecatedTokenParser(),
  6401. ];
  6402. }
  6403. public function getFilters()
  6404. {
  6405. $filters = [
  6406. new TwigFilter('date','twig_date_format_filter', ['needs_environment'=> true]),
  6407. new TwigFilter('date_modify','twig_date_modify_filter', ['needs_environment'=> true]),
  6408. new TwigFilter('format','sprintf'),
  6409. new TwigFilter('replace','twig_replace_filter'),
  6410. new TwigFilter('number_format','twig_number_format_filter', ['needs_environment'=> true]),
  6411. new TwigFilter('abs','abs'),
  6412. new TwigFilter('round','twig_round'),
  6413. new TwigFilter('url_encode','twig_urlencode_filter'),
  6414. new TwigFilter('json_encode','twig_jsonencode_filter'),
  6415. new TwigFilter('convert_encoding','twig_convert_encoding'),
  6416. new TwigFilter('title','twig_title_string_filter', ['needs_environment'=> true]),
  6417. new TwigFilter('capitalize','twig_capitalize_string_filter', ['needs_environment'=> true]),
  6418. new TwigFilter('upper','strtoupper'),
  6419. new TwigFilter('lower','strtolower'),
  6420. new TwigFilter('striptags','strip_tags'),
  6421. new TwigFilter('trim','twig_trim_filter'),
  6422. new TwigFilter('nl2br','nl2br', ['pre_escape'=>'html','is_safe'=> ['html']]),
  6423. new TwigFilter('spaceless','twig_spaceless', ['is_safe'=> ['html']]),
  6424. new TwigFilter('join','twig_join_filter'),
  6425. new TwigFilter('split','twig_split_filter', ['needs_environment'=> true]),
  6426. new TwigFilter('sort','twig_sort_filter'),
  6427. new TwigFilter('merge','twig_array_merge'),
  6428. new TwigFilter('batch','twig_array_batch'),
  6429. new TwigFilter('filter','twig_array_filter'),
  6430. new TwigFilter('map','twig_array_map'),
  6431. new TwigFilter('reduce','twig_array_reduce'),
  6432. new TwigFilter('reverse','twig_reverse_filter', ['needs_environment'=> true]),
  6433. new TwigFilter('length','twig_length_filter', ['needs_environment'=> true]),
  6434. new TwigFilter('slice','twig_slice', ['needs_environment'=> true]),
  6435. new TwigFilter('first','twig_first', ['needs_environment'=> true]),
  6436. new TwigFilter('last','twig_last', ['needs_environment'=> true]),
  6437. new TwigFilter('default','_twig_default_filter', ['node_class'=>'\Twig\Node\Expression\Filter\DefaultFilter']),
  6438. new TwigFilter('keys','twig_get_array_keys_filter'),
  6439. new TwigFilter('escape','twig_escape_filter', ['needs_environment'=> true,'is_safe_callback'=>'twig_escape_filter_is_safe']),
  6440. new TwigFilter('e','twig_escape_filter', ['needs_environment'=> true,'is_safe_callback'=>'twig_escape_filter_is_safe']),
  6441. ];
  6442. if (\function_exists('mb_get_info')) {
  6443. $filters[] = new TwigFilter('upper','twig_upper_filter', ['needs_environment'=> true]);
  6444. $filters[] = new TwigFilter('lower','twig_lower_filter', ['needs_environment'=> true]);
  6445. }
  6446. return $filters;
  6447. }
  6448. public function getFunctions()
  6449. {
  6450. return [
  6451. new TwigFunction('max','max'),
  6452. new TwigFunction('min','min'),
  6453. new TwigFunction('range','range'),
  6454. new TwigFunction('constant','twig_constant'),
  6455. new TwigFunction('cycle','twig_cycle'),
  6456. new TwigFunction('random','twig_random', ['needs_environment'=> true]),
  6457. new TwigFunction('date','twig_date_converter', ['needs_environment'=> true]),
  6458. new TwigFunction('include','twig_include', ['needs_environment'=> true,'needs_context'=> true,'is_safe'=> ['all']]),
  6459. new TwigFunction('source','twig_source', ['needs_environment'=> true,'is_safe'=> ['all']]),
  6460. ];
  6461. }
  6462. public function getTests()
  6463. {
  6464. return [
  6465. new TwigTest('even'null, ['node_class'=>'\Twig\Node\Expression\Test\EvenTest']),
  6466. new TwigTest('odd'null, ['node_class'=>'\Twig\Node\Expression\Test\OddTest']),
  6467. new TwigTest('defined'null, ['node_class'=>'\Twig\Node\Expression\Test\DefinedTest']),
  6468. new TwigTest('sameas'null, ['node_class'=>'\Twig\Node\Expression\Test\SameasTest','deprecated'=>'1.21','alternative'=>'same as']),
  6469. new TwigTest('same as'null, ['node_class'=>'\Twig\Node\Expression\Test\SameasTest']),
  6470. new TwigTest('none'null, ['node_class'=>'\Twig\Node\Expression\Test\NullTest']),
  6471. new TwigTest('null'null, ['node_class'=>'\Twig\Node\Expression\Test\NullTest']),
  6472. new TwigTest('divisibleby'null, ['node_class'=>'\Twig\Node\Expression\Test\DivisiblebyTest','deprecated'=>'1.21','alternative'=>'divisible by']),
  6473. new TwigTest('divisible by'null, ['node_class'=>'\Twig\Node\Expression\Test\DivisiblebyTest']),
  6474. new TwigTest('constant'null, ['node_class'=>'\Twig\Node\Expression\Test\ConstantTest']),
  6475. new TwigTest('empty','twig_test_empty'),
  6476. new TwigTest('iterable','twig_test_iterable'),
  6477. ];
  6478. }
  6479. public function getOperators()
  6480. {
  6481. return [
  6482. ['not'=> ['precedence'=> 50,'class'=>'\Twig\Node\Expression\Unary\NotUnary'],'-'=> ['precedence'=> 500,'class'=>'\Twig\Node\Expression\Unary\NegUnary'],'+'=> ['precedence'=> 500,'class'=>'\Twig\Node\Expression\Unary\PosUnary'],
  6483. ],
  6484. ['or'=> ['precedence'=> 10,'class'=>'\Twig\Node\Expression\Binary\OrBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'and'=> ['precedence'=> 15,'class'=>'\Twig\Node\Expression\Binary\AndBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'b-or'=> ['precedence'=> 16,'class'=>'\Twig\Node\Expression\Binary\BitwiseOrBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'b-xor'=> ['precedence'=> 17,'class'=>'\Twig\Node\Expression\Binary\BitwiseXorBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'b-and'=> ['precedence'=> 18,'class'=>'\Twig\Node\Expression\Binary\BitwiseAndBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'=='=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\EqualBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'!='=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\NotEqualBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'<'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\LessBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'>'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\GreaterBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'>='=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\GreaterEqualBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'<='=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\LessEqualBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'not in'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\NotInBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'in'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\InBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'matches'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\MatchesBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'starts with'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\StartsWithBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'ends with'=> ['precedence'=> 20,'class'=>'\Twig\Node\Expression\Binary\EndsWithBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'..'=> ['precedence'=> 25,'class'=>'\Twig\Node\Expression\Binary\RangeBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'+'=> ['precedence'=> 30,'class'=>'\Twig\Node\Expression\Binary\AddBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'-'=> ['precedence'=> 30,'class'=>'\Twig\Node\Expression\Binary\SubBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'~'=> ['precedence'=> 40,'class'=>'\Twig\Node\Expression\Binary\ConcatBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'*'=> ['precedence'=> 60,'class'=>'\Twig\Node\Expression\Binary\MulBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'/'=> ['precedence'=> 60,'class'=>'\Twig\Node\Expression\Binary\DivBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'//'=> ['precedence'=> 60,'class'=>'\Twig\Node\Expression\Binary\FloorDivBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'%'=> ['precedence'=> 60,'class'=>'\Twig\Node\Expression\Binary\ModBinary','associativity'=> ExpressionParser::OPERATOR_LEFT],'is'=> ['precedence'=> 100,'associativity'=> ExpressionParser::OPERATOR_LEFT],'is not'=> ['precedence'=> 100,'associativity'=> ExpressionParser::OPERATOR_LEFT],'**'=> ['precedence'=> 200,'class'=>'\Twig\Node\Expression\Binary\PowerBinary','associativity'=> ExpressionParser::OPERATOR_RIGHT],'??'=> ['precedence'=> 300,'class'=>'\Twig\Node\Expression\NullCoalesceExpression','associativity'=> ExpressionParser::OPERATOR_RIGHT],
  6485. ],
  6486. ];
  6487. }
  6488. public function getName()
  6489. {
  6490. return'core';
  6491. }
  6492. }
  6493. class_alias('Twig\Extension\CoreExtension','Twig_Extension_Core');
  6494. }
  6495. namespace {
  6496. use Twig\Environment;
  6497. use Twig\Error\LoaderError;
  6498. use Twig\Error\RuntimeError;
  6499. use Twig\Loader\SourceContextLoaderInterface;
  6500. use Twig\Markup;
  6501. use Twig\Node\Expression\ConstantExpression;
  6502. use Twig\Node\Node;
  6503. function twig_cycle($values$position)
  6504. {
  6505. if (!\is_array($values) && !$values instanceof \ArrayAccess) {
  6506. return $values;
  6507. }
  6508. return $values[$position % \count($values)];
  6509. }
  6510. function twig_random(Environment $env$values null$max null)
  6511. {
  6512. if (null === $values) {
  6513. return null === $max mt_rand() : mt_rand(0$max);
  6514. }
  6515. if (\is_int($values) || \is_float($values)) {
  6516. if (null === $max) {
  6517. if ($values 0) {
  6518. $max 0;
  6519. $min $values;
  6520. } else {
  6521. $max $values;
  6522. $min 0;
  6523. }
  6524. } else {
  6525. $min $values;
  6526. $max $max;
  6527. }
  6528. return mt_rand($min$max);
  6529. }
  6530. if (\is_string($values)) {
  6531. if (''=== $values) {
  6532. return'';
  6533. }
  6534. if (null !== $charset $env->getCharset()) {
  6535. if ('UTF-8'!== $charset) {
  6536. $values twig_convert_encoding($values,'UTF-8'$charset);
  6537. }
  6538. $values preg_split('/(?<!^)(?!$)/u'$values);
  6539. if ('UTF-8'!== $charset) {
  6540. foreach ($values as $i => $value) {
  6541. $values[$i] = twig_convert_encoding($value$charset,'UTF-8');
  6542. }
  6543. }
  6544. } else {
  6545. return $values[mt_rand(0, \strlen($values) - 1)];
  6546. }
  6547. }
  6548. if (!twig_test_iterable($values)) {
  6549. return $values;
  6550. }
  6551. $values twig_to_array($values);
  6552. if (=== \count($values)) {
  6553. throw new RuntimeError('The random function cannot pick from an empty array.');
  6554. }
  6555. return $values[array_rand($values1)];
  6556. }
  6557. function twig_date_format_filter(Environment $env$date$format null$timezone null)
  6558. {
  6559. if (null === $format) {
  6560. $formats $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat();
  6561. $format $date instanceof \DateInterval $formats[1] : $formats[0];
  6562. }
  6563. if ($date instanceof \DateInterval) {
  6564. return $date->format($format);
  6565. }
  6566. return twig_date_converter($env$date$timezone)->format($format);
  6567. }
  6568. function twig_date_modify_filter(Environment $env$date$modifier)
  6569. {
  6570. $date twig_date_converter($env$datefalse);
  6571. $resultDate $date->modify($modifier);
  6572. return null === $resultDate $date $resultDate;
  6573. }
  6574. function twig_date_converter(Environment $env$date null$timezone null)
  6575. {
  6576. if (false !== $timezone) {
  6577. if (null === $timezone) {
  6578. $timezone $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone();
  6579. } elseif (!$timezone instanceof \DateTimeZone) {
  6580. $timezone = new \DateTimeZone($timezone);
  6581. }
  6582. }
  6583. if ($date instanceof \DateTimeImmutable) {
  6584. return false !== $timezone $date->setTimezone($timezone) : $date;
  6585. }
  6586. if ($date instanceof \DateTime || $date instanceof \DateTimeInterface) {
  6587. $date = clone $date;
  6588. if (false !== $timezone) {
  6589. $date->setTimezone($timezone);
  6590. }
  6591. return $date;
  6592. }
  6593. if (null === $date ||'now'=== $date) {
  6594. return new \DateTime($datefalse !== $timezone $timezone $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
  6595. }
  6596. $asString = (string) $date;
  6597. if (ctype_digit($asString) || (!empty($asString) &&'-'=== $asString[0] && ctype_digit(substr($asString1)))) {
  6598. $date = new \DateTime('@'.$date);
  6599. } else {
  6600. $date = new \DateTime($date$env->getExtension('\Twig\Extension\CoreExtension')->getTimezone());
  6601. }
  6602. if (false !== $timezone) {
  6603. $date->setTimezone($timezone);
  6604. }
  6605. return $date;
  6606. }
  6607. function twig_replace_filter($str$from$to null)
  6608. {
  6609. if (\is_string($from) && \is_string($to)) {
  6610. @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0'E_USER_DEPRECATED);
  6611. return strtr($str$from$to);
  6612. }
  6613. if (!twig_test_iterable($from)) {
  6614. throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
  6615. }
  6616. return strtr($strtwig_to_array($from));
  6617. }
  6618. function twig_round($value$precision 0$method ='common')
  6619. {
  6620. if ('common'== $method) {
  6621. return round($value$precision);
  6622. }
  6623. if ('ceil'!= $method &&'floor'!= $method) {
  6624. throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
  6625. }
  6626. return $method($value pow(10$precision)) / pow(10$precision);
  6627. }
  6628. function twig_number_format_filter(Environment $env$number$decimal null$decimalPoint null$thousandSep null)
  6629. {
  6630. $defaults $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat();
  6631. if (null === $decimal) {
  6632. $decimal $defaults[0];
  6633. }
  6634. if (null === $decimalPoint) {
  6635. $decimalPoint $defaults[1];
  6636. }
  6637. if (null === $thousandSep) {
  6638. $thousandSep $defaults[2];
  6639. }
  6640. return number_format((float) $number$decimal$decimalPoint$thousandSep);
  6641. }
  6642. function twig_urlencode_filter($url)
  6643. {
  6644. if (\is_array($url)) {
  6645. if (\defined('PHP_QUERY_RFC3986')) {
  6646. return http_build_query($url,'','&'PHP_QUERY_RFC3986);
  6647. }
  6648. return http_build_query($url,'','&');
  6649. }
  6650. return rawurlencode($url);
  6651. }
  6652. function twig_jsonencode_filter($value$options 0)
  6653. {
  6654. if ($value instanceof Markup) {
  6655. $value = (string) $value;
  6656. } elseif (\is_array($value)) {
  6657. array_walk_recursive($value,'_twig_markup2string');
  6658. }
  6659. return json_encode($value$options);
  6660. }
  6661. function _twig_markup2string(&$value)
  6662. {
  6663. if ($value instanceof Markup) {
  6664. $value = (string) $value;
  6665. }
  6666. }
  6667. function twig_array_merge($arr1$arr2)
  6668. {
  6669. if (!twig_test_iterable($arr1)) {
  6670. throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1)));
  6671. }
  6672. if (!twig_test_iterable($arr2)) {
  6673. throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2)));
  6674. }
  6675. return array_merge(twig_to_array($arr1), twig_to_array($arr2));
  6676. }
  6677. function twig_slice(Environment $env$item$start$length null$preserveKeys false)
  6678. {
  6679. if ($item instanceof \Traversable) {
  6680. while ($item instanceof \IteratorAggregate) {
  6681. $item $item->getIterator();
  6682. }
  6683. if ($start >= && $length >= && $item instanceof \Iterator) {
  6684. try {
  6685. return iterator_to_array(new \LimitIterator($item$startnull === $length ? -$length), $preserveKeys);
  6686. } catch (\OutOfBoundsException $e) {
  6687. return [];
  6688. }
  6689. }
  6690. $item iterator_to_array($item$preserveKeys);
  6691. }
  6692. if (\is_array($item)) {
  6693. return \array_slice($item$start$length$preserveKeys);
  6694. }
  6695. $item = (string) $item;
  6696. if (\function_exists('mb_get_info') && null !== $charset $env->getCharset()) {
  6697. return (string) mb_substr($item$startnull === $length mb_strlen($item$charset) - $start $length$charset);
  6698. }
  6699. return (string) (null === $length substr($item$start) : substr($item$start$length));
  6700. }
  6701. function twig_first(Environment $env$item)
  6702. {
  6703. $elements twig_slice($env$item01false);
  6704. return \is_string($elements) ? $elements current($elements);
  6705. }
  6706. function twig_last(Environment $env$item)
  6707. {
  6708. $elements twig_slice($env$item, -11false);
  6709. return \is_string($elements) ? $elements current($elements);
  6710. }
  6711. function twig_join_filter($value$glue =''$and null)
  6712. {
  6713. if (!twig_test_iterable($value)) {
  6714. $value = (array) $value;
  6715. }
  6716. $value twig_to_array($valuefalse);
  6717. if (=== \count($value)) {
  6718. return'';
  6719. }
  6720. if (null === $and || $and === $glue) {
  6721. return implode($glue$value);
  6722. }
  6723. if (=== \count($value)) {
  6724. return $value[0];
  6725. }
  6726. return implode($glue, \array_slice($value0, -1)).$and.$value[\count($value) - 1];
  6727. }
  6728. function twig_split_filter(Environment $env$value$delimiter$limit null)
  6729. {
  6730. if (\strlen($delimiter) > 0) {
  6731. return null === $limit explode($delimiter$value) : explode($delimiter$value$limit);
  6732. }
  6733. if (!\function_exists('mb_get_info') || null === $charset $env->getCharset()) {
  6734. return str_split($valuenull === $limit $limit);
  6735. }
  6736. if ($limit <= 1) {
  6737. return preg_split('/(?<!^)(?!$)/u'$value);
  6738. }
  6739. $length mb_strlen($value$charset);
  6740. if ($length $limit) {
  6741. return [$value];
  6742. }
  6743. $r = [];
  6744. for ($i 0$i $length$i += $limit) {
  6745. $r[] = mb_substr($value$i$limit$charset);
  6746. }
  6747. return $r;
  6748. }
  6749. function _twig_default_filter($value$default ='')
  6750. {
  6751. if (twig_test_empty($value)) {
  6752. return $default;
  6753. }
  6754. return $value;
  6755. }
  6756. function twig_get_array_keys_filter($array)
  6757. {
  6758. if ($array instanceof \Traversable) {
  6759. while ($array instanceof \IteratorAggregate) {
  6760. $array $array->getIterator();
  6761. }
  6762. if ($array instanceof \Iterator) {
  6763. $keys = [];
  6764. $array->rewind();
  6765. while ($array->valid()) {
  6766. $keys[] = $array->key();
  6767. $array->next();
  6768. }
  6769. return $keys;
  6770. }
  6771. $keys = [];
  6772. foreach ($array as $key => $item) {
  6773. $keys[] = $key;
  6774. }
  6775. return $keys;
  6776. }
  6777. if (!\is_array($array)) {
  6778. return [];
  6779. }
  6780. return array_keys($array);
  6781. }
  6782. function twig_reverse_filter(Environment $env$item$preserveKeys false)
  6783. {
  6784. if ($item instanceof \Traversable) {
  6785. return array_reverse(iterator_to_array($item), $preserveKeys);
  6786. }
  6787. if (\is_array($item)) {
  6788. return array_reverse($item$preserveKeys);
  6789. }
  6790. if (null !== $charset $env->getCharset()) {
  6791. $string = (string) $item;
  6792. if ('UTF-8'!== $charset) {
  6793. $item twig_convert_encoding($string,'UTF-8'$charset);
  6794. }
  6795. preg_match_all('/./us'$item$matches);
  6796. $string implode(''array_reverse($matches[0]));
  6797. if ('UTF-8'!== $charset) {
  6798. $string twig_convert_encoding($string$charset,'UTF-8');
  6799. }
  6800. return $string;
  6801. }
  6802. return strrev((string) $item);
  6803. }
  6804. function twig_sort_filter($array)
  6805. {
  6806. if ($array instanceof \Traversable) {
  6807. $array iterator_to_array($array);
  6808. } elseif (!\is_array($array)) {
  6809. throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array)));
  6810. }
  6811. asort($array);
  6812. return $array;
  6813. }
  6814. function twig_in_filter($value$compare)
  6815. {
  6816. if ($value instanceof Markup) {
  6817. $value = (string) $value;
  6818. }
  6819. if ($compare instanceof Markup) {
  6820. $compare = (string) $compare;
  6821. }
  6822. if (\is_array($compare)) {
  6823. return \in_array($value$compare, \is_object($value) || \is_resource($value));
  6824. } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) {
  6825. return''=== $value || false !== strpos($compare, (string) $value);
  6826. } elseif ($compare instanceof \Traversable) {
  6827. if (\is_object($value) || \is_resource($value)) {
  6828. foreach ($compare as $item) {
  6829. if ($item === $value) {
  6830. return true;
  6831. }
  6832. }
  6833. } else {
  6834. foreach ($compare as $item) {
  6835. if ($item == $value) {
  6836. return true;
  6837. }
  6838. }
  6839. }
  6840. return false;
  6841. }
  6842. return false;
  6843. }
  6844. function twig_trim_filter($string$characterMask null$side ='both')
  6845. {
  6846. if (null === $characterMask) {
  6847. $characterMask =" \t\n\r\0\x0B";
  6848. }
  6849. switch ($side) {
  6850. case'both':
  6851. return trim($string$characterMask);
  6852. case'left':
  6853. return ltrim($string$characterMask);
  6854. case'right':
  6855. return rtrim($string$characterMask);
  6856. default:
  6857. throw new RuntimeError('Trimming side must be "left", "right" or "both".');
  6858. }
  6859. }
  6860. function twig_spaceless($content)
  6861. {
  6862. return trim(preg_replace('/>\s+</','><'$content));
  6863. }
  6864. function twig_escape_filter(Environment $env$string$strategy ='html'$charset null$autoescape false)
  6865. {
  6866. if ($autoescape && $string instanceof Markup) {
  6867. return $string;
  6868. }
  6869. if (!\is_string($string)) {
  6870. if (\is_object($string) && method_exists($string,'__toString')) {
  6871. $string = (string) $string;
  6872. } elseif (\in_array($strategy, ['html','js','css','html_attr','url'])) {
  6873. return $string;
  6874. }
  6875. }
  6876. if (''=== $string) {
  6877. return'';
  6878. }
  6879. if (null === $charset) {
  6880. $charset $env->getCharset();
  6881. }
  6882. switch ($strategy) {
  6883. case'html':
  6884. static $htmlspecialcharsCharsets = ['ISO-8859-1'=> true,'ISO8859-1'=> true,'ISO-8859-15'=> true,'ISO8859-15'=> true,'utf-8'=> true,'UTF-8'=> true,'CP866'=> true,'IBM866'=> true,'866'=> true,'CP1251'=> true,'WINDOWS-1251'=> true,'WIN-1251'=> true,'1251'=> true,'CP1252'=> true,'WINDOWS-1252'=> true,'1252'=> true,'KOI8-R'=> true,'KOI8-RU'=> true,'KOI8R'=> true,'BIG5'=> true,'950'=> true,'GB2312'=> true,'936'=> true,'BIG5-HKSCS'=> true,'SHIFT_JIS'=> true,'SJIS'=> true,'932'=> true,'EUC-JP'=> true,'EUCJP'=> true,'ISO8859-5'=> true,'ISO-8859-5'=> true,'MACROMAN'=> true,
  6885. ];
  6886. if (isset($htmlspecialcharsCharsets[$charset])) {
  6887. return htmlspecialchars($stringENT_QUOTES ENT_SUBSTITUTE$charset);
  6888. }
  6889. if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) {
  6890. $htmlspecialcharsCharsets[$charset] = true;
  6891. return htmlspecialchars($stringENT_QUOTES ENT_SUBSTITUTE$charset);
  6892. }
  6893. $string twig_convert_encoding($string,'UTF-8'$charset);
  6894. $string htmlspecialchars($stringENT_QUOTES ENT_SUBSTITUTE,'UTF-8');
  6895. return twig_convert_encoding($string$charset,'UTF-8');
  6896. case'js':
  6897. if ('UTF-8'!== $charset) {
  6898. $string twig_convert_encoding($string,'UTF-8'$charset);
  6899. }
  6900. if (!preg_match('//u'$string)) {
  6901. throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
  6902. }
  6903. $string preg_replace_callback('#[^a-zA-Z0-9,\._]#Su','_twig_escape_js_callback'$string);
  6904. if ('UTF-8'!== $charset) {
  6905. $string twig_convert_encoding($string$charset,'UTF-8');
  6906. }
  6907. return $string;
  6908. case'css':
  6909. if ('UTF-8'!== $charset) {
  6910. $string twig_convert_encoding($string,'UTF-8'$charset);
  6911. }
  6912. if (!preg_match('//u'$string)) {
  6913. throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
  6914. }
  6915. $string preg_replace_callback('#[^a-zA-Z0-9]#Su','_twig_escape_css_callback'$string);
  6916. if ('UTF-8'!== $charset) {
  6917. $string twig_convert_encoding($string$charset,'UTF-8');
  6918. }
  6919. return $string;
  6920. case'html_attr':
  6921. if ('UTF-8'!== $charset) {
  6922. $string twig_convert_encoding($string,'UTF-8'$charset);
  6923. }
  6924. if (!preg_match('//u'$string)) {
  6925. throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
  6926. }
  6927. $string preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su','_twig_escape_html_attr_callback'$string);
  6928. if ('UTF-8'!== $charset) {
  6929. $string twig_convert_encoding($string$charset,'UTF-8');
  6930. }
  6931. return $string;
  6932. case'url':
  6933. return rawurlencode($string);
  6934. default:
  6935. static $escapers;
  6936. if (null === $escapers) {
  6937. $escapers $env->getExtension('\Twig\Extension\CoreExtension')->getEscapers();
  6938. }
  6939. if (isset($escapers[$strategy])) {
  6940. return \call_user_func($escapers[$strategy], $env$string$charset);
  6941. }
  6942. $validStrategies implode(', 'array_merge(['html','js','url','css','html_attr'], array_keys($escapers)));
  6943. throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).'$strategy$validStrategies));
  6944. }
  6945. }
  6946. function twig_escape_filter_is_safe(Node $filterArgs)
  6947. {
  6948. foreach ($filterArgs as $arg) {
  6949. if ($arg instanceof ConstantExpression) {
  6950. return [$arg->getAttribute('value')];
  6951. }
  6952. return [];
  6953. }
  6954. return ['html'];
  6955. }
  6956. if (\function_exists('mb_convert_encoding')) {
  6957. function twig_convert_encoding($string$to$from)
  6958. {
  6959. return mb_convert_encoding($string$to$from);
  6960. }
  6961. } elseif (\function_exists('iconv')) {
  6962. function twig_convert_encoding($string$to$from)
  6963. {
  6964. return iconv($from$to$string);
  6965. }
  6966. } else {
  6967. function twig_convert_encoding($string$to$from)
  6968. {
  6969. throw new RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
  6970. }
  6971. }
  6972. if (\function_exists('mb_ord')) {
  6973. function twig_ord($string)
  6974. {
  6975. return mb_ord($string,'UTF-8');
  6976. }
  6977. } else {
  6978. function twig_ord($string)
  6979. {
  6980. $code = ($string unpack('C*'substr($string04))) ? $string[1] : 0;
  6981. if (0xF0 <= $code) {
  6982. return (($code 0xF0) << 18) + (($string[2] - 0x80) << 12) + (($string[3] - 0x80) << 6) + $string[4] - 0x80;
  6983. }
  6984. if (0xE0 <= $code) {
  6985. return (($code 0xE0) << 12) + (($string[2] - 0x80) << 6) + $string[3] - 0x80;
  6986. }
  6987. if (0xC0 <= $code) {
  6988. return (($code 0xC0) << 6) + $string[2] - 0x80;
  6989. }
  6990. return $code;
  6991. }
  6992. }
  6993. function _twig_escape_js_callback($matches)
  6994. {
  6995. $char $matches[0];
  6996. static $shortMap = ['\\'=>'\\\\','/'=>'\\/',"\x08"=>'\b',"\x0C"=>'\f',"\x0A"=>'\n',"\x0D"=>'\r',"\x09"=>'\t',
  6997. ];
  6998. if (isset($shortMap[$char])) {
  6999. return $shortMap[$char];
  7000. }
  7001. $char twig_convert_encoding($char,'UTF-16BE','UTF-8');
  7002. $char strtoupper(bin2hex($char));
  7003. if (>= \strlen($char)) {
  7004. return sprintf('\u%04s'$char);
  7005. }
  7006. return sprintf('\u%04s\u%04s'substr($char0, -4), substr($char, -4));
  7007. }
  7008. function _twig_escape_css_callback($matches)
  7009. {
  7010. $char $matches[0];
  7011. return sprintf('\\%X '=== \strlen($char) ? \ord($char) : twig_ord($char));
  7012. }
  7013. function _twig_escape_html_attr_callback($matches)
  7014. {
  7015. $chr $matches[0];
  7016. $ord = \ord($chr);
  7017. if (($ord <= 0x1f &&"\t"!= $chr &&"\n"!= $chr &&"\r"!= $chr) || ($ord >= 0x7f && $ord <= 0x9f)) {
  7018. return'&#xFFFD;';
  7019. }
  7020. if (== \strlen($chr)) {
  7021. static $entityMap = [
  7022. 34 =>'&quot;',
  7023. 38 =>'&amp;',
  7024. 60 =>'&lt;',
  7025. 62 =>'&gt;',
  7026. ];
  7027. if (isset($entityMap[$ord])) {
  7028. return $entityMap[$ord];
  7029. }
  7030. return sprintf('&#x%02X;'$ord);
  7031. }
  7032. return sprintf('&#x%04X;'twig_ord($chr));
  7033. }
  7034. if (\function_exists('mb_get_info')) {
  7035. function twig_length_filter(Environment $env$thing)
  7036. {
  7037. if (null === $thing) {
  7038. return 0;
  7039. }
  7040. if (is_scalar($thing)) {
  7041. return mb_strlen($thing$env->getCharset());
  7042. }
  7043. if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
  7044. return \count($thing);
  7045. }
  7046. if ($thing instanceof \Traversable) {
  7047. return iterator_count($thing);
  7048. }
  7049. if (\is_object($thing) && method_exists($thing,'__toString')) {
  7050. return mb_strlen((string) $thing$env->getCharset());
  7051. }
  7052. return 1;
  7053. }
  7054. function twig_upper_filter(Environment $env$string)
  7055. {
  7056. if (null !== $charset $env->getCharset()) {
  7057. return mb_strtoupper($string$charset);
  7058. }
  7059. return strtoupper($string);
  7060. }
  7061. function twig_lower_filter(Environment $env$string)
  7062. {
  7063. if (null !== $charset $env->getCharset()) {
  7064. return mb_strtolower($string$charset);
  7065. }
  7066. return strtolower($string);
  7067. }
  7068. function twig_title_string_filter(Environment $env$string)
  7069. {
  7070. if (null !== $charset $env->getCharset()) {
  7071. return mb_convert_case($stringMB_CASE_TITLE$charset);
  7072. }
  7073. return ucwords(strtolower($string));
  7074. }
  7075. function twig_capitalize_string_filter(Environment $env$string)
  7076. {
  7077. if (null !== $charset $env->getCharset()) {
  7078. return mb_strtoupper(mb_substr($string01$charset), $charset).mb_strtolower(mb_substr($string1mb_strlen($string$charset), $charset), $charset);
  7079. }
  7080. return ucfirst(strtolower($string));
  7081. }
  7082. }
  7083. else {
  7084. function twig_length_filter(Environment $env$thing)
  7085. {
  7086. if (null === $thing) {
  7087. return 0;
  7088. }
  7089. if (is_scalar($thing)) {
  7090. return \strlen($thing);
  7091. }
  7092. if ($thing instanceof \SimpleXMLElement) {
  7093. return \count($thing);
  7094. }
  7095. if (\is_object($thing) && method_exists($thing,'__toString') && !$thing instanceof \Countable) {
  7096. return \strlen((string) $thing);
  7097. }
  7098. if ($thing instanceof \Countable || \is_array($thing)) {
  7099. return \count($thing);
  7100. }
  7101. if ($thing instanceof \IteratorAggregate) {
  7102. return iterator_count($thing);
  7103. }
  7104. return 1;
  7105. }
  7106. function twig_title_string_filter(Environment $env$string)
  7107. {
  7108. return ucwords(strtolower($string));
  7109. }
  7110. function twig_capitalize_string_filter(Environment $env$string)
  7111. {
  7112. return ucfirst(strtolower($string));
  7113. }
  7114. }
  7115. function twig_ensure_traversable($seq)
  7116. {
  7117. if ($seq instanceof \Traversable || \is_array($seq)) {
  7118. return $seq;
  7119. }
  7120. return [];
  7121. }
  7122. function twig_to_array($seq$preserveKeys true)
  7123. {
  7124. if ($seq instanceof \Traversable) {
  7125. return iterator_to_array($seq$preserveKeys);
  7126. }
  7127. if (!\is_array($seq)) {
  7128. return $seq;
  7129. }
  7130. return $preserveKeys $seq array_values($seq);
  7131. }
  7132. function twig_test_empty($value)
  7133. {
  7134. if ($value instanceof \Countable) {
  7135. return == \count($value);
  7136. }
  7137. if ($value instanceof \Traversable) {
  7138. return !iterator_count($value);
  7139. }
  7140. if (\is_object($value) && method_exists($value,'__toString')) {
  7141. return''=== (string) $value;
  7142. }
  7143. return''=== $value || false === $value || null === $value || [] === $value;
  7144. }
  7145. function twig_test_iterable($value)
  7146. {
  7147. return $value instanceof \Traversable || \is_array($value);
  7148. }
  7149. function twig_include(Environment $env$context$template$variables = [], $withContext true$ignoreMissing false$sandboxed false)
  7150. {
  7151. $alreadySandboxed false;
  7152. $sandbox null;
  7153. if ($withContext) {
  7154. $variables array_merge($context$variables);
  7155. }
  7156. if ($isSandboxed $sandboxed && $env->hasExtension('\Twig\Extension\SandboxExtension')) {
  7157. $sandbox $env->getExtension('\Twig\Extension\SandboxExtension');
  7158. if (!$alreadySandboxed $sandbox->isSandboxed()) {
  7159. $sandbox->enableSandbox();
  7160. }
  7161. }
  7162. $loaded null;
  7163. try {
  7164. $loaded $env->resolveTemplate($template);
  7165. } catch (LoaderError $e) {
  7166. if (!$ignoreMissing) {
  7167. if ($isSandboxed && !$alreadySandboxed) {
  7168. $sandbox->disableSandbox();
  7169. }
  7170. throw $e;
  7171. }
  7172. } catch (\Throwable $e) {
  7173. if ($isSandboxed && !$alreadySandboxed) {
  7174. $sandbox->disableSandbox();
  7175. }
  7176. throw $e;
  7177. } catch (\Exception $e) {
  7178. if ($isSandboxed && !$alreadySandboxed) {
  7179. $sandbox->disableSandbox();
  7180. }
  7181. throw $e;
  7182. }
  7183. try {
  7184. $ret $loaded $loaded->render($variables) :'';
  7185. } catch (\Exception $e) {
  7186. if ($isSandboxed && !$alreadySandboxed) {
  7187. $sandbox->disableSandbox();
  7188. }
  7189. throw $e;
  7190. }
  7191. if ($isSandboxed && !$alreadySandboxed) {
  7192. $sandbox->disableSandbox();
  7193. }
  7194. return $ret;
  7195. }
  7196. function twig_source(Environment $env$name$ignoreMissing false)
  7197. {
  7198. $loader $env->getLoader();
  7199. try {
  7200. if (!$loader instanceof SourceContextLoaderInterface) {
  7201. return $loader->getSource($name);
  7202. } else {
  7203. return $loader->getSourceContext($name)->getCode();
  7204. }
  7205. } catch (LoaderError $e) {
  7206. if (!$ignoreMissing) {
  7207. throw $e;
  7208. }
  7209. }
  7210. }
  7211. function twig_constant($constant$object null)
  7212. {
  7213. if (null !== $object) {
  7214. $constant = \get_class($object).'::'.$constant;
  7215. }
  7216. return \constant($constant);
  7217. }
  7218. function twig_constant_is_defined($constant$object null)
  7219. {
  7220. if (null !== $object) {
  7221. $constant = \get_class($object).'::'.$constant;
  7222. }
  7223. return \defined($constant);
  7224. }
  7225. function twig_array_batch($items$size$fill null$preserveKeys true)
  7226. {
  7227. if (!twig_test_iterable($items)) {
  7228. throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
  7229. }
  7230. $size ceil($size);
  7231. $result array_chunk(twig_to_array($items$preserveKeys), $size$preserveKeys);
  7232. if (null !== $fill && $result) {
  7233. $last = \count($result) - 1;
  7234. if ($fillCount $size - \count($result[$last])) {
  7235. for ($i 0$i $fillCount; ++$i) {
  7236. $result[$last][] = $fill;
  7237. }
  7238. }
  7239. }
  7240. return $result;
  7241. }
  7242. function twig_array_filter($array$arrow)
  7243. {
  7244. if (\is_array($array)) {
  7245. if (\PHP_VERSION_ID >= 50600) {
  7246. return array_filter($array$arrow, \ARRAY_FILTER_USE_BOTH);
  7247. }
  7248. return array_filter($array$arrow);
  7249. }
  7250. return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
  7251. }
  7252. function twig_array_map($array$arrow)
  7253. {
  7254. $r = [];
  7255. foreach ($array as $k => $v) {
  7256. $r[$k] = $arrow($v$k);
  7257. }
  7258. return $r;
  7259. }
  7260. function twig_array_reduce($array$arrow$initial null)
  7261. {
  7262. if (!\is_array($array)) {
  7263. $array iterator_to_array($array);
  7264. }
  7265. return array_reduce($array$arrow$initial);
  7266. }
  7267. }
  7268. namespace Twig\Extension {
  7269. use Twig\NodeVisitor\EscaperNodeVisitor;
  7270. use Twig\TokenParser\AutoEscapeTokenParser;
  7271. use Twig\TwigFilter;
  7272. class EscaperExtension extends AbstractExtension
  7273. {
  7274. protected $defaultStrategy;
  7275. public function __construct($defaultStrategy ='html')
  7276. {
  7277. $this->setDefaultStrategy($defaultStrategy);
  7278. }
  7279. public function getTokenParsers()
  7280. {
  7281. return [new AutoEscapeTokenParser()];
  7282. }
  7283. public function getNodeVisitors()
  7284. {
  7285. return [new EscaperNodeVisitor()];
  7286. }
  7287. public function getFilters()
  7288. {
  7289. return [
  7290. new TwigFilter('raw','twig_raw_filter', ['is_safe'=> ['all']]),
  7291. ];
  7292. }
  7293. public function setDefaultStrategy($defaultStrategy)
  7294. {
  7295. if (true === $defaultStrategy) {
  7296. @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.'E_USER_DEPRECATED);
  7297. $defaultStrategy ='html';
  7298. }
  7299. if ('filename'=== $defaultStrategy) {
  7300. @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.'E_USER_DEPRECATED);
  7301. $defaultStrategy ='name';
  7302. }
  7303. if ('name'=== $defaultStrategy) {
  7304. $defaultStrategy = ['\Twig\FileExtensionEscapingStrategy','guess'];
  7305. }
  7306. $this->defaultStrategy $defaultStrategy;
  7307. }
  7308. public function getDefaultStrategy($name)
  7309. {
  7310. if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
  7311. return \call_user_func($this->defaultStrategy$name);
  7312. }
  7313. return $this->defaultStrategy;
  7314. }
  7315. public function getName()
  7316. {
  7317. return'escaper';
  7318. }
  7319. }
  7320. class_alias('Twig\Extension\EscaperExtension','Twig_Extension_Escaper');
  7321. }
  7322. namespace {
  7323. function twig_raw_filter($string)
  7324. {
  7325. return $string;
  7326. }
  7327. }
  7328. namespace Twig\Extension
  7329. {
  7330. use Twig\NodeVisitor\OptimizerNodeVisitor;
  7331. class OptimizerExtension extends AbstractExtension
  7332. {
  7333. protected $optimizers;
  7334. public function __construct($optimizers = -1)
  7335. {
  7336. $this->optimizers $optimizers;
  7337. }
  7338. public function getNodeVisitors()
  7339. {
  7340. return [new OptimizerNodeVisitor($this->optimizers)];
  7341. }
  7342. public function getName()
  7343. {
  7344. return'optimizer';
  7345. }
  7346. }
  7347. class_alias('Twig\Extension\OptimizerExtension','Twig_Extension_Optimizer');
  7348. }
  7349. namespace Twig\Loader
  7350. {
  7351. use Twig\Error\LoaderError;
  7352. interface LoaderInterface
  7353. {
  7354. public function getSource($name);
  7355. public function getCacheKey($name);
  7356. public function isFresh($name$time);
  7357. }
  7358. class_alias('Twig\Loader\LoaderInterface','Twig_LoaderInterface');
  7359. }
  7360. namespace Twig
  7361. {
  7362. class Markup implements \Countable
  7363. {
  7364. protected $content;
  7365. protected $charset;
  7366. public function __construct($content$charset)
  7367. {
  7368. $this->content = (string) $content;
  7369. $this->charset $charset;
  7370. }
  7371. public function __toString()
  7372. {
  7373. return $this->content;
  7374. }
  7375. public function count()
  7376. {
  7377. return \function_exists('mb_get_info') ? mb_strlen($this->content$this->charset) : \strlen($this->content);
  7378. }
  7379. }
  7380. class_alias('Twig\Markup','Twig_Markup');
  7381. }
  7382. namespace
  7383. {
  7384. use Twig\Environment;
  7385. interface Twig_TemplateInterface
  7386. {
  7387. const ANY_CALL ='any';
  7388. const ARRAY_CALL ='array';
  7389. const METHOD_CALL ='method';
  7390. public function render(array $context);
  7391. public function display(array $context, array $blocks = []);
  7392. public function getEnvironment();
  7393. }
  7394. }
  7395. namespace Twig
  7396. {
  7397. use Twig\Error\Error;
  7398. use Twig\Error\LoaderError;
  7399. use Twig\Error\RuntimeError;
  7400. abstract class Template implements \Twig_TemplateInterface
  7401. {
  7402. protected static $cache = [];
  7403. protected $parent;
  7404. protected $parents = [];
  7405. protected $env;
  7406. protected $blocks = [];
  7407. protected $traits = [];
  7408. protected $sandbox;
  7409. public function __construct(Environment $env)
  7410. {
  7411. $this->env $env;
  7412. }
  7413. public function __toString()
  7414. {
  7415. return $this->getTemplateName();
  7416. }
  7417. abstract public function getTemplateName();
  7418. public function getDebugInfo()
  7419. {
  7420. return [];
  7421. }
  7422. public function getSource()
  7423. {
  7424. @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.'E_USER_DEPRECATED);
  7425. return'';
  7426. }
  7427. public function getSourceContext()
  7428. {
  7429. return new Source(''$this->getTemplateName());
  7430. }
  7431. public function getEnvironment()
  7432. {
  7433. @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.'E_USER_DEPRECATED);
  7434. return $this->env;
  7435. }
  7436. public function getParent(array $context)
  7437. {
  7438. if (null !== $this->parent) {
  7439. return $this->parent;
  7440. }
  7441. try {
  7442. $parent $this->doGetParent($context);
  7443. if (false === $parent) {
  7444. return false;
  7445. }
  7446. if ($parent instanceof self || $parent instanceof TemplateWrapper) {
  7447. return $this->parents[$parent->getSourceContext()->getName()] = $parent;
  7448. }
  7449. if (!isset($this->parents[$parent])) {
  7450. $this->parents[$parent] = $this->loadTemplate($parent);
  7451. }
  7452. } catch (LoaderError $e) {
  7453. $e->setSourceContext(null);
  7454. $e->guess();
  7455. throw $e;
  7456. }
  7457. return $this->parents[$parent];
  7458. }
  7459. protected function doGetParent(array $context)
  7460. {
  7461. return false;
  7462. }
  7463. public function isTraitable()
  7464. {
  7465. return true;
  7466. }
  7467. public function displayParentBlock($name, array $context, array $blocks = [])
  7468. {
  7469. $name = (string) $name;
  7470. if (isset($this->traits[$name])) {
  7471. $this->traits[$name][0]->displayBlock($name$context$blocksfalse);
  7472. } elseif (false !== $parent $this->getParent($context)) {
  7473. $parent->displayBlock($name$context$blocksfalse);
  7474. } else {
  7475. throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.'$name), -1$this->getSourceContext());
  7476. }
  7477. }
  7478. public function displayBlock($name, array $context, array $blocks = [], $useBlocks true)
  7479. {
  7480. $name = (string) $name;
  7481. if ($useBlocks && isset($blocks[$name])) {
  7482. $template $blocks[$name][0];
  7483. $block $blocks[$name][1];
  7484. } elseif (isset($this->blocks[$name])) {
  7485. $template $this->blocks[$name][0];
  7486. $block $this->blocks[$name][1];
  7487. } else {
  7488. $template null;
  7489. $block null;
  7490. }
  7491. if (null !== $template && !$template instanceof self) {
  7492. throw new \LogicException('A block must be a method on a \Twig\Template instance.');
  7493. }
  7494. if (null !== $template) {
  7495. try {
  7496. $template->$block($context$blocks);
  7497. } catch (Error $e) {
  7498. if (!$e->getSourceContext()) {
  7499. $e->setSourceContext($template->getSourceContext());
  7500. }
  7501. if (-=== $e->getTemplateLine()) {
  7502. $e->guess();
  7503. }
  7504. throw $e;
  7505. } catch (\Exception $e) {
  7506. $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").'$e->getMessage()), -1$template->getSourceContext(), $e);
  7507. $e->guess();
  7508. throw $e;
  7509. }
  7510. } elseif (false !== $parent $this->getParent($context)) {
  7511. $parent->displayBlock($name$contextarray_merge($this->blocks$blocks), false);
  7512. } else {
  7513. @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.'$name$this->getTemplateName(), $name), E_USER_DEPRECATED);
  7514. }
  7515. }
  7516. public function renderParentBlock($name, array $context, array $blocks = [])
  7517. {
  7518. if ($this->env->isDebug()) {
  7519. ob_start();
  7520. } else {
  7521. ob_start(function () { return''; });
  7522. }
  7523. $this->displayParentBlock($name$context$blocks);
  7524. return ob_get_clean();
  7525. }
  7526. public function renderBlock($name, array $context, array $blocks = [], $useBlocks true)
  7527. {
  7528. if ($this->env->isDebug()) {
  7529. ob_start();
  7530. } else {
  7531. ob_start(function () { return''; });
  7532. }
  7533. $this->displayBlock($name$context$blocks$useBlocks);
  7534. return ob_get_clean();
  7535. }
  7536. public function hasBlock($name, array $context null, array $blocks = [])
  7537. {
  7538. if (null === $context) {
  7539. @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.'E_USER_DEPRECATED);
  7540. return isset($this->blocks[(string) $name]);
  7541. }
  7542. if (isset($blocks[$name])) {
  7543. return $blocks[$name][0] instanceof self;
  7544. }
  7545. if (isset($this->blocks[$name])) {
  7546. return true;
  7547. }
  7548. if (false !== $parent $this->getParent($context)) {
  7549. return $parent->hasBlock($name$context);
  7550. }
  7551. return false;
  7552. }
  7553. public function getBlockNames(array $context null, array $blocks = [])
  7554. {
  7555. if (null === $context) {
  7556. @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.'E_USER_DEPRECATED);
  7557. return array_keys($this->blocks);
  7558. }
  7559. $names array_merge(array_keys($blocks), array_keys($this->blocks));
  7560. if (false !== $parent $this->getParent($context)) {
  7561. $names array_merge($names$parent->getBlockNames($context));
  7562. }
  7563. return array_unique($names);
  7564. }
  7565. protected function loadTemplate($template$templateName null$line null$index null)
  7566. {
  7567. try {
  7568. if (\is_array($template)) {
  7569. return $this->env->resolveTemplate($template);
  7570. }
  7571. if ($template instanceof self || $template instanceof TemplateWrapper) {
  7572. return $template;
  7573. }
  7574. if ($template === $this->getTemplateName()) {
  7575. $class = \get_class($this);
  7576. if (false !== $pos strrpos($class,'___', -1)) {
  7577. $class substr($class0$pos);
  7578. }
  7579. return $this->env->loadClass($class$template$index);
  7580. }
  7581. return $this->env->loadTemplate($template$index);
  7582. } catch (Error $e) {
  7583. if (!$e->getSourceContext()) {
  7584. $e->setSourceContext($templateName ? new Source(''$templateName) : $this->getSourceContext());
  7585. }
  7586. if ($e->getTemplateLine() > 0) {
  7587. throw $e;
  7588. }
  7589. if (!$line) {
  7590. $e->guess();
  7591. } else {
  7592. $e->setTemplateLine($line);
  7593. }
  7594. throw $e;
  7595. }
  7596. }
  7597. protected function unwrap()
  7598. {
  7599. return $this;
  7600. }
  7601. public function getBlocks()
  7602. {
  7603. return $this->blocks;
  7604. }
  7605. public function display(array $context, array $blocks = [])
  7606. {
  7607. $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks$blocks));
  7608. }
  7609. public function render(array $context)
  7610. {
  7611. $level ob_get_level();
  7612. if ($this->env->isDebug()) {
  7613. ob_start();
  7614. } else {
  7615. ob_start(function () { return''; });
  7616. }
  7617. try {
  7618. $this->display($context);
  7619. } catch (\Exception $e) {
  7620. while (ob_get_level() > $level) {
  7621. ob_end_clean();
  7622. }
  7623. throw $e;
  7624. } catch (\Throwable $e) {
  7625. while (ob_get_level() > $level) {
  7626. ob_end_clean();
  7627. }
  7628. throw $e;
  7629. }
  7630. return ob_get_clean();
  7631. }
  7632. protected function displayWithErrorHandling(array $context, array $blocks = [])
  7633. {
  7634. try {
  7635. $this->doDisplay($context$blocks);
  7636. } catch (Error $e) {
  7637. if (!$e->getSourceContext()) {
  7638. $e->setSourceContext($this->getSourceContext());
  7639. }
  7640. if (-=== $e->getTemplateLine()) {
  7641. $e->guess();
  7642. }
  7643. throw $e;
  7644. } catch (\Exception $e) {
  7645. $e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").'$e->getMessage()), -1$this->getSourceContext(), $e);
  7646. $e->guess();
  7647. throw $e;
  7648. }
  7649. }
  7650. abstract protected function doDisplay(array $context, array $blocks = []);
  7651. final protected function getContext($context$item$ignoreStrictCheck false)
  7652. {
  7653. if (!\array_key_exists($item$context)) {
  7654. if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
  7655. return;
  7656. }
  7657. throw new RuntimeError(sprintf('Variable "%s" does not exist.'$item), -1$this->getSourceContext());
  7658. }
  7659. return $context[$item];
  7660. }
  7661. protected function getAttribute($object$item, array $arguments = [], $type self::ANY_CALL$isDefinedTest false$ignoreStrictCheck false)
  7662. {
  7663. if (self::METHOD_CALL !== $type) {
  7664. $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item $item;
  7665. if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object)))
  7666. || ($object instanceof \ArrayAccess && isset($object[$arrayItem]))
  7667. ) {
  7668. if ($isDefinedTest) {
  7669. return true;
  7670. }
  7671. return $object[$arrayItem];
  7672. }
  7673. if (self::ARRAY_CALL === $type || !\is_object($object)) {
  7674. if ($isDefinedTest) {
  7675. return false;
  7676. }
  7677. if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
  7678. return;
  7679. }
  7680. if ($object instanceof \ArrayAccess) {
  7681. $message sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.'$arrayItem, \get_class($object));
  7682. } elseif (\is_object($object)) {
  7683. $message sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.'$item, \get_class($object));
  7684. } elseif (\is_array($object)) {
  7685. if (empty($object)) {
  7686. $message sprintf('Key "%s" does not exist as the array is empty.'$arrayItem);
  7687. } else {
  7688. $message sprintf('Key "%s" for array with keys "%s" does not exist.'$arrayItemimplode(', 'array_keys($object)));
  7689. }
  7690. } elseif (self::ARRAY_CALL === $type) {
  7691. if (null === $object) {
  7692. $message sprintf('Impossible to access a key ("%s") on a null variable.'$item);
  7693. } else {
  7694. $message sprintf('Impossible to access a key ("%s") on a %s variable ("%s").'$item, \gettype($object), $object);
  7695. }
  7696. } elseif (null === $object) {
  7697. $message sprintf('Impossible to access an attribute ("%s") on a null variable.'$item);
  7698. } else {
  7699. $message sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").'$item, \gettype($object), $object);
  7700. }
  7701. throw new RuntimeError($message, -1$this->getSourceContext());
  7702. }
  7703. }
  7704. if (!\is_object($object)) {
  7705. if ($isDefinedTest) {
  7706. return false;
  7707. }
  7708. if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
  7709. return;
  7710. }
  7711. if (null === $object) {
  7712. $message sprintf('Impossible to invoke a method ("%s") on a null variable.'$item);
  7713. } elseif (\is_array($object)) {
  7714. $message sprintf('Impossible to invoke a method ("%s") on an array.'$item);
  7715. } else {
  7716. $message sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").'$item, \gettype($object), $object);
  7717. }
  7718. throw new RuntimeError($message, -1$this->getSourceContext());
  7719. }
  7720. if (self::METHOD_CALL !== $type && !$object instanceof self) { if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) {
  7721. if ($isDefinedTest) {
  7722. return true;
  7723. }
  7724. if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
  7725. $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object$item);
  7726. }
  7727. return $object->$item;
  7728. }
  7729. }
  7730. $class = \get_class($object);
  7731. if (!isset(self::$cache[$class])) {
  7732. if ($object instanceof self) {
  7733. $ref = new \ReflectionClass($class);
  7734. $methods = [];
  7735. foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) {
  7736. if ('getenvironment'!== strtr($refMethod->name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')) {
  7737. $methods[] = $refMethod->name;
  7738. }
  7739. }
  7740. } else {
  7741. $methods get_class_methods($object);
  7742. }
  7743. sort($methods);
  7744. $cache = [];
  7745. foreach ($methods as $method) {
  7746. $cache[$method] = $method;
  7747. $cache[$lcName strtr($method,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')] = $method;
  7748. if ('g'=== $lcName[0] && === strpos($lcName,'get')) {
  7749. $name substr($method3);
  7750. $lcName substr($lcName3);
  7751. } elseif ('i'=== $lcName[0] && === strpos($lcName,'is')) {
  7752. $name substr($method2);
  7753. $lcName substr($lcName2);
  7754. } else {
  7755. continue;
  7756. }
  7757. if ($name) {
  7758. if (!isset($cache[$name])) {
  7759. $cache[$name] = $method;
  7760. }
  7761. if (!isset($cache[$lcName])) {
  7762. $cache[$lcName] = $method;
  7763. }
  7764. }
  7765. }
  7766. self::$cache[$class] = $cache;
  7767. }
  7768. $call false;
  7769. if (isset(self::$cache[$class][$item])) {
  7770. $method self::$cache[$class][$item];
  7771. } elseif (isset(self::$cache[$class][$lcItem strtr($item,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')])) {
  7772. $method self::$cache[$class][$lcItem];
  7773. } elseif (isset(self::$cache[$class]['__call'])) {
  7774. $method $item;
  7775. $call true;
  7776. } else {
  7777. if ($isDefinedTest) {
  7778. return false;
  7779. }
  7780. if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
  7781. return;
  7782. }
  7783. throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".'$item$class), -1$this->getSourceContext());
  7784. }
  7785. if ($isDefinedTest) {
  7786. return true;
  7787. }
  7788. if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
  7789. $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object$method);
  7790. }
  7791. try {
  7792. if (!$arguments) {
  7793. $ret $object->$method();
  7794. } else {
  7795. $ret = \call_user_func_array([$object$method], $arguments);
  7796. }
  7797. } catch (\BadMethodCallException $e) {
  7798. if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
  7799. return;
  7800. }
  7801. throw $e;
  7802. }
  7803. if ($object instanceof \Twig_TemplateInterface) {
  7804. $self $object->getTemplateName() === $this->getTemplateName();
  7805. $message sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.'$item$object->getTemplateName(), $this->getTemplateName());
  7806. if ('renderBlock'=== $method ||'displayBlock'=== $method) {
  7807. $message .= sprintf(' Use block("%s"%s) instead).'$arguments[0], $self ?'':', template');
  7808. } elseif ('hasBlock'=== $method) {
  7809. $message .= sprintf(' Use "block("%s"%s) is defined" instead).'$arguments[0], $self ?'':', template');
  7810. } elseif ('render'=== $method ||'display'=== $method) {
  7811. $message .= sprintf(' Use include("%s") instead).'$object->getTemplateName());
  7812. }
  7813. @trigger_error($messageE_USER_DEPRECATED);
  7814. return''=== $ret ?'': new Markup($ret$this->env->getCharset());
  7815. }
  7816. return $ret;
  7817. }
  7818. }
  7819. class_alias('Twig\Template','Twig_Template');
  7820. }
  7821. namespace Monolog\Formatter
  7822. {
  7823. interface FormatterInterface
  7824. {
  7825. public function format(array $record);
  7826. public function formatBatch(array $records);
  7827. }
  7828. }
  7829. namespace Monolog\Formatter
  7830. {
  7831. use Exception;
  7832. use Monolog\Utils;
  7833. class NormalizerFormatter implements FormatterInterface
  7834. {
  7835. const SIMPLE_DATE ="Y-m-d H:i:s";
  7836. protected $dateFormat;
  7837. protected $maxDepth;
  7838. public function __construct($dateFormat null$maxDepth 9)
  7839. {
  7840. $this->dateFormat $dateFormat ?: static::SIMPLE_DATE;
  7841. $this->maxDepth $maxDepth;
  7842. if (!function_exists('json_encode')) {
  7843. throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
  7844. }
  7845. }
  7846. public function format(array $record)
  7847. {
  7848. return $this->normalize($record);
  7849. }
  7850. public function formatBatch(array $records)
  7851. {
  7852. foreach ($records as $key => $record) {
  7853. $records[$key] = $this->format($record);
  7854. }
  7855. return $records;
  7856. }
  7857. public function getMaxDepth()
  7858. {
  7859. return $this->maxDepth;
  7860. }
  7861. public function setMaxDepth($maxDepth)
  7862. {
  7863. $this->maxDepth $maxDepth;
  7864. }
  7865. protected function normalize($data$depth 0)
  7866. {
  7867. if ($depth $this->maxDepth) {
  7868. return'Over '.$this->maxDepth.' levels deep, aborting normalization';
  7869. }
  7870. if (null === $data || is_scalar($data)) {
  7871. if (is_float($data)) {
  7872. if (is_infinite($data)) {
  7873. return ($data ?'':'-') .'INF';
  7874. }
  7875. if (is_nan($data)) {
  7876. return'NaN';
  7877. }
  7878. }
  7879. return $data;
  7880. }
  7881. if (is_array($data)) {
  7882. $normalized = array();
  7883. $count 1;
  7884. foreach ($data as $key => $value) {
  7885. if ($count++ > 1000) {
  7886. $normalized['...'] ='Over 1000 items ('.count($data).' total), aborting normalization';
  7887. break;
  7888. }
  7889. $normalized[$key] = $this->normalize($value$depth+1);
  7890. }
  7891. return $normalized;
  7892. }
  7893. if ($data instanceof \DateTime) {
  7894. return $data->format($this->dateFormat);
  7895. }
  7896. if (is_object($data)) {
  7897. if ($data instanceof Exception || (PHP_VERSION_ID 70000 && $data instanceof \Throwable)) {
  7898. return $this->normalizeException($data);
  7899. }
  7900. if (method_exists($data,'__toString') && !$data instanceof \JsonSerializable) {
  7901. $value $data->__toString();
  7902. } else {
  7903. $value $this->toJson($datatrue);
  7904. }
  7905. return sprintf("[object] (%s: %s)"Utils::getClass($data), $value);
  7906. }
  7907. if (is_resource($data)) {
  7908. return sprintf('[resource] (%s)'get_resource_type($data));
  7909. }
  7910. return'[unknown('.gettype($data).')]';
  7911. }
  7912. protected function normalizeException($e)
  7913. {
  7914. if (!$e instanceof Exception && !$e instanceof \Throwable) {
  7915. throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Utils::getClass($e));
  7916. }
  7917. $data = array('class'=> Utils::getClass($e),'message'=> $e->getMessage(),'code'=> (int) $e->getCode(),'file'=> $e->getFile().':'.$e->getLine(),
  7918. );
  7919. if ($e instanceof \SoapFault) {
  7920. if (isset($e->faultcode)) {
  7921. $data['faultcode'] = $e->faultcode;
  7922. }
  7923. if (isset($e->faultactor)) {
  7924. $data['faultactor'] = $e->faultactor;
  7925. }
  7926. if (isset($e->detail)) {
  7927. if (is_string($e->detail)) {
  7928. $data['detail'] = $e->detail;
  7929. } elseif (is_object($e->detail) || is_array($e->detail)) {
  7930. $data['detail'] = $this->toJson($e->detailtrue);
  7931. }
  7932. }
  7933. }
  7934. $trace $e->getTrace();
  7935. foreach ($trace as $frame) {
  7936. if (isset($frame['file'])) {
  7937. $data['trace'][] = $frame['file'].':'.$frame['line'];
  7938. }
  7939. }
  7940. if ($previous $e->getPrevious()) {
  7941. $data['previous'] = $this->normalizeException($previous);
  7942. }
  7943. return $data;
  7944. }
  7945. protected function toJson($data$ignoreErrors false)
  7946. {
  7947. return Utils::jsonEncode($datanull$ignoreErrors);
  7948. }
  7949. }}
  7950. namespace Monolog\Formatter
  7951. {
  7952. use Monolog\Utils;
  7953. class LineFormatter extends NormalizerFormatter
  7954. {
  7955. const SIMPLE_FORMAT ="[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
  7956. protected $format;
  7957. protected $allowInlineLineBreaks;
  7958. protected $ignoreEmptyContextAndExtra;
  7959. protected $includeStacktraces;
  7960. public function __construct($format null$dateFormat null$allowInlineLineBreaks false$ignoreEmptyContextAndExtra false)
  7961. {
  7962. $this->format $format ?: static::SIMPLE_FORMAT;
  7963. $this->allowInlineLineBreaks $allowInlineLineBreaks;
  7964. $this->ignoreEmptyContextAndExtra $ignoreEmptyContextAndExtra;
  7965. parent::__construct($dateFormat);
  7966. }
  7967. public function includeStacktraces($include true)
  7968. {
  7969. $this->includeStacktraces $include;
  7970. if ($this->includeStacktraces) {
  7971. $this->allowInlineLineBreaks true;
  7972. }
  7973. }
  7974. public function allowInlineLineBreaks($allow true)
  7975. {
  7976. $this->allowInlineLineBreaks $allow;
  7977. }
  7978. public function ignoreEmptyContextAndExtra($ignore true)
  7979. {
  7980. $this->ignoreEmptyContextAndExtra $ignore;
  7981. }
  7982. public function format(array $record)
  7983. {
  7984. $vars parent::format($record);
  7985. $output $this->format;
  7986. foreach ($vars['extra'] as $var => $val) {
  7987. if (false !== strpos($output,'%extra.'.$var.'%')) {
  7988. $output str_replace('%extra.'.$var.'%'$this->stringify($val), $output);
  7989. unset($vars['extra'][$var]);
  7990. }
  7991. }
  7992. foreach ($vars['context'] as $var => $val) {
  7993. if (false !== strpos($output,'%context.'.$var.'%')) {
  7994. $output str_replace('%context.'.$var.'%'$this->stringify($val), $output);
  7995. unset($vars['context'][$var]);
  7996. }
  7997. }
  7998. if ($this->ignoreEmptyContextAndExtra) {
  7999. if (empty($vars['context'])) {
  8000. unset($vars['context']);
  8001. $output str_replace('%context%',''$output);
  8002. }
  8003. if (empty($vars['extra'])) {
  8004. unset($vars['extra']);
  8005. $output str_replace('%extra%',''$output);
  8006. }
  8007. }
  8008. foreach ($vars as $var => $val) {
  8009. if (false !== strpos($output,'%'.$var.'%')) {
  8010. $output str_replace('%'.$var.'%'$this->stringify($val), $output);
  8011. }
  8012. }
  8013. if (false !== strpos($output,'%')) {
  8014. $output preg_replace('/%(?:extra|context)\..+?%/',''$output);
  8015. }
  8016. return $output;
  8017. }
  8018. public function formatBatch(array $records)
  8019. {
  8020. $message ='';
  8021. foreach ($records as $record) {
  8022. $message .= $this->format($record);
  8023. }
  8024. return $message;
  8025. }
  8026. public function stringify($value)
  8027. {
  8028. return $this->replaceNewlines($this->convertToString($value));
  8029. }
  8030. protected function normalizeException($e)
  8031. {
  8032. if (!$e instanceof \Exception && !$e instanceof \Throwable) {
  8033. throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Utils::getClass($e));
  8034. }
  8035. $previousText ='';
  8036. if ($previous $e->getPrevious()) {
  8037. do {
  8038. $previousText .=', '.Utils::getClass($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
  8039. } while ($previous $previous->getPrevious());
  8040. }
  8041. $str ='[object] ('.Utils::getClass($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
  8042. if ($this->includeStacktraces) {
  8043. $str .="\n[stacktrace]\n".$e->getTraceAsString()."\n";
  8044. }
  8045. return $str;
  8046. }
  8047. protected function convertToString($data)
  8048. {
  8049. if (null === $data || is_bool($data)) {
  8050. return var_export($datatrue);
  8051. }
  8052. if (is_scalar($data)) {
  8053. return (string) $data;
  8054. }
  8055. if (version_compare(PHP_VERSION,'5.4.0','>=')) {
  8056. return $this->toJson($datatrue);
  8057. }
  8058. return str_replace('\\/','/'$this->toJson($datatrue));
  8059. }
  8060. protected function replaceNewlines($str)
  8061. {
  8062. if ($this->allowInlineLineBreaks) {
  8063. if (=== strpos($str,'{')) {
  8064. return str_replace(array('\r','\n'), array("\r","\n"), $str);
  8065. }
  8066. return $str;
  8067. }
  8068. return str_replace(array("\r\n","\r","\n"),' '$str);
  8069. }
  8070. }
  8071. }
  8072. namespace Monolog\Handler
  8073. {
  8074. use Monolog\Formatter\FormatterInterface;
  8075. interface HandlerInterface
  8076. {
  8077. public function isHandling(array $record);
  8078. public function handle(array $record);
  8079. public function handleBatch(array $records);
  8080. public function pushProcessor($callback);
  8081. public function popProcessor();
  8082. public function setFormatter(FormatterInterface $formatter);
  8083. public function getFormatter();
  8084. }
  8085. }
  8086. namespace Monolog
  8087. {
  8088. interface ResettableInterface
  8089. {
  8090. public function reset();
  8091. }
  8092. }
  8093. namespace Monolog\Handler
  8094. {
  8095. use Monolog\Formatter\FormatterInterface;
  8096. use Monolog\Formatter\LineFormatter;
  8097. use Monolog\Logger;
  8098. use Monolog\ResettableInterface;
  8099. abstract class AbstractHandler implements HandlerInterfaceResettableInterface
  8100. {
  8101. protected $level Logger::DEBUG;
  8102. protected $bubble true;
  8103. protected $formatter;
  8104. protected $processors = array();
  8105. public function __construct($level Logger::DEBUG$bubble true)
  8106. {
  8107. $this->setLevel($level);
  8108. $this->bubble $bubble;
  8109. }
  8110. public function isHandling(array $record)
  8111. {
  8112. return $record['level'] >= $this->level;
  8113. }
  8114. public function handleBatch(array $records)
  8115. {
  8116. foreach ($records as $record) {
  8117. $this->handle($record);
  8118. }
  8119. }
  8120. public function close()
  8121. {
  8122. }
  8123. public function pushProcessor($callback)
  8124. {
  8125. if (!is_callable($callback)) {
  8126. throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callbacktrue).' given');
  8127. }
  8128. array_unshift($this->processors$callback);
  8129. return $this;
  8130. }
  8131. public function popProcessor()
  8132. {
  8133. if (!$this->processors) {
  8134. throw new \LogicException('You tried to pop from an empty processor stack.');
  8135. }
  8136. return array_shift($this->processors);
  8137. }
  8138. public function setFormatter(FormatterInterface $formatter)
  8139. {
  8140. $this->formatter $formatter;
  8141. return $this;
  8142. }
  8143. public function getFormatter()
  8144. {
  8145. if (!$this->formatter) {
  8146. $this->formatter $this->getDefaultFormatter();
  8147. }
  8148. return $this->formatter;
  8149. }
  8150. public function setLevel($level)
  8151. {
  8152. $this->level Logger::toMonologLevel($level);
  8153. return $this;
  8154. }
  8155. public function getLevel()
  8156. {
  8157. return $this->level;
  8158. }
  8159. public function setBubble($bubble)
  8160. {
  8161. $this->bubble $bubble;
  8162. return $this;
  8163. }
  8164. public function getBubble()
  8165. {
  8166. return $this->bubble;
  8167. }
  8168. public function __destruct()
  8169. {
  8170. try {
  8171. $this->close();
  8172. } catch (\Exception $e) {
  8173. } catch (\Throwable $e) {
  8174. }
  8175. }
  8176. public function reset()
  8177. {
  8178. foreach ($this->processors as $processor) {
  8179. if ($processor instanceof ResettableInterface) {
  8180. $processor->reset();
  8181. }
  8182. }
  8183. }
  8184. protected function getDefaultFormatter()
  8185. {
  8186. return new LineFormatter();
  8187. }
  8188. }
  8189. }
  8190. namespace Monolog\Handler
  8191. {
  8192. use Monolog\ResettableInterface;
  8193. abstract class AbstractProcessingHandler extends AbstractHandler
  8194. {
  8195. public function handle(array $record)
  8196. {
  8197. if (!$this->isHandling($record)) {
  8198. return false;
  8199. }
  8200. $record $this->processRecord($record);
  8201. $record['formatted'] = $this->getFormatter()->format($record);
  8202. $this->write($record);
  8203. return false === $this->bubble;
  8204. }
  8205. abstract protected function write(array $record);
  8206. protected function processRecord(array $record)
  8207. {
  8208. if ($this->processors) {
  8209. foreach ($this->processors as $processor) {
  8210. $record call_user_func($processor$record);
  8211. }
  8212. }
  8213. return $record;
  8214. }
  8215. }
  8216. }
  8217. namespace Monolog\Handler
  8218. {
  8219. use Monolog\Logger;
  8220. use Monolog\Utils;
  8221. class StreamHandler extends AbstractProcessingHandler
  8222. {
  8223. const CHUNK_SIZE 524288;
  8224. protected $stream;
  8225. protected $url;
  8226. private $errorMessage;
  8227. protected $filePermission;
  8228. protected $useLocking;
  8229. private $dirCreated;
  8230. public function __construct($stream$level Logger::DEBUG$bubble true$filePermission null$useLocking false)
  8231. {
  8232. parent::__construct($level$bubble);
  8233. if (is_resource($stream)) {
  8234. $this->stream $stream;
  8235. $this->streamSetChunkSize();
  8236. } elseif (is_string($stream)) {
  8237. $this->url Utils::canonicalizePath($stream);
  8238. } else {
  8239. throw new \InvalidArgumentException('A stream must either be a resource or a string.');
  8240. }
  8241. $this->filePermission $filePermission;
  8242. $this->useLocking $useLocking;
  8243. }
  8244. public function close()
  8245. {
  8246. if ($this->url && is_resource($this->stream)) {
  8247. fclose($this->stream);
  8248. }
  8249. $this->stream null;
  8250. $this->dirCreated null;
  8251. }
  8252. public function getStream()
  8253. {
  8254. return $this->stream;
  8255. }
  8256. public function getUrl()
  8257. {
  8258. return $this->url;
  8259. }
  8260. protected function write(array $record)
  8261. {
  8262. if (!is_resource($this->stream)) {
  8263. if (null === $this->url ||''=== $this->url) {
  8264. throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
  8265. }
  8266. $this->createDir();
  8267. $this->errorMessage null;
  8268. set_error_handler(array($this,'customErrorHandler'));
  8269. $this->stream fopen($this->url,'a');
  8270. if ($this->filePermission !== null) {
  8271. @chmod($this->url$this->filePermission);
  8272. }
  8273. restore_error_handler();
  8274. if (!is_resource($this->stream)) {
  8275. $this->stream null;
  8276. throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage$this->url));
  8277. }
  8278. $this->streamSetChunkSize();
  8279. }
  8280. if ($this->useLocking) {
  8281. flock($this->streamLOCK_EX);
  8282. }
  8283. $this->streamWrite($this->stream$record);
  8284. if ($this->useLocking) {
  8285. flock($this->streamLOCK_UN);
  8286. }
  8287. }
  8288. protected function streamWrite($stream, array $record)
  8289. {
  8290. fwrite($stream, (string) $record['formatted']);
  8291. }
  8292. protected function streamSetChunkSize()
  8293. {
  8294. if (version_compare(PHP_VERSION,'5.4.0','>=')) {
  8295. return stream_set_chunk_size($this->streamself::CHUNK_SIZE);
  8296. }
  8297. return false;
  8298. }
  8299. private function customErrorHandler($code$msg)
  8300. {
  8301. $this->errorMessage preg_replace('{^(fopen|mkdir)\(.*?\): }',''$msg);
  8302. }
  8303. private function getDirFromStream($stream)
  8304. {
  8305. $pos strpos($stream,'://');
  8306. if ($pos === false) {
  8307. return dirname($stream);
  8308. }
  8309. if ('file://'=== substr($stream07)) {
  8310. return dirname(substr($stream7));
  8311. }
  8312. return null;
  8313. }
  8314. private function createDir()
  8315. {
  8316. if ($this->dirCreated) {
  8317. return;
  8318. }
  8319. $dir $this->getDirFromStream($this->url);
  8320. if (null !== $dir && !is_dir($dir)) {
  8321. $this->errorMessage null;
  8322. set_error_handler(array($this,'customErrorHandler'));
  8323. $status mkdir($dir0777true);
  8324. restore_error_handler();
  8325. if (false === $status && !is_dir($dir)) {
  8326. throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage$dir));
  8327. }
  8328. }
  8329. $this->dirCreated true;
  8330. }
  8331. }
  8332. }
  8333. namespace Monolog\Handler
  8334. {
  8335. use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
  8336. use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
  8337. use Monolog\Logger;
  8338. use Monolog\ResettableInterface;
  8339. use Monolog\Formatter\FormatterInterface;
  8340. class FingersCrossedHandler extends AbstractHandler
  8341. {
  8342. protected $handler;
  8343. protected $activationStrategy;
  8344. protected $buffering true;
  8345. protected $bufferSize;
  8346. protected $buffer = array();
  8347. protected $stopBuffering;
  8348. protected $passthruLevel;
  8349. public function __construct($handler$activationStrategy null$bufferSize 0$bubble true$stopBuffering true$passthruLevel null)
  8350. {
  8351. if (null === $activationStrategy) {
  8352. $activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
  8353. }
  8354. if (!$activationStrategy instanceof ActivationStrategyInterface) {
  8355. $activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
  8356. }
  8357. $this->handler $handler;
  8358. $this->activationStrategy $activationStrategy;
  8359. $this->bufferSize $bufferSize;
  8360. $this->bubble $bubble;
  8361. $this->stopBuffering $stopBuffering;
  8362. if ($passthruLevel !== null) {
  8363. $this->passthruLevel Logger::toMonologLevel($passthruLevel);
  8364. }
  8365. if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
  8366. throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
  8367. }
  8368. }
  8369. public function isHandling(array $record)
  8370. {
  8371. return true;
  8372. }
  8373. public function activate()
  8374. {
  8375. if ($this->stopBuffering) {
  8376. $this->buffering false;
  8377. }
  8378. $this->getHandler(end($this->buffer) ?: null)->handleBatch($this->buffer);
  8379. $this->buffer = array();
  8380. }
  8381. public function handle(array $record)
  8382. {
  8383. if ($this->processors) {
  8384. foreach ($this->processors as $processor) {
  8385. $record call_user_func($processor$record);
  8386. }
  8387. }
  8388. if ($this->buffering) {
  8389. $this->buffer[] = $record;
  8390. if ($this->bufferSize && count($this->buffer) > $this->bufferSize) {
  8391. array_shift($this->buffer);
  8392. }
  8393. if ($this->activationStrategy->isHandlerActivated($record)) {
  8394. $this->activate();
  8395. }
  8396. } else {
  8397. $this->getHandler($record)->handle($record);
  8398. }
  8399. return false === $this->bubble;
  8400. }
  8401. public function close()
  8402. {
  8403. $this->flushBuffer();
  8404. }
  8405. public function reset()
  8406. {
  8407. $this->flushBuffer();
  8408. parent::reset();
  8409. if ($this->getHandler() instanceof ResettableInterface) {
  8410. $this->getHandler()->reset();
  8411. }
  8412. }
  8413. public function clear()
  8414. {
  8415. $this->buffer = array();
  8416. $this->reset();
  8417. }
  8418. private function flushBuffer()
  8419. {
  8420. if (null !== $this->passthruLevel) {
  8421. $level $this->passthruLevel;
  8422. $this->buffer array_filter($this->buffer, function ($record) use ($level) {
  8423. return $record['level'] >= $level;
  8424. });
  8425. if (count($this->buffer) > 0) {
  8426. $this->getHandler(end($this->buffer) ?: null)->handleBatch($this->buffer);
  8427. }
  8428. }
  8429. $this->buffer = array();
  8430. $this->buffering true;
  8431. }
  8432. public function getHandler(array $record null)
  8433. {
  8434. if (!$this->handler instanceof HandlerInterface) {
  8435. $this->handler call_user_func($this->handler$record$this);
  8436. if (!$this->handler instanceof HandlerInterface) {
  8437. throw new \RuntimeException("The factory callable should return a HandlerInterface");
  8438. }
  8439. }
  8440. return $this->handler;
  8441. }
  8442. public function setFormatter(FormatterInterface $formatter)
  8443. {
  8444. $this->getHandler()->setFormatter($formatter);
  8445. return $this;
  8446. }
  8447. public function getFormatter()
  8448. {
  8449. return $this->getHandler()->getFormatter();
  8450. }
  8451. }
  8452. }
  8453. namespace Monolog\Handler
  8454. {
  8455. use Monolog\Logger;
  8456. use Monolog\Formatter\FormatterInterface;
  8457. class FilterHandler extends AbstractHandler
  8458. {
  8459. protected $handler;
  8460. protected $acceptedLevels;
  8461. protected $bubble;
  8462. public function __construct($handler$minLevelOrList Logger::DEBUG$maxLevel Logger::EMERGENCY$bubble true)
  8463. {
  8464. $this->handler $handler;
  8465. $this->bubble $bubble;
  8466. $this->setAcceptedLevels($minLevelOrList$maxLevel);
  8467. if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
  8468. throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
  8469. }
  8470. }
  8471. public function getAcceptedLevels()
  8472. {
  8473. return array_flip($this->acceptedLevels);
  8474. }
  8475. public function setAcceptedLevels($minLevelOrList Logger::DEBUG$maxLevel Logger::EMERGENCY)
  8476. {
  8477. if (is_array($minLevelOrList)) {
  8478. $acceptedLevels array_map('Monolog\Logger::toMonologLevel'$minLevelOrList);
  8479. } else {
  8480. $minLevelOrList Logger::toMonologLevel($minLevelOrList);
  8481. $maxLevel Logger::toMonologLevel($maxLevel);
  8482. $acceptedLevels array_values(array_filter(Logger::getLevels(), function ($level) use ($minLevelOrList$maxLevel) {
  8483. return $level >= $minLevelOrList && $level <= $maxLevel;
  8484. }));
  8485. }
  8486. $this->acceptedLevels array_flip($acceptedLevels);
  8487. }
  8488. public function isHandling(array $record)
  8489. {
  8490. return isset($this->acceptedLevels[$record['level']]);
  8491. }
  8492. public function handle(array $record)
  8493. {
  8494. if (!$this->isHandling($record)) {
  8495. return false;
  8496. }
  8497. if ($this->processors) {
  8498. foreach ($this->processors as $processor) {
  8499. $record call_user_func($processor$record);
  8500. }
  8501. }
  8502. $this->getHandler($record)->handle($record);
  8503. return false === $this->bubble;
  8504. }
  8505. public function handleBatch(array $records)
  8506. {
  8507. $filtered = array();
  8508. foreach ($records as $record) {
  8509. if ($this->isHandling($record)) {
  8510. $filtered[] = $record;
  8511. }
  8512. }
  8513. if (count($filtered) > 0) {
  8514. $this->getHandler($filtered[count($filtered) - 1])->handleBatch($filtered);
  8515. }
  8516. }
  8517. public function getHandler(array $record null)
  8518. {
  8519. if (!$this->handler instanceof HandlerInterface) {
  8520. $this->handler call_user_func($this->handler$record$this);
  8521. if (!$this->handler instanceof HandlerInterface) {
  8522. throw new \RuntimeException("The factory callable should return a HandlerInterface");
  8523. }
  8524. }
  8525. return $this->handler;
  8526. }
  8527. public function setFormatter(FormatterInterface $formatter)
  8528. {
  8529. $this->getHandler()->setFormatter($formatter);
  8530. return $this;
  8531. }
  8532. public function getFormatter()
  8533. {
  8534. return $this->getHandler()->getFormatter();
  8535. }
  8536. }
  8537. }
  8538. namespace Monolog\Handler
  8539. {
  8540. class TestHandler extends AbstractProcessingHandler
  8541. {
  8542. protected $records = array();
  8543. protected $recordsByLevel = array();
  8544. private $skipReset false;
  8545. public function getRecords()
  8546. {
  8547. return $this->records;
  8548. }
  8549. public function clear()
  8550. {
  8551. $this->records = array();
  8552. $this->recordsByLevel = array();
  8553. }
  8554. public function reset()
  8555. {
  8556. if (!$this->skipReset) {
  8557. $this->clear();
  8558. }
  8559. }
  8560. public function setSkipReset($skipReset)
  8561. {
  8562. $this->skipReset $skipReset;
  8563. }
  8564. public function hasRecords($level)
  8565. {
  8566. return isset($this->recordsByLevel[$level]);
  8567. }
  8568. public function hasRecord($record$level)
  8569. {
  8570. if (is_string($record)) {
  8571. $record = array('message'=> $record);
  8572. }
  8573. return $this->hasRecordThatPasses(function ($rec) use ($record) {
  8574. if ($rec['message'] !== $record['message']) {
  8575. return false;
  8576. }
  8577. if (isset($record['context']) && $rec['context'] !== $record['context']) {
  8578. return false;
  8579. }
  8580. return true;
  8581. }, $level);
  8582. }
  8583. public function hasRecordThatContains($message$level)
  8584. {
  8585. return $this->hasRecordThatPasses(function ($rec) use ($message) {
  8586. return strpos($rec['message'], $message) !== false;
  8587. }, $level);
  8588. }
  8589. public function hasRecordThatMatches($regex$level)
  8590. {
  8591. return $this->hasRecordThatPasses(function ($rec) use ($regex) {
  8592. return preg_match($regex$rec['message']) > 0;
  8593. }, $level);
  8594. }
  8595. public function hasRecordThatPasses($predicate$level)
  8596. {
  8597. if (!is_callable($predicate)) {
  8598. throw new \InvalidArgumentException("Expected a callable for hasRecordThatSucceeds");
  8599. }
  8600. if (!isset($this->recordsByLevel[$level])) {
  8601. return false;
  8602. }
  8603. foreach ($this->recordsByLevel[$level] as $i => $rec) {
  8604. if (call_user_func($predicate$rec$i)) {
  8605. return true;
  8606. }
  8607. }
  8608. return false;
  8609. }
  8610. protected function write(array $record)
  8611. {
  8612. $this->recordsByLevel[$record['level']][] = $record;
  8613. $this->records[] = $record;
  8614. }
  8615. public function __call($method$args)
  8616. {
  8617. if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/'$method$matches) > 0) {
  8618. $genericMethod $matches[1] . ('Records'!== $matches[3] ?'Record':'') . $matches[3];
  8619. $level constant('Monolog\Logger::'strtoupper($matches[2]));
  8620. if (method_exists($this$genericMethod)) {
  8621. $args[] = $level;
  8622. return call_user_func_array(array($this$genericMethod), $args);
  8623. }
  8624. }
  8625. throw new \BadMethodCallException('Call to undefined method 'get_class($this) .'::'$method .'()');
  8626. }
  8627. }
  8628. }
  8629. namespace Monolog
  8630. {
  8631. use Monolog\Handler\HandlerInterface;
  8632. use Monolog\Handler\StreamHandler;
  8633. use Psr\Log\LoggerInterface;
  8634. use Psr\Log\InvalidArgumentException;
  8635. use Exception;
  8636. class Logger implements LoggerInterfaceResettableInterface
  8637. {
  8638. const DEBUG 100;
  8639. const INFO 200;
  8640. const NOTICE 250;
  8641. const WARNING 300;
  8642. const ERROR 400;
  8643. const CRITICAL 500;
  8644. const ALERT 550;
  8645. const EMERGENCY 600;
  8646. const API 1;
  8647. protected static $levels = array(
  8648. self::DEBUG =>'DEBUG',
  8649. self::INFO =>'INFO',
  8650. self::NOTICE =>'NOTICE',
  8651. self::WARNING =>'WARNING',
  8652. self::ERROR =>'ERROR',
  8653. self::CRITICAL =>'CRITICAL',
  8654. self::ALERT =>'ALERT',
  8655. self::EMERGENCY =>'EMERGENCY',
  8656. );
  8657. protected static $timezone;
  8658. protected $name;
  8659. protected $handlers;
  8660. protected $processors;
  8661. protected $microsecondTimestamps true;
  8662. protected $exceptionHandler;
  8663. public function __construct($name, array $handlers = array(), array $processors = array())
  8664. {
  8665. $this->name $name;
  8666. $this->setHandlers($handlers);
  8667. $this->processors $processors;
  8668. }
  8669. public function getName()
  8670. {
  8671. return $this->name;
  8672. }
  8673. public function withName($name)
  8674. {
  8675. $new = clone $this;
  8676. $new->name $name;
  8677. return $new;
  8678. }
  8679. public function pushHandler(HandlerInterface $handler)
  8680. {
  8681. array_unshift($this->handlers$handler);
  8682. return $this;
  8683. }
  8684. public function popHandler()
  8685. {
  8686. if (!$this->handlers) {
  8687. throw new \LogicException('You tried to pop from an empty handler stack.');
  8688. }
  8689. return array_shift($this->handlers);
  8690. }
  8691. public function setHandlers(array $handlers)
  8692. {
  8693. $this->handlers = array();
  8694. foreach (array_reverse($handlers) as $handler) {
  8695. $this->pushHandler($handler);
  8696. }
  8697. return $this;
  8698. }
  8699. public function getHandlers()
  8700. {
  8701. return $this->handlers;
  8702. }
  8703. public function pushProcessor($callback)
  8704. {
  8705. if (!is_callable($callback)) {
  8706. throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callbacktrue).' given');
  8707. }
  8708. array_unshift($this->processors$callback);
  8709. return $this;
  8710. }
  8711. public function popProcessor()
  8712. {
  8713. if (!$this->processors) {
  8714. throw new \LogicException('You tried to pop from an empty processor stack.');
  8715. }
  8716. return array_shift($this->processors);
  8717. }
  8718. public function getProcessors()
  8719. {
  8720. return $this->processors;
  8721. }
  8722. public function useMicrosecondTimestamps($micro)
  8723. {
  8724. $this->microsecondTimestamps = (bool) $micro;
  8725. }
  8726. public function addRecord($level$message, array $context = array())
  8727. {
  8728. if (!$this->handlers) {
  8729. $this->pushHandler(new StreamHandler('php://stderr', static::DEBUG));
  8730. }
  8731. $levelName = static::getLevelName($level);
  8732. $handlerKey null;
  8733. reset($this->handlers);
  8734. while ($handler current($this->handlers)) {
  8735. if ($handler->isHandling(array('level'=> $level))) {
  8736. $handlerKey key($this->handlers);
  8737. break;
  8738. }
  8739. next($this->handlers);
  8740. }
  8741. if (null === $handlerKey) {
  8742. return false;
  8743. }
  8744. if (!static::$timezone) {
  8745. static::$timezone = new \DateTimeZone(date_default_timezone_get() ?:'UTC');
  8746. }
  8747. if ($this->microsecondTimestamps && PHP_VERSION_ID 70100) {
  8748. $ts = \DateTime::createFromFormat('U.u'sprintf('%.6F'microtime(true)), static::$timezone);
  8749. } else {
  8750. $ts = new \DateTime('now', static::$timezone);
  8751. }
  8752. $ts->setTimezone(static::$timezone);
  8753. $record = array('message'=> (string) $message,'context'=> $context,'level'=> $level,'level_name'=> $levelName,'channel'=> $this->name,'datetime'=> $ts,'extra'=> array(),
  8754. );
  8755. try {
  8756. foreach ($this->processors as $processor) {
  8757. $record call_user_func($processor$record);
  8758. }
  8759. while ($handler current($this->handlers)) {
  8760. if (true === $handler->handle($record)) {
  8761. break;
  8762. }
  8763. next($this->handlers);
  8764. }
  8765. } catch (Exception $e) {
  8766. $this->handleException($e$record);
  8767. }
  8768. return true;
  8769. }
  8770. public function close()
  8771. {
  8772. foreach ($this->handlers as $handler) {
  8773. if (method_exists($handler,'close')) {
  8774. $handler->close();
  8775. }
  8776. }
  8777. }
  8778. public function reset()
  8779. {
  8780. foreach ($this->handlers as $handler) {
  8781. if ($handler instanceof ResettableInterface) {
  8782. $handler->reset();
  8783. }
  8784. }
  8785. foreach ($this->processors as $processor) {
  8786. if ($processor instanceof ResettableInterface) {
  8787. $processor->reset();
  8788. }
  8789. }
  8790. }
  8791. public function addDebug($message, array $context = array())
  8792. {
  8793. return $this->addRecord(static::DEBUG$message$context);
  8794. }
  8795. public function addInfo($message, array $context = array())
  8796. {
  8797. return $this->addRecord(static::INFO$message$context);
  8798. }
  8799. public function addNotice($message, array $context = array())
  8800. {
  8801. return $this->addRecord(static::NOTICE$message$context);
  8802. }
  8803. public function addWarning($message, array $context = array())
  8804. {
  8805. return $this->addRecord(static::WARNING$message$context);
  8806. }
  8807. public function addError($message, array $context = array())
  8808. {
  8809. return $this->addRecord(static::ERROR$message$context);
  8810. }
  8811. public function addCritical($message, array $context = array())
  8812. {
  8813. return $this->addRecord(static::CRITICAL$message$context);
  8814. }
  8815. public function addAlert($message, array $context = array())
  8816. {
  8817. return $this->addRecord(static::ALERT$message$context);
  8818. }
  8819. public function addEmergency($message, array $context = array())
  8820. {
  8821. return $this->addRecord(static::EMERGENCY$message$context);
  8822. }
  8823. public static function getLevels()
  8824. {
  8825. return array_flip(static::$levels);
  8826. }
  8827. public static function getLevelName($level)
  8828. {
  8829. if (!isset(static::$levels[$level])) {
  8830. throw new InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', 'array_keys(static::$levels)));
  8831. }
  8832. return static::$levels[$level];
  8833. }
  8834. public static function toMonologLevel($level)
  8835. {
  8836. if (is_string($level)) {
  8837. $upper strtr($level,'abcdefgilmnortuwy','ABCDEFGILMNORTUWY');
  8838. if (defined(__CLASS__.'::'.$upper)) {
  8839. return constant(__CLASS__ .'::'$upper);
  8840. }
  8841. }
  8842. return $level;
  8843. }
  8844. public function isHandling($level)
  8845. {
  8846. $record = array('level'=> $level,
  8847. );
  8848. foreach ($this->handlers as $handler) {
  8849. if ($handler->isHandling($record)) {
  8850. return true;
  8851. }
  8852. }
  8853. return false;
  8854. }
  8855. public function setExceptionHandler($callback)
  8856. {
  8857. if (!is_callable($callback)) {
  8858. throw new \InvalidArgumentException('Exception handler must be valid callable (callback or object with an __invoke method), '.var_export($callbacktrue).' given');
  8859. }
  8860. $this->exceptionHandler $callback;
  8861. return $this;
  8862. }
  8863. public function getExceptionHandler()
  8864. {
  8865. return $this->exceptionHandler;
  8866. }
  8867. protected function handleException(Exception $e, array $record)
  8868. {
  8869. if (!$this->exceptionHandler) {
  8870. throw $e;
  8871. }
  8872. call_user_func($this->exceptionHandler$e$record);
  8873. }
  8874. public function log($level$message, array $context = array())
  8875. {
  8876. $level = static::toMonologLevel($level);
  8877. return $this->addRecord($level$message$context);
  8878. }
  8879. public function debug($message, array $context = array())
  8880. {
  8881. return $this->addRecord(static::DEBUG$message$context);
  8882. }
  8883. public function info($message, array $context = array())
  8884. {
  8885. return $this->addRecord(static::INFO$message$context);
  8886. }
  8887. public function notice($message, array $context = array())
  8888. {
  8889. return $this->addRecord(static::NOTICE$message$context);
  8890. }
  8891. public function warn($message, array $context = array())
  8892. {
  8893. return $this->addRecord(static::WARNING$message$context);
  8894. }
  8895. public function warning($message, array $context = array())
  8896. {
  8897. return $this->addRecord(static::WARNING$message$context);
  8898. }
  8899. public function err($message, array $context = array())
  8900. {
  8901. return $this->addRecord(static::ERROR$message$context);
  8902. }
  8903. public function error($message, array $context = array())
  8904. {
  8905. return $this->addRecord(static::ERROR$message$context);
  8906. }
  8907. public function crit($message, array $context = array())
  8908. {
  8909. return $this->addRecord(static::CRITICAL$message$context);
  8910. }
  8911. public function critical($message, array $context = array())
  8912. {
  8913. return $this->addRecord(static::CRITICAL$message$context);
  8914. }
  8915. public function alert($message, array $context = array())
  8916. {
  8917. return $this->addRecord(static::ALERT$message$context);
  8918. }
  8919. public function emerg($message, array $context = array())
  8920. {
  8921. return $this->addRecord(static::EMERGENCY$message$context);
  8922. }
  8923. public function emergency($message, array $context = array())
  8924. {
  8925. return $this->addRecord(static::EMERGENCY$message$context);
  8926. }
  8927. public static function setTimezone(\DateTimeZone $tz)
  8928. {
  8929. self::$timezone $tz;
  8930. }
  8931. }
  8932. }
  8933. namespace Symfony\Component\HttpKernel\Log
  8934. {
  8935. interface DebugLoggerInterface
  8936. {
  8937. public function getLogs();
  8938. public function countErrors();
  8939. }
  8940. }
  8941. namespace Symfony\Bridge\Monolog
  8942. {
  8943. use Monolog\Logger as BaseLogger;
  8944. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  8945. class Logger extends BaseLogger implements DebugLoggerInterface
  8946. {
  8947. public function getLogs()
  8948. {
  8949. if ($logger $this->getDebugLogger()) {
  8950. return $logger->getLogs();
  8951. }
  8952. return array();
  8953. }
  8954. public function countErrors()
  8955. {
  8956. if ($logger $this->getDebugLogger()) {
  8957. return $logger->countErrors();
  8958. }
  8959. return 0;
  8960. }
  8961. private function getDebugLogger()
  8962. {
  8963. foreach ($this->processors as $processor) {
  8964. if ($processor instanceof DebugLoggerInterface) {
  8965. return $processor;
  8966. }
  8967. }
  8968. foreach ($this->handlers as $handler) {
  8969. if ($handler instanceof DebugLoggerInterface) {
  8970. return $handler;
  8971. }
  8972. }
  8973. }
  8974. }
  8975. }
  8976. namespace Monolog\Handler\FingersCrossed
  8977. {
  8978. interface ActivationStrategyInterface
  8979. {
  8980. public function isHandlerActivated(array $record);
  8981. }
  8982. }
  8983. namespace Monolog\Handler\FingersCrossed
  8984. {
  8985. use Monolog\Logger;
  8986. class ErrorLevelActivationStrategy implements ActivationStrategyInterface
  8987. {
  8988. private $actionLevel;
  8989. public function __construct($actionLevel)
  8990. {
  8991. $this->actionLevel Logger::toMonologLevel($actionLevel);
  8992. }
  8993. public function isHandlerActivated(array $record)
  8994. {
  8995. return $record['level'] >= $this->actionLevel;
  8996. }
  8997. }
  8998. }
  8999. namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
  9000. {
  9001. use Doctrine\Common\Annotations\Reader;
  9002. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9003. use Symfony\Component\HttpKernel\KernelEvents;
  9004. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9005. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
  9006. use Doctrine\Common\Util\ClassUtils;
  9007. class ControllerListener implements EventSubscriberInterface
  9008. {
  9009. protected $reader;
  9010. public function __construct(Reader $reader)
  9011. {
  9012. $this->reader $reader;
  9013. }
  9014. public function onKernelController(FilterControllerEvent $event)
  9015. {
  9016. $controller $event->getController();
  9017. if (!is_array($controller) && method_exists($controller,'__invoke')) {
  9018. $controller = array($controller,'__invoke');
  9019. }
  9020. if (!is_array($controller)) {
  9021. return;
  9022. }
  9023. $className class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
  9024. $object = new \ReflectionClass($className);
  9025. $method $object->getMethod($controller[1]);
  9026. $classConfigurations $this->getConfigurations($this->reader->getClassAnnotations($object));
  9027. $methodConfigurations $this->getConfigurations($this->reader->getMethodAnnotations($method));
  9028. $configurations = array();
  9029. foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) {
  9030. if (!array_key_exists($key$classConfigurations)) {
  9031. $configurations[$key] = $methodConfigurations[$key];
  9032. } elseif (!array_key_exists($key$methodConfigurations)) {
  9033. $configurations[$key] = $classConfigurations[$key];
  9034. } else {
  9035. if (is_array($classConfigurations[$key])) {
  9036. if (!is_array($methodConfigurations[$key])) {
  9037. throw new \UnexpectedValueException('Configurations should both be an array or both not be an array');
  9038. }
  9039. $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]);
  9040. } else {
  9041. $configurations[$key] = $methodConfigurations[$key];
  9042. }
  9043. }
  9044. }
  9045. $request $event->getRequest();
  9046. foreach ($configurations as $key => $attributes) {
  9047. $request->attributes->set($key$attributes);
  9048. }
  9049. }
  9050. protected function getConfigurations(array $annotations)
  9051. {
  9052. $configurations = array();
  9053. foreach ($annotations as $configuration) {
  9054. if ($configuration instanceof ConfigurationInterface) {
  9055. if ($configuration->allowArray()) {
  9056. $configurations['_'.$configuration->getAliasName()][] = $configuration;
  9057. } elseif (!isset($configurations['_'.$configuration->getAliasName()])) {
  9058. $configurations['_'.$configuration->getAliasName()] = $configuration;
  9059. } else {
  9060. throw new \LogicException(sprintf('Multiple "%s" annotations are not allowed.'$configuration->getAliasName()));
  9061. }
  9062. }
  9063. }
  9064. return $configurations;
  9065. }
  9066. public static function getSubscribedEvents()
  9067. {
  9068. return array(
  9069. KernelEvents::CONTROLLER =>'onKernelController',
  9070. );
  9071. }
  9072. }
  9073. }
  9074. namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
  9075. {
  9076. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9077. use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager;
  9078. use Symfony\Component\HttpFoundation\Request;
  9079. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9080. use Symfony\Component\HttpKernel\KernelEvents;
  9081. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9082. class ParamConverterListener implements EventSubscriberInterface
  9083. {
  9084. protected $manager;
  9085. protected $autoConvert;
  9086. private $isParameterTypeSupported;
  9087. public function __construct(ParamConverterManager $manager$autoConvert true)
  9088. {
  9089. $this->manager $manager;
  9090. $this->autoConvert $autoConvert;
  9091. $this->isParameterTypeSupported method_exists('ReflectionParameter','getType');
  9092. }
  9093. public function onKernelController(FilterControllerEvent $event)
  9094. {
  9095. $controller $event->getController();
  9096. $request $event->getRequest();
  9097. $configurations = array();
  9098. if ($configuration $request->attributes->get('_converters')) {
  9099. foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
  9100. $configurations[$configuration->getName()] = $configuration;
  9101. }
  9102. }
  9103. if (is_array($controller)) {
  9104. $r = new \ReflectionMethod($controller[0], $controller[1]);
  9105. } elseif (is_object($controller) && is_callable($controller,'__invoke')) {
  9106. $r = new \ReflectionMethod($controller,'__invoke');
  9107. } else {
  9108. $r = new \ReflectionFunction($controller);
  9109. }
  9110. if ($this->autoConvert) {
  9111. $configurations $this->autoConfigure($r$request$configurations);
  9112. }
  9113. $this->manager->apply($request$configurations);
  9114. }
  9115. private function autoConfigure(\ReflectionFunctionAbstract $rRequest $request$configurations)
  9116. {
  9117. foreach ($r->getParameters() as $param) {
  9118. if ($param->getClass() && $param->getClass()->isInstance($request)) {
  9119. continue;
  9120. }
  9121. $name $param->getName();
  9122. $class $param->getClass();
  9123. $hasType $this->isParameterTypeSupported && $param->hasType();
  9124. if ($class || $hasType) {
  9125. if (!isset($configurations[$name])) {
  9126. $configuration = new ParamConverter(array());
  9127. $configuration->setName($name);
  9128. $configurations[$name] = $configuration;
  9129. }
  9130. if ($class && null === $configurations[$name]->getClass()) {
  9131. $configurations[$name]->setClass($class->getName());
  9132. }
  9133. }
  9134. if (isset($configurations[$name])) {
  9135. $configurations[$name]->setIsOptional($param->isOptional() || $param->isDefaultValueAvailable() || $hasType && $param->getType()->allowsNull());
  9136. }
  9137. }
  9138. return $configurations;
  9139. }
  9140. public static function getSubscribedEvents()
  9141. {
  9142. return array(
  9143. KernelEvents::CONTROLLER =>'onKernelController',
  9144. );
  9145. }
  9146. }
  9147. }
  9148. namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
  9149. {
  9150. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9151. use Symfony\Component\HttpFoundation\Request;
  9152. interface ParamConverterInterface
  9153. {
  9154. public function apply(Request $requestParamConverter $configuration);
  9155. public function supports(ParamConverter $configuration);
  9156. }
  9157. }
  9158. namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
  9159. {
  9160. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9161. use Symfony\Component\HttpFoundation\Request;
  9162. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9163. use DateTime;
  9164. class DateTimeParamConverter implements ParamConverterInterface
  9165. {
  9166. public function apply(Request $requestParamConverter $configuration)
  9167. {
  9168. $param $configuration->getName();
  9169. if (!$request->attributes->has($param)) {
  9170. return false;
  9171. }
  9172. $options $configuration->getOptions();
  9173. $value $request->attributes->get($param);
  9174. if (!$value && $configuration->isOptional()) {
  9175. return false;
  9176. }
  9177. if (isset($options['format'])) {
  9178. $date DateTime::createFromFormat($options['format'], $value);
  9179. if (!$date) {
  9180. throw new NotFoundHttpException(sprintf('Invalid date given for parameter "%s".'$param));
  9181. }
  9182. } else {
  9183. if (false === strtotime($value)) {
  9184. throw new NotFoundHttpException(sprintf('Invalid date given for parameter "%s".'$param));
  9185. }
  9186. $date = new DateTime($value);
  9187. }
  9188. $request->attributes->set($param$date);
  9189. return true;
  9190. }
  9191. public function supports(ParamConverter $configuration)
  9192. {
  9193. if (null === $configuration->getClass()) {
  9194. return false;
  9195. }
  9196. return'DateTime'=== $configuration->getClass();
  9197. }
  9198. }
  9199. }
  9200. namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
  9201. {
  9202. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9203. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9204. use Symfony\Component\HttpFoundation\Request;
  9205. use Doctrine\Common\Persistence\ManagerRegistry;
  9206. use Doctrine\ORM\NoResultException;
  9207. class DoctrineParamConverter implements ParamConverterInterface
  9208. {
  9209. protected $registry;
  9210. public function __construct(ManagerRegistry $registry null)
  9211. {
  9212. $this->registry $registry;
  9213. }
  9214. public function apply(Request $requestParamConverter $configuration)
  9215. {
  9216. $name $configuration->getName();
  9217. $class $configuration->getClass();
  9218. $options $this->getOptions($configuration);
  9219. if (null === $request->attributes->get($namefalse)) {
  9220. $configuration->setIsOptional(true);
  9221. }
  9222. if (false === $object $this->find($class$request$options$name)) {
  9223. if (false === $object $this->findOneBy($class$request$options)) {
  9224. if ($configuration->isOptional()) {
  9225. $object null;
  9226. } else {
  9227. throw new \LogicException(sprintf('Unable to guess how to get a Doctrine instance from the request information for parameter "%s".'$name));
  9228. }
  9229. }
  9230. }
  9231. if (null === $object && false === $configuration->isOptional()) {
  9232. throw new NotFoundHttpException(sprintf('%s object not found.'$class));
  9233. }
  9234. $request->attributes->set($name$object);
  9235. return true;
  9236. }
  9237. protected function find($classRequest $request$options$name)
  9238. {
  9239. if ($options['mapping'] || $options['exclude']) {
  9240. return false;
  9241. }
  9242. $id $this->getIdentifier($request$options$name);
  9243. if (false === $id || null === $id) {
  9244. return false;
  9245. }
  9246. if (isset($options['repository_method'])) {
  9247. $method $options['repository_method'];
  9248. } else {
  9249. $method ='find';
  9250. }
  9251. try {
  9252. return $this->getManager($options['entity_manager'], $class)->getRepository($class)->$method($id);
  9253. } catch (NoResultException $e) {
  9254. return;
  9255. }
  9256. }
  9257. protected function getIdentifier(Request $request$options$name)
  9258. {
  9259. if (isset($options['id'])) {
  9260. if (!is_array($options['id'])) {
  9261. $name $options['id'];
  9262. } elseif (is_array($options['id'])) {
  9263. $id = array();
  9264. foreach ($options['id'] as $field) {
  9265. $id[$field] = $request->attributes->get($field);
  9266. }
  9267. return $id;
  9268. }
  9269. }
  9270. if ($request->attributes->has($name)) {
  9271. return $request->attributes->get($name);
  9272. }
  9273. if ($request->attributes->has('id') && !isset($options['id'])) {
  9274. return $request->attributes->get('id');
  9275. }
  9276. return false;
  9277. }
  9278. protected function findOneBy($classRequest $request$options)
  9279. {
  9280. if (!$options['mapping']) {
  9281. $keys $request->attributes->keys();
  9282. $options['mapping'] = $keys array_combine($keys$keys) : array();
  9283. }
  9284. foreach ($options['exclude'] as $exclude) {
  9285. unset($options['mapping'][$exclude]);
  9286. }
  9287. if (!$options['mapping']) {
  9288. return false;
  9289. }
  9290. if (isset($options['id']) && null === $request->attributes->get($options['id'])) {
  9291. return false;
  9292. }
  9293. $criteria = array();
  9294. $em $this->getManager($options['entity_manager'], $class);
  9295. $metadata $em->getClassMetadata($class);
  9296. $mapMethodSignature = isset($options['repository_method'])
  9297. && isset($options['map_method_signature'])
  9298. && $options['map_method_signature'] === true;
  9299. foreach ($options['mapping'] as $attribute => $field) {
  9300. if ($metadata->hasField($field)
  9301. || ($metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field))
  9302. || $mapMethodSignature) {
  9303. $criteria[$field] = $request->attributes->get($attribute);
  9304. }
  9305. }
  9306. if ($options['strip_null']) {
  9307. $criteria array_filter($criteria, function ($value) { return !is_null($value); });
  9308. }
  9309. if (!$criteria) {
  9310. return false;
  9311. }
  9312. if (isset($options['repository_method'])) {
  9313. $repositoryMethod $options['repository_method'];
  9314. } else {
  9315. $repositoryMethod ='findOneBy';
  9316. }
  9317. try {
  9318. if ($mapMethodSignature) {
  9319. return $this->findDataByMapMethodSignature($em$class$repositoryMethod$criteria);
  9320. }
  9321. return $em->getRepository($class)->$repositoryMethod($criteria);
  9322. } catch (NoResultException $e) {
  9323. return;
  9324. }
  9325. }
  9326. private function findDataByMapMethodSignature($em$class$repositoryMethod$criteria)
  9327. {
  9328. $arguments = array();
  9329. $repository $em->getRepository($class);
  9330. $ref = new \ReflectionMethod($repository$repositoryMethod);
  9331. foreach ($ref->getParameters() as $parameter) {
  9332. if (array_key_exists($parameter->name$criteria)) {
  9333. $arguments[] = $criteria[$parameter->name];
  9334. } elseif ($parameter->isDefaultValueAvailable()) {
  9335. $arguments[] = $parameter->getDefaultValue();
  9336. } else {
  9337. throw new \InvalidArgumentException(sprintf('Repository method "%s::%s" requires that you provide a value for the "$%s" argument.'get_class($repository), $repositoryMethod$parameter->name));
  9338. }
  9339. }
  9340. return $ref->invokeArgs($repository$arguments);
  9341. }
  9342. public function supports(ParamConverter $configuration)
  9343. {
  9344. if (null === $this->registry || !count($this->registry->getManagers())) {
  9345. return false;
  9346. }
  9347. if (null === $configuration->getClass()) {
  9348. return false;
  9349. }
  9350. $options $this->getOptions($configuration);
  9351. $em $this->getManager($options['entity_manager'], $configuration->getClass());
  9352. if (null === $em) {
  9353. return false;
  9354. }
  9355. return !$em->getMetadataFactory()->isTransient($configuration->getClass());
  9356. }
  9357. protected function getOptions(ParamConverter $configuration)
  9358. {
  9359. return array_replace(array('entity_manager'=> null,'exclude'=> array(),'mapping'=> array(),'strip_null'=> false,
  9360. ), $configuration->getOptions());
  9361. }
  9362. private function getManager($name$class)
  9363. {
  9364. if (null === $name) {
  9365. return $this->registry->getManagerForClass($class);
  9366. }
  9367. return $this->registry->getManager($name);
  9368. }
  9369. }
  9370. }
  9371. namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
  9372. {
  9373. use Symfony\Component\HttpFoundation\Request;
  9374. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
  9375. class ParamConverterManager
  9376. {
  9377. protected $converters = array();
  9378. protected $namedConverters = array();
  9379. public function apply(Request $request$configurations)
  9380. {
  9381. if (is_object($configurations)) {
  9382. $configurations = array($configurations);
  9383. }
  9384. foreach ($configurations as $configuration) {
  9385. $this->applyConverter($request$configuration);
  9386. }
  9387. }
  9388. protected function applyConverter(Request $requestConfigurationInterface $configuration)
  9389. {
  9390. $value $request->attributes->get($configuration->getName());
  9391. $className $configuration->getClass();
  9392. if (is_object($value) && $value instanceof $className) {
  9393. return;
  9394. }
  9395. if ($converterName $configuration->getConverter()) {
  9396. if (!isset($this->namedConverters[$converterName])) {
  9397. throw new \RuntimeException(sprintf("No converter named '%s' found for conversion of parameter '%s'.",
  9398. $converterName$configuration->getName()
  9399. ));
  9400. }
  9401. $converter $this->namedConverters[$converterName];
  9402. if (!$converter->supports($configuration)) {
  9403. throw new \RuntimeException(sprintf("Converter '%s' does not support conversion of parameter '%s'.",
  9404. $converterName$configuration->getName()
  9405. ));
  9406. }
  9407. $converter->apply($request$configuration);
  9408. return;
  9409. }
  9410. foreach ($this->all() as $converter) {
  9411. if ($converter->supports($configuration)) {
  9412. if ($converter->apply($request$configuration)) {
  9413. return;
  9414. }
  9415. }
  9416. }
  9417. }
  9418. public function add(ParamConverterInterface $converter$priority 0$name null)
  9419. {
  9420. if ($priority !== null) {
  9421. if (!isset($this->converters[$priority])) {
  9422. $this->converters[$priority] = array();
  9423. }
  9424. $this->converters[$priority][] = $converter;
  9425. }
  9426. if (null !== $name) {
  9427. $this->namedConverters[$name] = $converter;
  9428. }
  9429. }
  9430. public function all()
  9431. {
  9432. krsort($this->converters);
  9433. $converters = array();
  9434. foreach ($this->converters as $all) {
  9435. $converters array_merge($converters$all);
  9436. }
  9437. return $converters;
  9438. }
  9439. }
  9440. }
  9441. namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
  9442. {
  9443. use Symfony\Component\DependencyInjection\ContainerInterface;
  9444. use Symfony\Component\HttpFoundation\Request;
  9445. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9446. use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
  9447. use Symfony\Component\HttpKernel\KernelEvents;
  9448. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9449. use Symfony\Component\HttpFoundation\StreamedResponse;
  9450. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9451. class TemplateListener implements EventSubscriberInterface
  9452. {
  9453. protected $container;
  9454. public function __construct(ContainerInterface $container)
  9455. {
  9456. $this->container $container;
  9457. }
  9458. public function onKernelController(FilterControllerEvent $event)
  9459. {
  9460. $request $event->getRequest();
  9461. $template $request->attributes->get('_template');
  9462. if (!$template instanceof Template) {
  9463. return;
  9464. }
  9465. $template->setOwner($controller $event->getController());
  9466. if (null === $template->getTemplate()) {
  9467. $guesser $this->container->get('sensio_framework_extra.view.guesser');
  9468. $template->setTemplate($guesser->guessTemplateName($controller$request$template->getEngine()));
  9469. }
  9470. }
  9471. public function onKernelView(GetResponseForControllerResultEvent $event)
  9472. {
  9473. $request $event->getRequest();
  9474. $template $request->attributes->get('_template');
  9475. if (!$template instanceof Template) {
  9476. return;
  9477. }
  9478. $parameters $event->getControllerResult();
  9479. $owner $template->getOwner();
  9480. list($controller$action) = $owner;
  9481. if (null === $parameters) {
  9482. $parameters $this->resolveDefaultParameters($request$template$controller$action);
  9483. }
  9484. $templating $this->container->get('templating');
  9485. if ($template->isStreamable()) {
  9486. $callback = function () use ($templating$template$parameters) {
  9487. return $templating->stream($template->getTemplate(), $parameters);
  9488. };
  9489. $event->setResponse(new StreamedResponse($callback));
  9490. } else {
  9491. $event->setResponse($templating->renderResponse($template->getTemplate(), $parameters));
  9492. }
  9493. $template->setOwner(array());
  9494. }
  9495. public static function getSubscribedEvents()
  9496. {
  9497. return array(
  9498. KernelEvents::CONTROLLER => array('onKernelController', -128),
  9499. KernelEvents::VIEW =>'onKernelView',
  9500. );
  9501. }
  9502. private function resolveDefaultParameters(Request $requestTemplate $template$controller$action)
  9503. {
  9504. $parameters = array();
  9505. $arguments $template->getVars();
  9506. if (=== count($arguments)) {
  9507. $r = new \ReflectionObject($controller);
  9508. $arguments = array();
  9509. foreach ($r->getMethod($action)->getParameters() as $param) {
  9510. $arguments[] = $param;
  9511. }
  9512. }
  9513. foreach ($arguments as $argument) {
  9514. if ($argument instanceof \ReflectionParameter) {
  9515. $parameters[$name $argument->getName()] = !$request->attributes->has($name) && $argument->isDefaultValueAvailable() ? $argument->getDefaultValue() : $request->attributes->get($name);
  9516. } else {
  9517. $parameters[$argument] = $request->attributes->get($argument);
  9518. }
  9519. }
  9520. return $parameters;
  9521. }
  9522. }
  9523. }
  9524. namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
  9525. {
  9526. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9527. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  9528. use Symfony\Component\HttpKernel\KernelEvents;
  9529. use Symfony\Component\HttpFoundation\Response;
  9530. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9531. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  9532. class HttpCacheListener implements EventSubscriberInterface
  9533. {
  9534. private $lastModifiedDates;
  9535. private $etags;
  9536. private $expressionLanguage;
  9537. public function __construct()
  9538. {
  9539. $this->lastModifiedDates = new \SplObjectStorage();
  9540. $this->etags = new \SplObjectStorage();
  9541. }
  9542. public function onKernelController(FilterControllerEvent $event)
  9543. {
  9544. $request $event->getRequest();
  9545. if (!$configuration $request->attributes->get('_cache')) {
  9546. return;
  9547. }
  9548. $response = new Response();
  9549. $lastModifiedDate ='';
  9550. if ($configuration->getLastModified()) {
  9551. $lastModifiedDate $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
  9552. $response->setLastModified($lastModifiedDate);
  9553. }
  9554. $etag ='';
  9555. if ($configuration->getETag()) {
  9556. $etag hash('sha256'$this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
  9557. $response->setETag($etag);
  9558. }
  9559. if ($response->isNotModified($request)) {
  9560. $event->setController(function () use ($response) {
  9561. return $response;
  9562. });
  9563. $event->stopPropagation();
  9564. } else {
  9565. if ($etag) {
  9566. $this->etags[$request] = $etag;
  9567. }
  9568. if ($lastModifiedDate) {
  9569. $this->lastModifiedDates[$request] = $lastModifiedDate;
  9570. }
  9571. }
  9572. }
  9573. public function onKernelResponse(FilterResponseEvent $event)
  9574. {
  9575. $request $event->getRequest();
  9576. if (!$configuration $request->attributes->get('_cache')) {
  9577. return;
  9578. }
  9579. $response $event->getResponse();
  9580. if (!in_array($response->getStatusCode(), array(200203300301302304404410))) {
  9581. return;
  9582. }
  9583. if (null !== $age $configuration->getSMaxAge()) {
  9584. if (!is_numeric($age)) {
  9585. $now microtime(true);
  9586. $age ceil(strtotime($configuration->getSMaxAge(), $now) - $now);
  9587. }
  9588. $response->setSharedMaxAge($age);
  9589. }
  9590. if (null !== $age $configuration->getMaxAge()) {
  9591. if (!is_numeric($age)) {
  9592. $now microtime(true);
  9593. $age ceil(strtotime($configuration->getMaxAge(), $now) - $now);
  9594. }
  9595. $response->setMaxAge($age);
  9596. }
  9597. if (null !== $configuration->getExpires()) {
  9598. $date = \DateTime::createFromFormat('U'strtotime($configuration->getExpires()), new \DateTimeZone('UTC'));
  9599. $response->setExpires($date);
  9600. }
  9601. if (null !== $configuration->getVary()) {
  9602. $response->setVary($configuration->getVary());
  9603. }
  9604. if ($configuration->isPublic()) {
  9605. $response->setPublic();
  9606. }
  9607. if ($configuration->isPrivate()) {
  9608. $response->setPrivate();
  9609. }
  9610. if (isset($this->lastModifiedDates[$request])) {
  9611. $response->setLastModified($this->lastModifiedDates[$request]);
  9612. unset($this->lastModifiedDates[$request]);
  9613. }
  9614. if (isset($this->etags[$request])) {
  9615. $response->setETag($this->etags[$request]);
  9616. unset($this->etags[$request]);
  9617. }
  9618. }
  9619. public static function getSubscribedEvents()
  9620. {
  9621. return array(
  9622. KernelEvents::CONTROLLER =>'onKernelController',
  9623. KernelEvents::RESPONSE =>'onKernelResponse',
  9624. );
  9625. }
  9626. private function getExpressionLanguage()
  9627. {
  9628. if (null === $this->expressionLanguage) {
  9629. if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
  9630. throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
  9631. }
  9632. $this->expressionLanguage = new ExpressionLanguage();
  9633. }
  9634. return $this->expressionLanguage;
  9635. }
  9636. }
  9637. }
  9638. namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
  9639. {
  9640. use Sensio\Bundle\FrameworkExtraBundle\Security\ExpressionLanguage;
  9641. use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
  9642. use Symfony\Component\HttpKernel\KernelEvents;
  9643. use Symfony\Component\HttpFoundation\Request;
  9644. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9645. use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
  9646. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  9647. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  9648. use Symfony\Component\Security\Core\SecurityContextInterface;
  9649. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9650. use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
  9651. class SecurityListener implements EventSubscriberInterface
  9652. {
  9653. private $tokenStorage;
  9654. private $authChecker;
  9655. private $language;
  9656. private $trustResolver;
  9657. private $roleHierarchy;
  9658. public function __construct(SecurityContextInterface $securityContext nullExpressionLanguage $language nullAuthenticationTrustResolverInterface $trustResolver nullRoleHierarchyInterface $roleHierarchy nullTokenStorageInterface $tokenStorage nullAuthorizationCheckerInterface $authChecker null)
  9659. {
  9660. $this->tokenStorage $tokenStorage ?: $securityContext;
  9661. $this->authChecker $authChecker ?: $securityContext;
  9662. $this->language $language;
  9663. $this->trustResolver $trustResolver;
  9664. $this->roleHierarchy $roleHierarchy;
  9665. }
  9666. public function onKernelController(FilterControllerEvent $event)
  9667. {
  9668. $request $event->getRequest();
  9669. if (!$configuration $request->attributes->get('_security')) {
  9670. return;
  9671. }
  9672. if (null === $this->tokenStorage || null === $this->trustResolver) {
  9673. throw new \LogicException('To use the @Security tag, you need to install the Symfony Security bundle.');
  9674. }
  9675. if (null === $this->tokenStorage->getToken()) {
  9676. throw new \LogicException('To use the @Security tag, your controller needs to be behind a firewall.');
  9677. }
  9678. if (null === $this->language) {
  9679. throw new \LogicException('To use the @Security tag, you need to use the Security component 2.4 or newer and install the ExpressionLanguage component.');
  9680. }
  9681. if (!$this->language->evaluate($configuration->getExpression(), $this->getVariables($request))) {
  9682. throw new AccessDeniedException(sprintf('Expression "%s" denied access.'$configuration->getExpression()));
  9683. }
  9684. }
  9685. private function getVariables(Request $request)
  9686. {
  9687. $token $this->tokenStorage->getToken();
  9688. if (null !== $this->roleHierarchy) {
  9689. $roles $this->roleHierarchy->getReachableRoles($token->getRoles());
  9690. } else {
  9691. $roles $token->getRoles();
  9692. }
  9693. $variables = array('token'=> $token,'user'=> $token->getUser(),'object'=> $request,'subject'=> $request,'request'=> $request,'roles'=> array_map(function ($role) { return $role->getRole(); }, $roles),'trust_resolver'=> $this->trustResolver,'auth_checker'=> $this->authChecker,
  9694. );
  9695. return array_merge($request->attributes->all(), $variables);
  9696. }
  9697. public static function getSubscribedEvents()
  9698. {
  9699. return array(KernelEvents::CONTROLLER =>'onKernelController');
  9700. }
  9701. }
  9702. }
  9703. namespace Sensio\Bundle\FrameworkExtraBundle\Configuration
  9704. {
  9705. interface ConfigurationInterface
  9706. {
  9707. public function getAliasName();
  9708. public function allowArray();
  9709. }
  9710. }
  9711. namespace Sensio\Bundle\FrameworkExtraBundle\Configuration
  9712. {
  9713. abstract class ConfigurationAnnotation implements ConfigurationInterface
  9714. {
  9715. public function __construct(array $values)
  9716. {
  9717. foreach ($values as $k => $v) {
  9718. if (!method_exists($this$name ='set'.$k)) {
  9719. throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".'$kget_class($this)));
  9720. }
  9721. $this->$name($v);
  9722. }
  9723. }
  9724. }
  9725. }