/app/cache/dev/classes.php
PHP | 6561 lines | 6561 code | 0 blank | 0 comment | 805 complexity | e291ed3e9004544c91b622b84b29463a MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- namespace Symfony\Component\EventDispatcher
- {
- interface EventSubscriberInterface
- {
- public static function getSubscribedEvents();
- }
- }
- namespace Symfony\Component\HttpKernel\EventListener
- {
- use Symfony\Component\HttpKernel\Event\GetResponseEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- abstract class SessionListener implements EventSubscriberInterface
- {
- public function onKernelRequest(GetResponseEvent $event)
- {
- if (!$event->isMasterRequest()) {
- return;
- }
- $request = $event->getRequest();
- $session = $this->getSession();
- if (null === $session || $request->hasSession()) {
- return;
- }
- $request->setSession($session);
- }
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::REQUEST => array('onKernelRequest', 128),
- );
- }
- abstract protected function getSession();
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\EventListener
- {
- use Symfony\Component\HttpKernel\EventListener\SessionListener as BaseSessionListener;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class SessionListener extends BaseSessionListener
- {
- private $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- }
- protected function getSession()
- {
- if (!$this->container->has('session')) {
- return;
- }
- return $this->container->get('session');
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage
- {
- use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
- interface SessionStorageInterface
- {
- public function start();
- public function isStarted();
- public function getId();
- public function setId($id);
- public function getName();
- public function setName($name);
- public function regenerate($destroy = false, $lifetime = null);
- public function save();
- public function clear();
- public function getBag($name);
- public function registerBag(SessionBagInterface $bag);
- public function getMetadataBag();
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage
- {
- use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
- use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
- use Symfony\Component\HttpFoundation\Session\Storage\Proxy\NativeProxy;
- use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
- use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
- class NativeSessionStorage implements SessionStorageInterface
- {
- protected $bags;
- protected $started = false;
- protected $closed = false;
- protected $saveHandler;
- protected $metadataBag;
- public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
- {
- session_cache_limiter(''); ini_set('session.use_cookies', 1);
- if (version_compare(phpversion(),'5.4.0','>=')) {
- session_register_shutdown();
- } else {
- register_shutdown_function('session_write_close');
- }
- $this->setMetadataBag($metaBag);
- $this->setOptions($options);
- $this->setSaveHandler($handler);
- }
- public function getSaveHandler()
- {
- return $this->saveHandler;
- }
- public function start()
- {
- if ($this->started && !$this->closed) {
- return true;
- }
- if (version_compare(phpversion(),'5.4.0','>=') && \PHP_SESSION_ACTIVE === session_status()) {
- throw new \RuntimeException('Failed to start the session: already started by PHP.');
- }
- if (version_compare(phpversion(),'5.4.0','<') && isset($_SESSION) && session_id()) {
- throw new \RuntimeException('Failed to start the session: already started by PHP ($_SESSION is set).');
- }
- if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
- throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
- }
- if (!session_start()) {
- throw new \RuntimeException('Failed to start the session');
- }
- $this->loadSession();
- if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
- $this->saveHandler->setActive(true);
- }
- return true;
- }
- public function getId()
- {
- if (!$this->started && !$this->closed) {
- return''; }
- return $this->saveHandler->getId();
- }
- public function setId($id)
- {
- $this->saveHandler->setId($id);
- }
- public function getName()
- {
- return $this->saveHandler->getName();
- }
- public function setName($name)
- {
- $this->saveHandler->setName($name);
- }
- public function regenerate($destroy = false, $lifetime = null)
- {
- if (null !== $lifetime) {
- ini_set('session.cookie_lifetime', $lifetime);
- }
- if ($destroy) {
- $this->metadataBag->stampNew();
- }
- $ret = session_regenerate_id($destroy);
- if ('files'=== $this->getSaveHandler()->getSaveHandlerName()) {
- session_write_close();
- if (isset($_SESSION)) {
- $backup = $_SESSION;
- session_start();
- $_SESSION = $backup;
- } else {
- session_start();
- }
- $this->loadSession();
- }
- return $ret;
- }
- public function save()
- {
- session_write_close();
- if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
- $this->saveHandler->setActive(false);
- }
- $this->closed = true;
- $this->started = false;
- }
- public function clear()
- {
- foreach ($this->bags as $bag) {
- $bag->clear();
- }
- $_SESSION = array();
- $this->loadSession();
- }
- public function registerBag(SessionBagInterface $bag)
- {
- $this->bags[$bag->getName()] = $bag;
- }
- public function getBag($name)
- {
- if (!isset($this->bags[$name])) {
- throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name));
- }
- if ($this->saveHandler->isActive() && !$this->started) {
- $this->loadSession();
- } elseif (!$this->started) {
- $this->start();
- }
- return $this->bags[$name];
- }
- public function setMetadataBag(MetadataBag $metaBag = null)
- {
- if (null === $metaBag) {
- $metaBag = new MetadataBag();
- }
- $this->metadataBag = $metaBag;
- }
- public function getMetadataBag()
- {
- return $this->metadataBag;
- }
- public function isStarted()
- {
- return $this->started;
- }
- public function setOptions(array $options)
- {
- $validOptions = array_flip(array('cache_limiter','cookie_domain','cookie_httponly','cookie_lifetime','cookie_path','cookie_secure','entropy_file','entropy_length','gc_divisor','gc_maxlifetime','gc_probability','hash_bits_per_character','hash_function','name','referer_check','serialize_handler','use_cookies','use_only_cookies','use_trans_sid','upload_progress.enabled','upload_progress.cleanup','upload_progress.prefix','upload_progress.name','upload_progress.freq','upload_progress.min-freq','url_rewriter.tags',
- ));
- foreach ($options as $key => $value) {
- if (isset($validOptions[$key])) {
- ini_set('session.'.$key, $value);
- }
- }
- }
- public function setSaveHandler($saveHandler = null)
- {
- if (!$saveHandler instanceof AbstractProxy &&
- !$saveHandler instanceof NativeSessionHandler &&
- !$saveHandler instanceof \SessionHandlerInterface &&
- null !== $saveHandler) {
- throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
- }
- if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
- $saveHandler = new SessionHandlerProxy($saveHandler);
- } elseif (!$saveHandler instanceof AbstractProxy) {
- $saveHandler = version_compare(phpversion(),'5.4.0','>=') ?
- new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy();
- }
- $this->saveHandler = $saveHandler;
- if ($this->saveHandler instanceof \SessionHandlerInterface) {
- if (version_compare(phpversion(),'5.4.0','>=')) {
- session_set_save_handler($this->saveHandler, false);
- } else {
- session_set_save_handler(
- array($this->saveHandler,'open'),
- array($this->saveHandler,'close'),
- array($this->saveHandler,'read'),
- array($this->saveHandler,'write'),
- array($this->saveHandler,'destroy'),
- array($this->saveHandler,'gc')
- );
- }
- }
- }
- protected function loadSession(array &$session = null)
- {
- if (null === $session) {
- $session = &$_SESSION;
- }
- $bags = array_merge($this->bags, array($this->metadataBag));
- foreach ($bags as $bag) {
- $key = $bag->getStorageKey();
- $session[$key] = isset($session[$key]) ? $session[$key] : array();
- $bag->initialize($session[$key]);
- }
- $this->started = true;
- $this->closed = false;
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage
- {
- use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
- use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
- class PhpBridgeSessionStorage extends NativeSessionStorage
- {
- public function __construct($handler = null, MetadataBag $metaBag = null)
- {
- $this->setMetadataBag($metaBag);
- $this->setSaveHandler($handler);
- }
- public function start()
- {
- if ($this->started && !$this->closed) {
- return true;
- }
- $this->loadSession();
- if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
- $this->saveHandler->setActive(true);
- }
- return true;
- }
- public function clear()
- {
- foreach ($this->bags as $bag) {
- $bag->clear();
- }
- $this->loadSession();
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
- {
- if (version_compare(phpversion(),'5.4.0','>=')) {
- class NativeSessionHandler extends \SessionHandler
- {
- }
- } else {
- class NativeSessionHandler
- {
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage\Handler
- {
- class NativeFileSessionHandler extends NativeSessionHandler
- {
- public function __construct($savePath = null)
- {
- if (null === $savePath) {
- $savePath = ini_get('session.save_path');
- }
- $baseDir = $savePath;
- if ($count = substr_count($savePath,';')) {
- if ($count > 2) {
- throw new \InvalidArgumentException(sprintf('Invalid argument $savePath \'%s\'', $savePath));
- }
- $baseDir = ltrim(strrchr($savePath,';'),';');
- }
- if ($baseDir && !is_dir($baseDir)) {
- mkdir($baseDir, 0777, true);
- }
- ini_set('session.save_path', $savePath);
- ini_set('session.save_handler','files');
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
- {
- abstract class AbstractProxy
- {
- protected $wrapper = false;
- protected $active = false;
- protected $saveHandlerName;
- public function getSaveHandlerName()
- {
- return $this->saveHandlerName;
- }
- public function isSessionHandlerInterface()
- {
- return ($this instanceof \SessionHandlerInterface);
- }
- public function isWrapper()
- {
- return $this->wrapper;
- }
- public function isActive()
- {
- if (version_compare(phpversion(),'5.4.0','>=')) {
- return $this->active = \PHP_SESSION_ACTIVE === session_status();
- }
- return $this->active;
- }
- public function setActive($flag)
- {
- if (version_compare(phpversion(),'5.4.0','>=')) {
- throw new \LogicException('This method is disabled in PHP 5.4.0+');
- }
- $this->active = (bool) $flag;
- }
- public function getId()
- {
- return session_id();
- }
- public function setId($id)
- {
- if ($this->isActive()) {
- throw new \LogicException('Cannot change the ID of an active session');
- }
- session_id($id);
- }
- public function getName()
- {
- return session_name();
- }
- public function setName($name)
- {
- if ($this->isActive()) {
- throw new \LogicException('Cannot change the name of an active session');
- }
- session_name($name);
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy
- {
- class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
- {
- protected $handler;
- public function __construct(\SessionHandlerInterface $handler)
- {
- $this->handler = $handler;
- $this->wrapper = ($handler instanceof \SessionHandler);
- $this->saveHandlerName = $this->wrapper ? ini_get('session.save_handler') :'user';
- }
- public function open($savePath, $sessionName)
- {
- $return = (bool) $this->handler->open($savePath, $sessionName);
- if (true === $return) {
- $this->active = true;
- }
- return $return;
- }
- public function close()
- {
- $this->active = false;
- return (bool) $this->handler->close();
- }
- public function read($sessionId)
- {
- return (string) $this->handler->read($sessionId);
- }
- public function write($sessionId, $data)
- {
- return (bool) $this->handler->write($sessionId, $data);
- }
- public function destroy($sessionId)
- {
- return (bool) $this->handler->destroy($sessionId);
- }
- public function gc($maxlifetime)
- {
- return (bool) $this->handler->gc($maxlifetime);
- }
- }
- }
- namespace Symfony\Component\HttpFoundation\Session
- {
- use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
- interface SessionInterface
- {
- public function start();
- public function getId();
- public function setId($id);
- public function getName();
- public function setName($name);
- public function invalidate($lifetime = null);
- public function migrate($destroy = false, $lifetime = null);
- public function save();
- public function has($name);
- public function get($name, $default = null);
- public function set($name, $value);
- public function all();
- public function replace(array $attributes);
- public function remove($name);
- public function clear();
- public function isStarted();
- public function registerBag(SessionBagInterface $bag);
- public function getBag($name);
- public function getMetadataBag();
- }
- }
- namespace Symfony\Component\HttpFoundation\Session
- {
- use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
- use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
- use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
- use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
- use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
- use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
- class Session implements SessionInterface, \IteratorAggregate, \Countable
- {
- protected $storage;
- private $flashName;
- private $attributeName;
- public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
- {
- $this->storage = $storage ?: new NativeSessionStorage();
- $attributes = $attributes ?: new AttributeBag();
- $this->attributeName = $attributes->getName();
- $this->registerBag($attributes);
- $flashes = $flashes ?: new FlashBag();
- $this->flashName = $flashes->getName();
- $this->registerBag($flashes);
- }
- public function start()
- {
- return $this->storage->start();
- }
- public function has($name)
- {
- return $this->storage->getBag($this->attributeName)->has($name);
- }
- public function get($name, $default = null)
- {
- return $this->storage->getBag($this->attributeName)->get($name, $default);
- }
- public function set($name, $value)
- {
- $this->storage->getBag($this->attributeName)->set($name, $value);
- }
- public function all()
- {
- return $this->storage->getBag($this->attributeName)->all();
- }
- public function replace(array $attributes)
- {
- $this->storage->getBag($this->attributeName)->replace($attributes);
- }
- public function remove($name)
- {
- return $this->storage->getBag($this->attributeName)->remove($name);
- }
- public function clear()
- {
- $this->storage->getBag($this->attributeName)->clear();
- }
- public function isStarted()
- {
- return $this->storage->isStarted();
- }
- public function getIterator()
- {
- return new \ArrayIterator($this->storage->getBag($this->attributeName)->all());
- }
- public function count()
- {
- return count($this->storage->getBag($this->attributeName)->all());
- }
- public function invalidate($lifetime = null)
- {
- $this->storage->clear();
- return $this->migrate(true, $lifetime);
- }
- public function migrate($destroy = false, $lifetime = null)
- {
- return $this->storage->regenerate($destroy, $lifetime);
- }
- public function save()
- {
- $this->storage->save();
- }
- public function getId()
- {
- return $this->storage->getId();
- }
- public function setId($id)
- {
- $this->storage->setId($id);
- }
- public function getName()
- {
- return $this->storage->getName();
- }
- public function setName($name)
- {
- $this->storage->setName($name);
- }
- public function getMetadataBag()
- {
- return $this->storage->getMetadataBag();
- }
- public function registerBag(SessionBagInterface $bag)
- {
- $this->storage->registerBag($bag);
- }
- public function getBag($name)
- {
- return $this->storage->getBag($name);
- }
- public function getFlashBag()
- {
- return $this->getBag($this->flashName);
- }
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Templating
- {
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\HttpFoundation\Session\Session;
- use Symfony\Component\Security\Core\SecurityContext;
- use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
- use Symfony\Component\HttpFoundation\Request;
- class GlobalVariables
- {
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- }
- public function getSecurity()
- {
- if ($this->container->has('security.context')) {
- return $this->container->get('security.context');
- }
- }
- public function getUser()
- {
- if (!$security = $this->getSecurity()) {
- return;
- }
- if (!$token = $security->getToken()) {
- return;
- }
- $user = $token->getUser();
- if (!is_object($user)) {
- return;
- }
- return $user;
- }
- public function getRequest()
- {
- if ($this->container->has('request_stack')) {
- return $this->container->get('request_stack')->getCurrentRequest();
- }
- }
- public function getSession()
- {
- if ($request = $this->getRequest()) {
- return $request->getSession();
- }
- }
- public function getEnvironment()
- {
- return $this->container->getParameter('kernel.environment');
- }
- public function getDebug()
- {
- return (bool) $this->container->getParameter('kernel.debug');
- }
- }
- }
- namespace Symfony\Component\Templating
- {
- interface TemplateReferenceInterface
- {
- public function all();
- public function set($name, $value);
- public function get($name);
- public function getPath();
- public function getLogicalName();
- public function __toString();
- }
- }
- namespace Symfony\Component\Templating
- {
- class TemplateReference implements TemplateReferenceInterface
- {
- protected $parameters;
- public function __construct($name = null, $engine = null)
- {
- $this->parameters = array('name'=> $name,'engine'=> $engine,
- );
- }
- public function __toString()
- {
- return $this->getLogicalName();
- }
- public function set($name, $value)
- {
- if (array_key_exists($name, $this->parameters)) {
- $this->parameters[$name] = $value;
- } else {
- throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
- }
- return $this;
- }
- public function get($name)
- {
- if (array_key_exists($name, $this->parameters)) {
- return $this->parameters[$name];
- }
- throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
- }
- public function all()
- {
- return $this->parameters;
- }
- public function getPath()
- {
- return $this->parameters['name'];
- }
- public function getLogicalName()
- {
- return $this->parameters['name'];
- }
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Templating
- {
- use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
- class TemplateReference extends BaseTemplateReference
- {
- public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
- {
- $this->parameters = array('bundle'=> $bundle,'controller'=> $controller,'name'=> $name,'format'=> $format,'engine'=> $engine,
- );
- }
- public function getPath()
- {
- $controller = str_replace('\\','/', $this->get('controller'));
- $path = (empty($controller) ?'': $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
- return empty($this->parameters['bundle']) ?'views/'.$path :'@'.$this->get('bundle').'/Resources/views/'.$path;
- }
- public function getLogicalName()
- {
- return sprintf('%s:%s:%s.%s.%s', $this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
- }
- }
- }
- namespace Symfony\Component\Templating
- {
- interface TemplateNameParserInterface
- {
- public function parse($name);
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Templating
- {
- use Symfony\Component\Templating\TemplateNameParserInterface;
- use Symfony\Component\Templating\TemplateReferenceInterface;
- use Symfony\Component\HttpKernel\KernelInterface;
- class TemplateNameParser implements TemplateNameParserInterface
- {
- protected $kernel;
- protected $cache = array();
- public function __construct(KernelInterface $kernel)
- {
- $this->kernel = $kernel;
- }
- public function parse($name)
- {
- if ($name instanceof TemplateReferenceInterface) {
- return $name;
- } elseif (isset($this->cache[$name])) {
- return $this->cache[$name];
- }
- $name = str_replace(':/',':', preg_replace('#/{2,}#','/', strtr($name,'\\','/')));
- if (false !== strpos($name,'..')) {
- throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
- }
- if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
- throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
- }
- $template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);
- if ($template->get('bundle')) {
- try {
- $this->kernel->getBundle($template->get('bundle'));
- } catch (\Exception $e) {
- throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
- }
- }
- return $this->cache[$name] = $template;
- }
- }
- }
- namespace Symfony\Component\Config
- {
- interface FileLocatorInterface
- {
- public function locate($name, $currentPath = null, $first = true);
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Templating\Loader
- {
- use Symfony\Component\Config\FileLocatorInterface;
- use Symfony\Component\Templating\TemplateReferenceInterface;
- class TemplateLocator implements FileLocatorInterface
- {
- protected $locator;
- protected $cache;
- public function __construct(FileLocatorInterface $locator, $cacheDir = null)
- {
- if (null !== $cacheDir && is_file($cache = $cacheDir.'/templates.php')) {
- $this->cache = require $cache;
- }
- $this->locator = $locator;
- }
- protected function getCacheKey($template)
- {
- return $template->getLogicalName();
- }
- public function locate($template, $currentPath = null, $first = true)
- {
- if (!$template instanceof TemplateReferenceInterface) {
- throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
- }
- $key = $this->getCacheKey($template);
- if (isset($this->cache[$key])) {
- return $this->cache[$key];
- }
- try {
- return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
- } catch (\InvalidArgumentException $e) {
- throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
- }
- }
- }
- }
- namespace Symfony\Component\Routing
- {
- interface RequestContextAwareInterface
- {
- public function setContext(RequestContext $context);
- public function getContext();
- }
- }
- namespace Symfony\Component\Routing\Generator
- {
- use Symfony\Component\Routing\Exception\InvalidParameterException;
- use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
- use Symfony\Component\Routing\Exception\RouteNotFoundException;
- use Symfony\Component\Routing\RequestContextAwareInterface;
- interface UrlGeneratorInterface extends RequestContextAwareInterface
- {
- const ABSOLUTE_URL = true;
- const ABSOLUTE_PATH = false;
- const RELATIVE_PATH ='relative';
- const NETWORK_PATH ='network';
- public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH);
- }
- }
- namespace Symfony\Component\Routing\Generator
- {
- interface ConfigurableRequirementsInterface
- {
- public function setStrictRequirements($enabled);
- public function isStrictRequirements();
- }
- }
- namespace Symfony\Component\Routing\Generator
- {
- use Symfony\Component\Routing\RouteCollection;
- use Symfony\Component\Routing\RequestContext;
- use Symfony\Component\Routing\Exception\InvalidParameterException;
- use Symfony\Component\Routing\Exception\RouteNotFoundException;
- use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
- use Psr\Log\LoggerInterface;
- class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface
- {
- protected $routes;
- protected $context;
- protected $strictRequirements = true;
- protected $logger;
- protected $decodedChars = array('%2F'=>'/','%40'=>'@','%3A'=>':','%3B'=>';','%2C'=>',','%3D'=>'=','%2B'=>'+','%21'=>'!','%2A'=>'*','%7C'=>'|',
- );
- public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null)
- {
- $this->routes = $routes;
- $this->context = $context;
- $this->logger = $logger;
- }
- public function setContext(RequestContext $context)
- {
- $this->context = $context;
- }
- public function getContext()
- {
- return $this->context;
- }
- public function setStrictRequirements($enabled)
- {
- $this->strictRequirements = null === $enabled ? null : (bool) $enabled;
- }
- public function isStrictRequirements()
- {
- return $this->strictRequirements;
- }
- public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
- {
- if (null === $route = $this->routes->get($name)) {
- throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
- }
- $compiledRoute = $route->compile();
- return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), $route->getSchemes());
- }
- protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
- {
- $variables = array_flip($variables);
- $mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
- if ($diff = array_diff_key($variables, $mergedParams)) {
- throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', array_keys($diff)), $name));
- }
- $url ='';
- $optional = true;
- foreach ($tokens as $token) {
- if ('variable'=== $token[0]) {
- if (!$optional || !array_key_exists($token[3], $defaults) || null !== $mergedParams[$token[3]] && (string) $mergedParams[$token[3]] !== (string) $defaults[$token[3]]) {
- if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
- $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
- if ($this->strictRequirements) {
- throw new InvalidParameterException($message);
- }
- if ($this->logger) {
- $this->logger->error($message);
- }
- return;
- }
- $url = $token[1].$mergedParams[$token[3]].$url;
- $optional = false;
- }
- } else {
- $url = $token[1].$url;
- $optional = false;
- }
- }
- if (''=== $url) {
- $url ='/';
- }
- $url = strtr(rawurlencode($url), $this->decodedChars);
- $url = strtr($url, array('/../'=>'/%2E%2E/','/./'=>'/%2E/'));
- if ('/..'=== substr($url, -3)) {
- $url = substr($url, 0, -2).'%2E%2E';
- } elseif ('/.'=== substr($url, -2)) {
- $url = substr($url, 0, -1).'%2E';
- }
- $schemeAuthority ='';
- if ($host = $this->context->getHost()) {
- $scheme = $this->context->getScheme();
- if ($requiredSchemes) {
- $schemeMatched = false;
- foreach ($requiredSchemes as $requiredScheme) {
- if ($scheme === $requiredScheme) {
- $schemeMatched = true;
- break;
- }
- }
- if (!$schemeMatched) {
- $referenceType = self::ABSOLUTE_URL;
- $scheme = current($requiredSchemes);
- }
- } elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
- $referenceType = self::ABSOLUTE_URL;
- $scheme = $req;
- }
- if ($hostTokens) {
- $routeHost ='';
- foreach ($hostTokens as $token) {
- if ('variable'=== $token[0]) {
- if (null !== $this->strictRequirements && !preg_match('#^'.$token[2].'$#', $mergedParams[$token[3]])) {
- $message = sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given) to generate a corresponding URL.', $token[3], $name, $token[2], $mergedParams[$token[3]]);
- if ($this->strictRequirements) {
- throw new InvalidParameterException($message);
- }
- if ($this->logger) {
- $this->logger->error($message);
- }
- return;
- }
- $routeHost = $token[1].$mergedParams[$token[3]].$routeHost;
- } else {
- $routeHost = $token[1].$routeHost;
- }
- }
- if ($routeHost !== $host) {
- $host = $routeHost;
- if (self::ABSOLUTE_URL !== $referenceType) {
- $referenceType = self::NETWORK_PATH;
- }
- }
- }
- if (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType) {
- $port ='';
- if ('http'=== $scheme && 80 != $this->context->getHttpPort()) {
- $port =':'.$this->context->getHttpPort();
- } elseif ('https'=== $scheme && 443 != $this->context->getHttpsPort()) {
- $port =':'.$this->context->getHttpsPort();
- }
- $schemeAuthority = self::NETWORK_PATH === $referenceType ?'//': "$scheme://";
- $schemeAuthority .= $host.$port;
- }
- }
- if (self::RELATIVE_PATH === $referenceType) {
- $url = self::getRelativePath($this->context->getPathInfo(), $url);
- } else {
- $url = $schemeAuthority.$this->context->getBaseUrl().$url;
- }
- $extra = array_diff_key($parameters, $variables, $defaults);
- if ($extra && $query = http_build_query($extra,'','&')) {
- $url .='?'.$query;
- }
- return $url;
- }
- public static function getRelativePath($basePath, $targetPath)
- {
- if ($basePath === $targetPath) {
- return'';
- }
- $sourceDirs = explode('/', isset($basePath[0]) &&'/'=== $basePath[0] ? substr($basePath, 1) : $basePath);
- $targetDirs = explode('/', isset($targetPath[0]) &&'/'=== $targetPath[0] ? substr($targetPath, 1) : $targetPath);
- array_pop($sourceDirs);
- $targetFile = array_pop($targetDirs);
- foreach ($sourceDirs as $i => $dir) {
- if (isset($targetDirs[$i]) && $dir === $targetDirs[$i]) {
- unset($sourceDirs[$i], $targetDirs[$i]);
- } else {
- break;
- }
- }
- $targetDirs[] = $targetFile;
- $path = str_repeat('../', count($sourceDirs)).implode('/', $targetDirs);
- return''=== $path ||'/'=== $path[0]
- || false !== ($colonPos = strpos($path,':')) && ($colonPos < ($slashPos = strpos($path,'/')) || false === $slashPos)
- ? "./$path" : $path;
- }
- }
- }
- namespace Symfony\Component\Routing
- {
- use Symfony\Component\HttpFoundation\Request;
- class RequestContext
- {
- private $baseUrl;
- private $pathInfo;
- private $method;
- private $host;
- private $scheme;
- private $httpPort;
- private $httpsPort;
- private $queryString;
- private $parameters = array();
- public function __construct($baseUrl ='', $method ='GET', $host ='localhost', $scheme ='http', $httpPort = 80, $httpsPort = 443, $path ='/', $queryString ='')
- {
- $this->baseUrl = $baseUrl;
- $this->method = strtoupper($method);
- $this->host = $host;
- $this->scheme = strtolower($scheme);
- $this->httpPort = $httpPort;
- $this->httpsPort = $httpsPort;
- $this->pathInfo = $path;
- $this->queryString = $queryString;
- }
- public function fromRequest(Request $request)
- {
- $this->setBaseUrl($request->getBaseUrl());
- $this->setPathInfo($request->getPathInfo());
- $this->setMethod($request->getMethod());
- $this->setHost($request->getHost());
- $this->setScheme($request->getScheme());
- $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
- $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
- $this->setQueryString($request->server->get('QUERY_STRING'));
- }
- public function getBaseUrl()
- {
- return $this->baseUrl;
- }
- public function setBaseUrl($baseUrl)
- {
- $this->baseUrl = $baseUrl;
- }
- public function getPathInfo()
- {
- return $this->pathInfo;
- }
- public function setPathInfo($pathInfo)
- {
- $this->pathInfo = $pathInfo;
- }
- public function getMethod()
- {
- return $this->method;
- }
- public function setMethod($method)
- {
- $this->method = strtoupper($method);
- }
- public function getHost()
- {
- return $this->host;
- }
- public function setHost($host)
- {
- $this->host = $host;
- }
- public function getScheme()
- {
- return $this->scheme;
- }
- public function setScheme($scheme)
- {
- $this->scheme = strtolower($scheme);
- }
- public function getHttpPort()
- {
- return $this->httpPort;
- }
- public function setHttpPort($httpPort)
- {
- $this->httpPort = $httpPort;
- }
- public function getHttpsPort()
- {
- return $this->httpsPort;
- }
- public function setHttpsPort($httpsPort)
- {
- $this->httpsPort = $httpsPort;
- }
- public function getQueryString()
- {
- return $this->queryString;
- }
- public function setQueryString($queryString)
- {
- $this->queryString = $queryString;
- }
- public function getParameters()
- {
- return $this->parameters;
- }
- public function setParameters(array $parameters)
- {
- $this->parameters = $parameters;
- return $this;
- }
- public function getParameter($name)
- {
- return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
- }
- public function hasParameter($name)
- {
- return array_key_exists($name, $this->parameters);
- }
- public function setParameter($name, $parameter)
- {
- $this->parameters[$name] = $parameter;
- }
- }
- }
- namespace Symfony\Component\Routing\Matcher
- {
- use Symfony\Component\Routing\RequestContextAwareInterface;
- use Symfony\Component\Routing\Exception\ResourceNotFoundException;
- use Symfony\Component\Routing\Exception\MethodNotAllowedException;
- interface UrlMatcherInterface extends RequestContextAwareInterface
- {
- public function match($pathinfo);
- }
- }
- namespace Symfony\Component\Routing
- {
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
- interface RouterInterface extends UrlMatcherInterface, UrlGeneratorInterface
- {
- public function getRouteCollection();
- }
- }
- namespace Symfony\Component\Routing\Matcher
- {
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Routing\Exception\ResourceNotFoundException;
- use Symfony\Component\Routing\Exception\MethodNotAllowedException;
- interface RequestMatcherInterface
- {
- public function matchRequest(Request $request);
- }
- }
- namespace Symfony\Component\Routing
- {
- use Symfony\Component\Config\Loader\LoaderInterface;
- use Symfony\Component\Config\ConfigCache;
- use Psr\Log\LoggerInterface;
- use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
- use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
- use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
- use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
- use Symfony\Component\HttpFoundation\Request;
- class Router implements RouterInterface, RequestMatcherInterface
- {
- protected $matcher;
- protected $generator;
- protected $context;
- protected $loader;
- protected $collection;
- protected $resource;
- protected $options = array();
- protected $logger;
- public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null)
- {
- $this->loader = $loader;
- $this->resource = $resource;
- $this->logger = $logger;
- $this->context = $context ?: new RequestContext();
- $this->setOptions($options);
- }
- public function setOptions(array $options)
- {
- $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,
- );
- $invalid = array();
- foreach ($options as $key => $value) {
- if (array_key_exists($key, $this->options)) {
- $this->options[$key] = $value;
- } else {
- $invalid[] = $key;
- }
- }
- if ($invalid) {
- throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('", "', $invalid)));
- }
- }
- public function setOption($key, $value)
- {
- if (!array_key_exists($key, $this->options)) {
- throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
- }
- $this->options[$key] = $value;
- }
- public function getOption($key)
- {
- if (!array_key_exists($key, $this->options)) {
- throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
- }
- return $this->options[$key];
- }
- public function getRouteCollection()
- {
- if (null === $this->collection) {
- $this->collection = $this->loader->load($this->resource, $this->options['resource_type']);
- }
- return $this->collection;
- }
- public function setContext(RequestContext $context)
- {
- $this->context = $context;
- if (null !== $this->matcher) {
- $this->getMatcher()->setContext($context);
- }
- if (null !== $this->generator) {
- $this->getGenerator()->setContext($context);
- }
- }
- public function getContext()
- {
- return $this->context;
- }
- public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
- {
- return $this->getGenerator()->generate($name, $parameters, $referenceType);
- }
- public function match($pathinfo)
- {
- return $this->getMatcher()->match($pathinfo);
- }
- public function matchRequest(Request $request)
- {
- $matcher = $this->getMatcher();
- if (!$matcher instanceof RequestMatcherInterface) {
- return $matcher->match($request->getPathInfo());
- }
- return $matcher->matchRequest($request);
- }
- public function getMatcher()
- {
- if (null !== $this->matcher) {
- return $this->matcher;
- }
- if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
- return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context);
- }
- $class = $this->options['matcher_cache_class'];
- $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
- if (!$cache->isFresh()) {
- $dumper = $this->getMatcherDumperInstance();
- $options = array('class'=> $class,'base_class'=> $this->options['matcher_base_class'],
- );
- $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
- }
- require_once $cache;
- return $this->matcher = new $class($this->context);
- }
- public function getGenerator()
- {
- if (null !== $this->generator) {
- return $this->generator;
- }
- if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
- $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->logger);
- } else {
- $class = $this->options['generator_cache_class'];
- $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
- if (!$cache->isFresh()) {
- $dumper = $this->getGeneratorDumperInstance();
- $options = array('class'=> $class,'base_class'=> $this->options['generator_base_class'],
- );
- $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
- }
- require_once $cache;
- $this->generator = new $class($this->context, $this->logger);
- }
- if ($this->generator instanceof ConfigurableRequirementsInterface) {
- $this->generator->setStrictRequirements($this->options['strict_requirements']);
- }
- return $this->generator;
- }
- protected function getGeneratorDumperInstance()
- {
- return new $this->options['generator_dumper_class']($this->getRouteCollection());
- }
- protected function getMatcherDumperInstance()
- {
- return new $this->options['matcher_dumper_class']($this->getRouteCollection());
- }
- }
- }
- namespace Symfony\Component\Routing\Matcher
- {
- interface RedirectableUrlMatcherInterface
- {
- public function redirect($path, $route, $scheme = null);
- }
- }
- namespace Symfony\Component\Routing\Matcher
- {
- use Symfony\Component\Routing\Exception\MethodNotAllowedException;
- use Symfony\Component\Routing\Exception\ResourceNotFoundException;
- use Symfony\Component\Routing\RouteCollection;
- use Symfony\Component\Routing\RequestContext;
- use Symfony\Component\Routing\Route;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
- class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
- {
- const REQUIREMENT_MATCH = 0;
- const REQUIREMENT_MISMATCH = 1;
- const ROUTE_MATCH = 2;
- protected $context;
- protected $allow = array();
- protected $routes;
- protected $request;
- protected $expressionLanguage;
- public function __construct(RouteCollection $routes, RequestContext $context)
- {
- $this->routes = $routes;
- $this->context = $context;
- }
- public function setContext(RequestContext $context)
- {
- $this->context = $context;
- }
- public function getContext()
- {
- return $this->context;
- }
- public function match($pathinfo)
- {
- $this->allow = array();
- if ($ret = $this->matchCollection(rawurldecode($pathinfo), $this->routes)) {
- return $ret;
- }
- throw 0 < count($this->allow)
- ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow)))
- : new ResourceNotFoundException();
- }
- public function matchRequest(Request $request)
- {
- $this->request = $request;
- $ret = $this->match($request->getPathInfo());
- $this->request = null;
- return $ret;
- }
- protected function matchCollection($pathinfo, RouteCollection $routes)
- {
- foreach ($routes as $name => $route) {
- $compiledRoute = $route->compile();
- if (''!== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
- continue;
- }
- if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
- continue;
- }
- $hostMatches = array();
- if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
- continue;
- }
- if ($req = $route->getRequirement('_method')) {
- if ('HEAD'=== $method = $this->context->getMethod()) {
- $method ='GET';
- }
- if (!in_array($method, $req = explode('|', strtoupper($req)))) {
- $this->allow = array_merge($this->allow, $req);
- continue;
- }
- }
- $status = $this->handleRouteRequirements($pathinfo, $name, $route);
- if (self::ROUTE_MATCH === $status[0]) {
- return $status[1];
- }
- if (self::REQUIREMENT_MISMATCH === $status[0]) {
- continue;
- }
- return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
- }
- }
- protected function getAttributes(Route $route, $name, array $attributes)
- {
- $attributes['_route'] = $name;
- return $this->mergeDefaults($attributes, $route->getDefaults());
- }
- protected function handleRouteRequirements($pathinfo, $name, Route $route)
- {
- if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context'=> $this->context,'request'=> $this->request))) {
- return array(self::REQUIREMENT_MISMATCH, null);
- }
- $scheme = $this->context->getScheme();
- $status = $route->getSchemes() && !$route->hasScheme($scheme) ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
- return array($status, null);
- }
- protected function mergeDefaults($params, $defaults)
- {
- foreach ($params as $key => $value) {
- if (!is_int($key)) {
- $defaults[$key] = $value;
- }
- }
- return $defaults;
- }
- protected function getExpressionLanguage()
- {
- if (null === $this->expressionLanguage) {
- if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
- throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
- }
- $this->expressionLanguage = new ExpressionLanguage();
- }
- return $this->expressionLanguage;
- }
- }
- }
- namespace Symfony\Component\Routing\Matcher
- {
- use Symfony\Component\Routing\Exception\ResourceNotFoundException;
- use Symfony\Component\Routing\Route;
- abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
- {
- public function match($pathinfo)
- {
- try {
- $parameters = parent::match($pathinfo);
- } catch (ResourceNotFoundException $e) {
- if ('/'=== substr($pathinfo, -1) || !in_array($this->context->getMethod(), array('HEAD','GET'))) {
- throw $e;
- }
- try {
- parent::match($pathinfo.'/');
- return $this->redirect($pathinfo.'/', null);
- } catch (ResourceNotFoundException $e2) {
- throw $e;
- }
- }
- return $parameters;
- }
- protected function handleRouteRequirements($pathinfo, $name, Route $route)
- {
- if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context'=> $this->context,'request'=> $this->request))) {
- return array(self::REQUIREMENT_MISMATCH, null);
- }
- $scheme = $this->context->getScheme();
- $schemes = $route->getSchemes();
- if ($schemes && !$route->hasScheme($scheme)) {
- return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, current($schemes)));
- }
- return array(self::REQUIREMENT_MATCH, null);
- }
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Routing
- {
- use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
- class RedirectableUrlMatcher extends BaseMatcher
- {
- public function redirect($path, $route, $scheme = null)
- {
- 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,
- );
- }
- }
- }
- namespace Symfony\Component\HttpKernel\CacheWarmer
- {
- interface WarmableInterface
- {
- public function warmUp($cacheDir);
- }
- }
- namespace Symfony\Bundle\FrameworkBundle\Routing
- {
- use Symfony\Component\Routing\Router as BaseRouter;
- use Symfony\Component\Routing\RequestContext;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\Routing\RouteCollection;
- use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
- use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
- use Symfony\Component\DependencyInjection\Exception\RuntimeException;
- class Router extends BaseRouter implements WarmableInterface
- {
- private $container;
- public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
- {
- $this->container = $container;
- $this->resource = $resource;
- $this->context = $context ?: new RequestContext();
- $this->setOptions($options);
- }
- public function getRouteCollection()
- {
- if (null === $this->collection) {
- $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
- $this->resolveParameters($this->collection);
- }
- return $this->collection;
- }
- public function warmUp($cacheDir)
- {
- $currentDir = $this->getOption('cache_dir');
- $this->setOption('cache_dir', $cacheDir);
- $this->getMatcher();
- $this->getGenerator();
- $this->setOption('cache_dir', $currentDir);
- }
- private function resolveParameters(RouteCollection $collection)
- {
- foreach ($collection as $route) {
- foreach ($route->getDefaults() as $name => $value) {
- $route->setDefault($name, $this->resolve($value));
- }
- foreach ($route->getRequirements() as $name => $value) {
- $route->setRequirement($name, $this->resolve($value));
- }
- $route->setPath($this->resolve($route->getPath()));
- $route->setHost($this->resolve($route->getHost()));
- }
- }
- private function resolve($value)
- {
- if (is_array($value)) {
- foreach ($value as $key => $val) {
- $value[$key] = $this->resolve($val);
- }
- return $value;
- }
- if (!is_string($value)) {
- return $value;
- }
- $container = $this->container;
- $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) {
- if (!isset($match[1])) {
- return'%%';
- }
- $resolved = $container->getParameter($match[1]);
- if (is_string($resolved) || is_numeric($resolved)) {
- return (string) $resolved;
- }
- 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.',
- $match[1],
- $value,
- gettype($resolved)
- )
- );
- }, $value);
- return str_replace('%%','%', $escapedValue);
- }
- }
- }
- namespace Symfony\Component\Config
- {
- class FileLocator implements FileLocatorInterface
- {
- protected $paths;
- public function __construct($paths = array())
- {
- $this->paths = (array) $paths;
- }
- public function locate($name, $currentPath = null, $first = true)
- {
- if ($this->isAbsolutePath($name)) {
- if (!file_exists($name)) {
- throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
- }
- return $name;
- }
- $filepaths = array();
- if (null !== $currentPath && file_exists($file = $currentPath.DIRECTORY_SEPARATOR.$name)) {
- if (true === $first) {
- return $file;
- }
- $filepaths[] = $file;
- }
- foreach ($this->paths as $path) {
- if (file_exists($file = $path.DIRECTORY_SEPARATOR.$name)) {
- if (true === $first) {
- return $file;
- }
- $filepaths[] = $file;
- }
- }
- if (!$filepaths) {
- throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s%s).', $name, null !== $currentPath ? $currentPath.', ':'', implode(', ', $this->paths)));
- }
- return array_values(array_unique($filepaths));
- }
- private function isAbsolutePath($file)
- {
- if ($file[0] =='/'|| $file[0] =='\\'|| (strlen($file) > 3 && ctype_alpha($file[0])
- && $file[1] ==':'&& ($file[2] =='\\'|| $file[2] =='/')
- )
- || null !== parse_url($file, PHP_URL_SCHEME)
- ) {
- return true;
- }
- return false;
- }
- }
- }
- namespace Symfony\Component\EventDispatcher
- {
- class Event
- {
- private $propagationStopped = false;
- private $dispatcher;
- private $name;
- public function isPropagationStopped()
- {
- return $this->propagationStopped;
- }
- public function stopPropagation()
- {
- $this->propagationStopped = true;
- }
- public function setDispatcher(EventDispatcherInterface $dispatcher)
- {
- $this->dispatcher = $dispatcher;
- }
- public function getDispatcher()
- {
- return $this->dispatcher;
- }
- public function getName()
- {
- return $this->name;
- }
- public function setName($name)
- {
- $this->name = $name;
- }
- }
- }
- namespace Symfony\Component\EventDispatcher
- {
- interface EventDispatcherInterface
- {
- public function dispatch($eventName, Event $event = null);
- public function addListener($eventName, $listener, $priority = 0);
- public function addSubscriber(EventSubscriberInterface $subscriber);
- public function removeListener($eventName, $listener);
- public function removeSubscriber(EventSubscriberInterface $subscriber);
- public function getListeners($eventName = null);
- public function hasListeners($eventName = null);
- }
- }
- namespace Symfony\Component\EventDispatcher
- {
- class EventDispatcher implements EventDispatcherInterface
- {
- private $listeners = array();
- private $sorted = array();
- public function dispatch($eventName, Event $event = null)
- {
- if (null === $event) {
- $event = new Event();
- }
- $event->setDispatcher($this);
- $event->setName($eventName);
- if (!isset($this->listeners[$eventName])) {
- return $event;
- }
- $this->doDispatch($this->getListeners($eventName), $eventName, $event);
- return $event;
- }
- public function getListeners($eventName = null)
- {
- if (null !== $eventName) {
- if (!isset($this->sorted[$eventName])) {
- $this->sortListeners($eventName);
- }
- return $this->sorted[$eventName];
- }
- foreach (array_keys($this->listeners) as $eventName) {
- if (!isset($this->sorted[$eventName])) {
- $this->sortListeners($eventName);
- }
- }
- return array_filter($this->sorted);
- }
- public function hasListeners($eventName = null)
- {
- return (bool) count($this->getListeners($eventName));
- }
- public function addListener($eventName, $listener, $priority = 0)
- {
- $this->listeners[$eventName][$priority][] = $listener;
- unset($this->sorted[$eventN…
Large files files are truncated, but you can click here to view the full file