mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-05 18:41:02 +00:00
twig implementation
This commit is contained in:
parent
2b840e0cfb
commit
4f5b44bd3b
1418 changed files with 108207 additions and 1586 deletions
4
vendor/symfony/routing/Symfony/Component/Routing/.gitignore
vendored
Normal file
4
vendor/symfony/routing/Symfony/Component/Routing/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
|
156
vendor/symfony/routing/Symfony/Component/Routing/Annotation/Route.php
vendored
Normal file
156
vendor/symfony/routing/Symfony/Component/Routing/Annotation/Route.php
vendored
Normal file
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation class for @Route().
|
||||
*
|
||||
* @Annotation
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Route
|
||||
{
|
||||
private $path;
|
||||
private $name;
|
||||
private $requirements;
|
||||
private $options;
|
||||
private $defaults;
|
||||
private $host;
|
||||
private $methods;
|
||||
private $schemes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data An array of key/value parameters.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->requirements = array();
|
||||
$this->options = array();
|
||||
$this->defaults = array();
|
||||
$this->methods = array();
|
||||
$this->schemes = array();
|
||||
|
||||
if (isset($data['value'])) {
|
||||
$data['path'] = $data['value'];
|
||||
unset($data['value']);
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$method = 'set'.str_replace('_', '', $key);
|
||||
if (!method_exists($this, $method)) {
|
||||
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this)));
|
||||
}
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->path = $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use getPath instead.
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setHost($pattern)
|
||||
{
|
||||
$this->host = $pattern;
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setRequirements($requirements)
|
||||
{
|
||||
$this->requirements = $requirements;
|
||||
}
|
||||
|
||||
public function getRequirements()
|
||||
{
|
||||
return $this->requirements;
|
||||
}
|
||||
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function setDefaults($defaults)
|
||||
{
|
||||
$this->defaults = $defaults;
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return $this->defaults;
|
||||
}
|
||||
|
||||
public function setSchemes($schemes)
|
||||
{
|
||||
$this->schemes = is_array($schemes) ? $schemes : array($schemes);
|
||||
}
|
||||
|
||||
public function getSchemes()
|
||||
{
|
||||
return $this->schemes;
|
||||
}
|
||||
|
||||
public function setMethods($methods)
|
||||
{
|
||||
$this->methods = is_array($methods) ? $methods : array($methods);
|
||||
}
|
||||
|
||||
public function getMethods()
|
||||
{
|
||||
return $this->methods;
|
||||
}
|
||||
}
|
162
vendor/symfony/routing/Symfony/Component/Routing/CHANGELOG.md
vendored
Normal file
162
vendor/symfony/routing/Symfony/Component/Routing/CHANGELOG.md
vendored
Normal file
|
@ -0,0 +1,162 @@
|
|||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.3.0
|
||||
-----
|
||||
|
||||
* added RequestContext::getQueryString()
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
|
||||
* [DEPRECATION] Several route settings have been renamed (the old ones will be removed in 3.0):
|
||||
|
||||
* The `pattern` setting for a route has been deprecated in favor of `path`
|
||||
* The `_scheme` and `_method` requirements have been moved to the `schemes` and `methods` settings
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
article_edit:
|
||||
pattern: /article/{id}
|
||||
requirements: { '_method': 'POST|PUT', '_scheme': 'https', 'id': '\d+' }
|
||||
|
||||
<route id="article_edit" pattern="/article/{id}">
|
||||
<requirement key="_method">POST|PUT</requirement>
|
||||
<requirement key="_scheme">https</requirement>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
$route = new Route();
|
||||
$route->setPattern('/article/{id}');
|
||||
$route->setRequirement('_method', 'POST|PUT');
|
||||
$route->setRequirement('_scheme', 'https');
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
article_edit:
|
||||
path: /article/{id}
|
||||
methods: [POST, PUT]
|
||||
schemes: https
|
||||
requirements: { 'id': '\d+' }
|
||||
|
||||
<route id="article_edit" pattern="/article/{id}" methods="POST PUT" schemes="https">
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
$route = new Route();
|
||||
$route->setPath('/article/{id}');
|
||||
$route->setMethods(array('POST', 'PUT'));
|
||||
$route->setSchemes('https');
|
||||
```
|
||||
|
||||
* [BC BREAK] RouteCollection does not behave like a tree structure anymore but as
|
||||
a flat array of Routes. So when using PHP to build the RouteCollection, you must
|
||||
make sure to add routes to the sub-collection before adding it to the parent
|
||||
collection (this is not relevant when using YAML or XML for Route definitions).
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
$rootCollection = new RouteCollection();
|
||||
$subCollection = new RouteCollection();
|
||||
$rootCollection->addCollection($subCollection);
|
||||
$subCollection->add('foo', new Route('/foo'));
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
$rootCollection = new RouteCollection();
|
||||
$subCollection = new RouteCollection();
|
||||
$subCollection->add('foo', new Route('/foo'));
|
||||
$rootCollection->addCollection($subCollection);
|
||||
```
|
||||
|
||||
Also one must call `addCollection` from the bottom to the top hierarchy.
|
||||
So the correct sequence is the following (and not the reverse):
|
||||
|
||||
```
|
||||
$childCollection->->addCollection($grandchildCollection);
|
||||
$rootCollection->addCollection($childCollection);
|
||||
```
|
||||
|
||||
* [DEPRECATION] The methods `RouteCollection::getParent()` and `RouteCollection::getRoot()`
|
||||
have been deprecated and will be removed in Symfony 2.3.
|
||||
* [BC BREAK] Misusing the `RouteCollection::addPrefix` method to add defaults, requirements
|
||||
or options without adding a prefix is not supported anymore. So if you called `addPrefix`
|
||||
with an empty prefix or `/` only (both have no relevance), like
|
||||
`addPrefix('', $defaultsArray, $requirementsArray, $optionsArray)`
|
||||
you need to use the new dedicated methods `addDefaults($defaultsArray)`,
|
||||
`addRequirements($requirementsArray)` or `addOptions($optionsArray)` instead.
|
||||
* [DEPRECATION] The `$options` parameter to `RouteCollection::addPrefix()` has been deprecated
|
||||
because adding options has nothing to do with adding a path prefix. If you want to add options
|
||||
to all child routes of a RouteCollection, you can use `addOptions()`.
|
||||
* [DEPRECATION] The method `RouteCollection::getPrefix()` has been deprecated
|
||||
because it suggested that all routes in the collection would have this prefix, which is
|
||||
not necessarily true. On top of that, since there is no tree structure anymore, this method
|
||||
is also useless. Don't worry about performance, prefix optimization for matching is still done
|
||||
in the dumper, which was also improved in 2.2.0 to find even more grouping possibilities.
|
||||
* [DEPRECATION] `RouteCollection::addCollection(RouteCollection $collection)` should now only be
|
||||
used with a single parameter. The other params `$prefix`, `$default`, `$requirements` and `$options`
|
||||
will still work, but have been deprecated. The `addPrefix` method should be used for this
|
||||
use-case instead.
|
||||
Before: `$parentCollection->addCollection($collection, '/prefix', array(...), array(...))`
|
||||
After:
|
||||
```
|
||||
$collection->addPrefix('/prefix', array(...), array(...));
|
||||
$parentCollection->addCollection($collection);
|
||||
```
|
||||
* added support for the method default argument values when defining a @Route
|
||||
* Adjacent placeholders without separator work now, e.g. `/{x}{y}{z}.{_format}`.
|
||||
* Characters that function as separator between placeholders are now whitelisted
|
||||
to fix routes with normal text around a variable, e.g. `/prefix{var}suffix`.
|
||||
* [BC BREAK] The default requirement of a variable has been changed slightly.
|
||||
Previously it disallowed the previous and the next char around a variable. Now
|
||||
it disallows the slash (`/`) and the next char. Using the previous char added
|
||||
no value and was problematic because the route `/index.{_format}` would be
|
||||
matched by `/index.ht/ml`.
|
||||
* The default requirement now uses possessive quantifiers when possible which
|
||||
improves matching performance by up to 20% because it prevents backtracking
|
||||
when it's not needed.
|
||||
* The ConfigurableRequirementsInterface can now also be used to disable the requirements
|
||||
check on URL generation completely by calling `setStrictRequirements(null)`. It
|
||||
improves performance in production environment as you should know that params always
|
||||
pass the requirements (otherwise it would break your link anyway).
|
||||
* There is no restriction on the route name anymore. So non-alphanumeric characters
|
||||
are now also allowed.
|
||||
* [BC BREAK] `RouteCompilerInterface::compile(Route $route)` was made static
|
||||
(only relevant if you implemented your own RouteCompiler).
|
||||
* Added possibility to generate relative paths and network paths in the UrlGenerator, e.g.
|
||||
"../parent-file" and "//example.com/dir/file". The third parameter in
|
||||
`UrlGeneratorInterface::generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)`
|
||||
now accepts more values and you should use the constants defined in `UrlGeneratorInterface` for
|
||||
claritiy. The old method calls with a Boolean parameter will continue to work because they
|
||||
equal the signature using the constants.
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
|
||||
* added RequestMatcherInterface
|
||||
* added RequestContext::fromRequest()
|
||||
* the UrlMatcher does not throw a \LogicException anymore when the required
|
||||
scheme is not the current one
|
||||
* added TraceableUrlMatcher
|
||||
* added the possibility to define options, default values and requirements
|
||||
for placeholders in prefix, including imported routes
|
||||
* added RouterInterface::getRouteCollection
|
||||
* [BC BREAK] the UrlMatcher urldecodes the route parameters only once, they
|
||||
were decoded twice before. Note that the `urldecode()` calls have been
|
||||
changed for a single `rawurldecode()` in order to support `+` for input
|
||||
paths.
|
||||
* added RouteCollection::getRoot method to retrieve the root of a
|
||||
RouteCollection tree
|
||||
* [BC BREAK] made RouteCollection::setParent private which could not have
|
||||
been used anyway without creating inconsistencies
|
||||
* [BC BREAK] RouteCollection::remove also removes a route from parent
|
||||
collections (not only from its children)
|
||||
* added ConfigurableRequirementsInterface that allows to disable exceptions
|
||||
(and generate empty URLs instead) when generating a route with an invalid
|
||||
parameter value
|
134
vendor/symfony/routing/Symfony/Component/Routing/CompiledRoute.php
vendored
Normal file
134
vendor/symfony/routing/Symfony/Component/Routing/CompiledRoute.php
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
/**
|
||||
* CompiledRoutes are returned by the RouteCompiler class.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class CompiledRoute
|
||||
{
|
||||
private $variables;
|
||||
private $tokens;
|
||||
private $staticPrefix;
|
||||
private $regex;
|
||||
private $pathVariables;
|
||||
private $hostVariables;
|
||||
private $hostRegex;
|
||||
private $hostTokens;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $staticPrefix The static prefix of the compiled route
|
||||
* @param string $regex The regular expression to use to match this route
|
||||
* @param array $tokens An array of tokens to use to generate URL for this route
|
||||
* @param array $pathVariables An array of path variables
|
||||
* @param string|null $hostRegex Host regex
|
||||
* @param array $hostTokens Host tokens
|
||||
* @param array $hostVariables An array of host variables
|
||||
* @param array $variables An array of variables (variables defined in the path and in the host patterns)
|
||||
*/
|
||||
public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostRegex = null, array $hostTokens = array(), array $hostVariables = array(), array $variables = array())
|
||||
{
|
||||
$this->staticPrefix = (string) $staticPrefix;
|
||||
$this->regex = $regex;
|
||||
$this->tokens = $tokens;
|
||||
$this->pathVariables = $pathVariables;
|
||||
$this->hostRegex = $hostRegex;
|
||||
$this->hostTokens = $hostTokens;
|
||||
$this->hostVariables = $hostVariables;
|
||||
$this->variables = $variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the static prefix.
|
||||
*
|
||||
* @return string The static prefix
|
||||
*/
|
||||
public function getStaticPrefix()
|
||||
{
|
||||
return $this->staticPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the regex.
|
||||
*
|
||||
* @return string The regex
|
||||
*/
|
||||
public function getRegex()
|
||||
{
|
||||
return $this->regex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host regex
|
||||
*
|
||||
* @return string|null The host regex or null
|
||||
*/
|
||||
public function getHostRegex()
|
||||
{
|
||||
return $this->hostRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tokens.
|
||||
*
|
||||
* @return array The tokens
|
||||
*/
|
||||
public function getTokens()
|
||||
{
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host tokens.
|
||||
*
|
||||
* @return array The tokens
|
||||
*/
|
||||
public function getHostTokens()
|
||||
{
|
||||
return $this->hostTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variables.
|
||||
*
|
||||
* @return array The variables
|
||||
*/
|
||||
public function getVariables()
|
||||
{
|
||||
return $this->variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path variables.
|
||||
*
|
||||
* @return array The variables
|
||||
*/
|
||||
public function getPathVariables()
|
||||
{
|
||||
return $this->pathVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host variables.
|
||||
*
|
||||
* @return array The variables
|
||||
*/
|
||||
public function getHostVariables()
|
||||
{
|
||||
return $this->hostVariables;
|
||||
}
|
||||
|
||||
}
|
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/ExceptionInterface.php
vendored
Normal file
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/ExceptionInterface.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* ExceptionInterface
|
||||
*
|
||||
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/InvalidParameterException.php
vendored
Normal file
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/InvalidParameterException.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* Exception thrown when a parameter is not valid
|
||||
*
|
||||
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class InvalidParameterException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
46
vendor/symfony/routing/Symfony/Component/Routing/Exception/MethodNotAllowedException.php
vendored
Normal file
46
vendor/symfony/routing/Symfony/Component/Routing/Exception/MethodNotAllowedException.php
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* The resource was found but the request method is not allowed.
|
||||
*
|
||||
* This exception should trigger an HTTP 405 response in your application code.
|
||||
*
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class MethodNotAllowedException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedMethods = array();
|
||||
|
||||
public function __construct(array $allowedMethods, $message = null, $code = 0, \Exception $previous = null)
|
||||
{
|
||||
$this->allowedMethods = array_map('strtoupper', $allowedMethods);
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the allowed HTTP methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedMethods()
|
||||
{
|
||||
return $this->allowedMethods;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* Exception thrown when a route cannot be generated because of missing
|
||||
* mandatory parameters.
|
||||
*
|
||||
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class MissingMandatoryParametersException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
25
vendor/symfony/routing/Symfony/Component/Routing/Exception/ResourceNotFoundException.php
vendored
Normal file
25
vendor/symfony/routing/Symfony/Component/Routing/Exception/ResourceNotFoundException.php
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* The resource was not found.
|
||||
*
|
||||
* This exception should trigger an HTTP 404 response in your application code.
|
||||
*
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ResourceNotFoundException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/RouteNotFoundException.php
vendored
Normal file
23
vendor/symfony/routing/Symfony/Component/Routing/Exception/RouteNotFoundException.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Exception;
|
||||
|
||||
/**
|
||||
* Exception thrown when a route does not exists
|
||||
*
|
||||
* @author Alexandre Salomé <alexandre.salome@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class RouteNotFoundException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
55
vendor/symfony/routing/Symfony/Component/Routing/Generator/ConfigurableRequirementsInterface.php
vendored
Normal file
55
vendor/symfony/routing/Symfony/Component/Routing/Generator/ConfigurableRequirementsInterface.php
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Generator;
|
||||
|
||||
/**
|
||||
* ConfigurableRequirementsInterface must be implemented by URL generators that
|
||||
* can be configured whether an exception should be generated when the parameters
|
||||
* do not match the requirements. It is also possible to disable the requirements
|
||||
* check for URL generation completely.
|
||||
*
|
||||
* The possible configurations and use-cases:
|
||||
* - setStrictRequirements(true): Throw an exception for mismatching requirements. This
|
||||
* is mostly useful in development environment.
|
||||
* - setStrictRequirements(false): Don't throw an exception but return null as URL for
|
||||
* mismatching requirements and log the problem. Useful when you cannot control all
|
||||
* params because they come from third party libs but don't want to have a 404 in
|
||||
* production environment. It should log the mismatch so one can review it.
|
||||
* - setStrictRequirements(null): Return the URL with the given parameters without
|
||||
* checking the requirements at all. When generating an URL you should either trust
|
||||
* your params or you validated them beforehand because otherwise it would break your
|
||||
* link anyway. So in production environment you should know that params always pass
|
||||
* the requirements. Thus this option allows to disable the check on URL generation for
|
||||
* performance reasons (saving a preg_match for each requirement every time a URL is
|
||||
* generated).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
interface ConfigurableRequirementsInterface
|
||||
{
|
||||
/**
|
||||
* Enables or disables the exception on incorrect parameters.
|
||||
* Passing null will deactivate the requirements check completely.
|
||||
*
|
||||
* @param Boolean|null $enabled
|
||||
*/
|
||||
public function setStrictRequirements($enabled);
|
||||
|
||||
/**
|
||||
* Returns whether to throw an exception on incorrect parameters.
|
||||
* Null means the requirements check is deactivated completely.
|
||||
*
|
||||
* @return Boolean|null
|
||||
*/
|
||||
public function isStrictRequirements();
|
||||
}
|
45
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php
vendored
Normal file
45
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Generator\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* GeneratorDumper is the base class for all built-in generator dumpers.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class GeneratorDumper implements GeneratorDumperInterface
|
||||
{
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
private $routes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param RouteCollection $routes The RouteCollection to dump
|
||||
*/
|
||||
public function __construct(RouteCollection $routes)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes()
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
}
|
41
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php
vendored
Normal file
41
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/GeneratorDumperInterface.php
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Generator\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* GeneratorDumperInterface is the interface that all generator dumper classes must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface GeneratorDumperInterface
|
||||
{
|
||||
/**
|
||||
* Dumps a set of routes to a string representation of executable code
|
||||
* that can then be used to generate a URL of such a route.
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string Executable code
|
||||
*/
|
||||
public function dump(array $options = array());
|
||||
|
||||
/**
|
||||
* Gets the routes to dump.
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*/
|
||||
public function getRoutes();
|
||||
}
|
123
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php
vendored
Normal file
123
vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Generator\Dumper;
|
||||
|
||||
/**
|
||||
* PhpGeneratorDumper creates a PHP class able to generate URLs for a given set of routes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class PhpGeneratorDumper extends GeneratorDumper
|
||||
{
|
||||
/**
|
||||
* Dumps a set of routes to a PHP class.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * class: The class name
|
||||
* * base_class: The base class name
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string A PHP class representing the generator class
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
{
|
||||
$options = array_merge(array(
|
||||
'class' => 'ProjectUrlGenerator',
|
||||
'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
|
||||
), $options);
|
||||
|
||||
return <<<EOF
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* {$options['class']}
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class {$options['class']} extends {$options['base_class']}
|
||||
{
|
||||
static private \$declaredRoutes = {$this->generateDeclaredRoutes()};
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(RequestContext \$context, LoggerInterface \$logger = null)
|
||||
{
|
||||
\$this->context = \$context;
|
||||
\$this->logger = \$logger;
|
||||
}
|
||||
|
||||
{$this->generateGenerateMethod()}
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code representing an array of defined routes
|
||||
* together with the routes properties (e.g. requirements).
|
||||
*
|
||||
* @return string PHP code
|
||||
*/
|
||||
private function generateDeclaredRoutes()
|
||||
{
|
||||
$routes = "array(\n";
|
||||
foreach ($this->getRoutes()->all() as $name => $route) {
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
$properties = array();
|
||||
$properties[] = $compiledRoute->getVariables();
|
||||
$properties[] = $route->getDefaults();
|
||||
$properties[] = $route->getRequirements();
|
||||
$properties[] = $compiledRoute->getTokens();
|
||||
$properties[] = $compiledRoute->getHostTokens();
|
||||
|
||||
$routes .= sprintf(" '%s' => %s,\n", $name, str_replace("\n", '', var_export($properties, true)));
|
||||
}
|
||||
$routes .= ' )';
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code representing the `generate` method that implements the UrlGeneratorInterface.
|
||||
*
|
||||
* @return string PHP code
|
||||
*/
|
||||
private function generateGenerateMethod()
|
||||
{
|
||||
return <<<EOF
|
||||
public function generate(\$name, \$parameters = array(), \$referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
if (!isset(self::\$declaredRoutes[\$name])) {
|
||||
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', \$name));
|
||||
}
|
||||
|
||||
list(\$variables, \$defaults, \$requirements, \$tokens, \$hostTokens) = self::\$declaredRoutes[\$name];
|
||||
|
||||
return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$referenceType, \$hostTokens);
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
}
|
322
vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php
vendored
Normal file
322
vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php
vendored
Normal file
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* UrlGenerator can generate a URL or a path for any route in the RouteCollection
|
||||
* based on the passed parameters.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInterface
|
||||
{
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
protected $routes;
|
||||
|
||||
/**
|
||||
* @var RequestContext
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var Boolean|null
|
||||
*/
|
||||
protected $strictRequirements = true;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface|null
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
|
||||
*
|
||||
* PHP's rawurlencode() encodes all chars except "a-zA-Z0-9-._~" according to RFC 3986. But we want to allow some chars
|
||||
* to be used in their literal form (reasons below). Other chars inside the path must of course be encoded, e.g.
|
||||
* "?" and "#" (would be interpreted wrongly as query and fragment identifier),
|
||||
* "'" and """ (are used as delimiters in HTML).
|
||||
*/
|
||||
protected $decodedChars = array(
|
||||
// the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
|
||||
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
|
||||
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
|
||||
'%2F' => '/',
|
||||
// the following chars are general delimiters in the URI specification but have only special meaning in the authority component
|
||||
// so they can safely be used in the path in unencoded form
|
||||
'%40' => '@',
|
||||
'%3A' => ':',
|
||||
// these chars are only sub-delimiters that have no predefined meaning and can therefore be used literally
|
||||
// so URI producing applications can use these chars to delimit subcomponents in a path segment without being encoded for better readability
|
||||
'%3B' => ';',
|
||||
'%2C' => ',',
|
||||
'%3D' => '=',
|
||||
'%2B' => '+',
|
||||
'%21' => '!',
|
||||
'%2A' => '*',
|
||||
'%7C' => '|',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param RouteCollection $routes A RouteCollection instance
|
||||
* @param RequestContext $context The context
|
||||
* @param LoggerInterface|null $logger A logger instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
$this->context = $context;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContext(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStrictRequirements($enabled)
|
||||
{
|
||||
$this->strictRequirements = null === $enabled ? null : (Boolean) $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isStrictRequirements()
|
||||
{
|
||||
return $this->strictRequirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
// the Route has a cache of its own and is not recompiled as long as it does not get modified
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
*/
|
||||
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens)
|
||||
{
|
||||
$variables = array_flip($variables);
|
||||
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
||||
|
||||
// all params must be given
|
||||
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]]) {
|
||||
// check requirement
|
||||
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 null;
|
||||
}
|
||||
|
||||
$url = $token[1].$mergedParams[$token[3]].$url;
|
||||
$optional = false;
|
||||
}
|
||||
} else {
|
||||
// static text
|
||||
$url = $token[1].$url;
|
||||
$optional = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ('' === $url) {
|
||||
$url = '/';
|
||||
}
|
||||
|
||||
// the contexts base url is already encoded (see Symfony\Component\HttpFoundation\Request)
|
||||
$url = strtr(rawurlencode($url), $this->decodedChars);
|
||||
|
||||
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
|
||||
// so we need to encode them as they are not used for this purpose here
|
||||
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
|
||||
$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 (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 null;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
// add a query string if needed
|
||||
$extra = array_diff_key($parameters, $variables, $defaults);
|
||||
if ($extra && $query = http_build_query($extra, '', '&')) {
|
||||
$url .= '?'.$query;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target path as relative reference from the base path.
|
||||
*
|
||||
* Only the URIs path component (no schema, host etc.) is relevant and must be given, starting with a slash.
|
||||
* Both paths must be absolute and not contain relative parts.
|
||||
* Relative URLs from one resource to another are useful when generating self-contained downloadable document archives.
|
||||
* Furthermore, they can be used to reduce the link size in documents.
|
||||
*
|
||||
* Example target paths, given a base path of "/a/b/c/d":
|
||||
* - "/a/b/c/d" -> ""
|
||||
* - "/a/b/c/" -> "./"
|
||||
* - "/a/b/" -> "../"
|
||||
* - "/a/b/c/other" -> "other"
|
||||
* - "/a/x/y" -> "../../x/y"
|
||||
*
|
||||
* @param string $basePath The base path
|
||||
* @param string $targetPath The target path
|
||||
*
|
||||
* @return string The relative target path
|
||||
*/
|
||||
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);
|
||||
|
||||
// A reference to the same base directory or an empty subdirectory must be prefixed with "./".
|
||||
// This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used
|
||||
// as the first segment of a relative-path reference, as it would be mistaken for a scheme name
|
||||
// (see http://tools.ietf.org/html/rfc3986#section-4.2).
|
||||
return '' === $path || '/' === $path[0]
|
||||
|| false !== ($colonPos = strpos($path, ':')) && ($colonPos < ($slashPos = strpos($path, '/')) || false === $slashPos)
|
||||
? "./$path" : $path;
|
||||
}
|
||||
}
|
87
vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGeneratorInterface.php
vendored
Normal file
87
vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGeneratorInterface.php
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* UrlGeneratorInterface is the interface that all URL generator classes must implement.
|
||||
*
|
||||
* The constants in this interface define the different types of resource references that
|
||||
* are declared in RFC 3986: http://tools.ietf.org/html/rfc3986
|
||||
* We are using the term "URL" instead of "URI" as this is more common in web applications
|
||||
* and we do not need to distinguish them as the difference is mostly semantical and
|
||||
* less technical. Generating URIs, i.e. representation-independent resource identifiers,
|
||||
* is also possible.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface UrlGeneratorInterface extends RequestContextAwareInterface
|
||||
{
|
||||
/**
|
||||
* Generates an absolute URL, e.g. "http://example.com/dir/file".
|
||||
*/
|
||||
const ABSOLUTE_URL = true;
|
||||
|
||||
/**
|
||||
* Generates an absolute path, e.g. "/dir/file".
|
||||
*/
|
||||
const ABSOLUTE_PATH = false;
|
||||
|
||||
/**
|
||||
* Generates a relative path based on the current request path, e.g. "../parent-file".
|
||||
* @see UrlGenerator::getRelativePath()
|
||||
*/
|
||||
const RELATIVE_PATH = 'relative';
|
||||
|
||||
/**
|
||||
* Generates a network path, e.g. "//example.com/dir/file".
|
||||
* Such reference reuses the current scheme but specifies the host.
|
||||
*/
|
||||
const NETWORK_PATH = 'network';
|
||||
|
||||
/**
|
||||
* Generates a URL or path for a specific route based on the given parameters.
|
||||
*
|
||||
* Parameters that reference placeholders in the route pattern will substitute them in the
|
||||
* path or host. Extra params are added as query string to the URL.
|
||||
*
|
||||
* When the passed reference type cannot be generated for the route because it requires a different
|
||||
* host or scheme than the current one, the method will return a more comprehensive reference
|
||||
* that includes the required params. For example, when you call this method with $referenceType = ABSOLUTE_PATH
|
||||
* but the route requires the https scheme whereas the current scheme is http, it will instead return an
|
||||
* ABSOLUTE_URL with the https scheme and the current host. This makes sure the generated URL matches
|
||||
* the route in any case.
|
||||
*
|
||||
* If there is no route with the given name, the generator must throw the RouteNotFoundException.
|
||||
*
|
||||
* @param string $name The name of the route
|
||||
* @param mixed $parameters An array of parameters
|
||||
* @param Boolean|string $referenceType The type of reference to be generated (one of the constants)
|
||||
*
|
||||
* @return string The generated URL
|
||||
*
|
||||
* @throws RouteNotFoundException If the named route doesn't exist
|
||||
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH);
|
||||
}
|
19
vendor/symfony/routing/Symfony/Component/Routing/LICENSE
vendored
Normal file
19
vendor/symfony/routing/Symfony/Component/Routing/LICENSE
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2004-2013 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
246
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
vendored
Normal file
246
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
vendored
Normal file
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Config\Loader\LoaderResolverInterface;
|
||||
|
||||
/**
|
||||
* AnnotationClassLoader loads routing information from a PHP class and its methods.
|
||||
*
|
||||
* You need to define an implementation for the getRouteDefaults() method. Most of the
|
||||
* time, this method should define some PHP callable to be called for the route
|
||||
* (a controller in MVC speak).
|
||||
*
|
||||
* The @Route annotation can be set on the class (for global parameters),
|
||||
* and on each method.
|
||||
*
|
||||
* The @Route annotation main value is the route path. The annotation also
|
||||
* recognizes several parameters: requirements, options, defaults, schemes,
|
||||
* methods, host, and name. The name parameter is mandatory.
|
||||
* Here is an example of how you should be able to use it:
|
||||
*
|
||||
* /**
|
||||
* * @Route("/Blog")
|
||||
* * /
|
||||
* class Blog
|
||||
* {
|
||||
* /**
|
||||
* * @Route("/", name="blog_index")
|
||||
* * /
|
||||
* public function index()
|
||||
* {
|
||||
* }
|
||||
*
|
||||
* /**
|
||||
* * @Route("/{id}", name="blog_post", requirements = {"id" = "\d+"})
|
||||
* * /
|
||||
* public function show()
|
||||
* {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class AnnotationClassLoader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
protected $reader;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $routeAnnotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $defaultRouteIndex = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Reader $reader
|
||||
*/
|
||||
public function __construct(Reader $reader)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the annotation class to read route properties from.
|
||||
*
|
||||
* @param string $class A fully-qualified class name
|
||||
*/
|
||||
public function setRouteAnnotationClass($class)
|
||||
{
|
||||
$this->routeAnnotationClass = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads from annotations from a class.
|
||||
*
|
||||
* @param string $class A class name
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When route can't be parsed
|
||||
*/
|
||||
public function load($class, $type = null)
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$globals = array(
|
||||
'path' => '',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
'host' => '',
|
||||
);
|
||||
|
||||
$class = new \ReflectionClass($class);
|
||||
if ($class->isAbstract()) {
|
||||
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
|
||||
}
|
||||
|
||||
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
|
||||
// for BC reasons
|
||||
if (null !== $annot->getPath()) {
|
||||
$globals['path'] = $annot->getPath();
|
||||
} elseif (null !== $annot->getPattern()) {
|
||||
$globals['path'] = $annot->getPattern();
|
||||
}
|
||||
|
||||
if (null !== $annot->getRequirements()) {
|
||||
$globals['requirements'] = $annot->getRequirements();
|
||||
}
|
||||
|
||||
if (null !== $annot->getOptions()) {
|
||||
$globals['options'] = $annot->getOptions();
|
||||
}
|
||||
|
||||
if (null !== $annot->getDefaults()) {
|
||||
$globals['defaults'] = $annot->getDefaults();
|
||||
}
|
||||
|
||||
if (null !== $annot->getSchemes()) {
|
||||
$globals['schemes'] = $annot->getSchemes();
|
||||
}
|
||||
|
||||
if (null !== $annot->getMethods()) {
|
||||
$globals['methods'] = $annot->getMethods();
|
||||
}
|
||||
|
||||
if (null !== $annot->getHost()) {
|
||||
$globals['host'] = $annot->getHost();
|
||||
}
|
||||
}
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->addResource(new FileResource($class->getFileName()));
|
||||
|
||||
foreach ($class->getMethods() as $method) {
|
||||
$this->defaultRouteIndex = 0;
|
||||
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $this->routeAnnotationClass) {
|
||||
$this->addRoute($collection, $annot, $globals, $class, $method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
|
||||
{
|
||||
$name = $annot->getName();
|
||||
if (null === $name) {
|
||||
$name = $this->getDefaultRouteName($class, $method);
|
||||
}
|
||||
|
||||
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
|
||||
foreach ($method->getParameters() as $param) {
|
||||
if ($param->isOptional()) {
|
||||
$defaults[$param->getName()] = $param->getDefaultValue();
|
||||
}
|
||||
}
|
||||
$requirements = array_replace($globals['requirements'], $annot->getRequirements());
|
||||
$options = array_replace($globals['options'], $annot->getOptions());
|
||||
$schemes = array_replace($globals['schemes'], $annot->getSchemes());
|
||||
$methods = array_replace($globals['methods'], $annot->getMethods());
|
||||
|
||||
$host = $annot->getHost();
|
||||
if (null === $host) {
|
||||
$host = $globals['host'];
|
||||
}
|
||||
|
||||
$route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $host, $schemes, $methods);
|
||||
|
||||
$this->configureRoute($route, $class, $method, $annot);
|
||||
|
||||
$collection->add($name, $route);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setResolver(LoaderResolverInterface $resolver)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getResolver()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default route name for a class method.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
|
||||
{
|
||||
$name = strtolower(str_replace('\\', '_', $class->name).'_'.$method->name);
|
||||
if ($this->defaultRouteIndex > 0) {
|
||||
$name .= '_'.$this->defaultRouteIndex;
|
||||
}
|
||||
$this->defaultRouteIndex++;
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot);
|
||||
}
|
77
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
vendored
Normal file
77
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Config\Resource\DirectoryResource;
|
||||
|
||||
/**
|
||||
* AnnotationDirectoryLoader loads routing information from annotations set
|
||||
* on PHP classes and methods.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class AnnotationDirectoryLoader extends AnnotationFileLoader
|
||||
{
|
||||
/**
|
||||
* Loads from annotations from a directory.
|
||||
*
|
||||
* @param string $path A directory path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed
|
||||
*/
|
||||
public function load($path, $type = null)
|
||||
{
|
||||
$dir = $this->locator->locate($path);
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->addResource(new DirectoryResource($dir, '/\.php$/'));
|
||||
$files = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY));
|
||||
usort($files, function (\SplFileInfo $a, \SplFileInfo $b) {
|
||||
return (string) $a > (string) $b ? 1 : -1;
|
||||
});
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($class = $this->findClass($file)) {
|
||||
$refl = new \ReflectionClass($class);
|
||||
if ($refl->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$collection->addCollection($this->loader->load($class, $type));
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
try {
|
||||
$path = $this->locator->locate($resource);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_string($resource) && is_dir($path) && (!$type || 'annotation' === $type);
|
||||
}
|
||||
}
|
122
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
vendored
Normal file
122
vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
|
||||
/**
|
||||
* AnnotationFileLoader loads routing information from annotations set
|
||||
* on a PHP class and its methods.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class AnnotationFileLoader extends FileLoader
|
||||
{
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param FileLocatorInterface $locator A FileLocator instance
|
||||
* @param AnnotationClassLoader $loader An AnnotationClassLoader instance
|
||||
* @param string|array $paths A path or an array of paths where to look for resources
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader, $paths = array())
|
||||
{
|
||||
if (!function_exists('token_get_all')) {
|
||||
throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
|
||||
}
|
||||
|
||||
parent::__construct($locator, $paths);
|
||||
|
||||
$this->loader = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads from annotations from a file.
|
||||
*
|
||||
* @param string $file A PHP file path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
|
||||
*/
|
||||
public function load($file, $type = null)
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
$collection = new RouteCollection();
|
||||
if ($class = $this->findClass($path)) {
|
||||
$collection->addResource(new FileResource($path));
|
||||
$collection->addCollection($this->loader->load($class, $type));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full class name for the first class in the file.
|
||||
*
|
||||
* @param string $file A PHP file path
|
||||
*
|
||||
* @return string|false Full class name if found, false otherwise
|
||||
*/
|
||||
protected function findClass($file)
|
||||
{
|
||||
$class = false;
|
||||
$namespace = false;
|
||||
$tokens = token_get_all(file_get_contents($file));
|
||||
for ($i = 0, $count = count($tokens); $i < $count; $i++) {
|
||||
$token = $tokens[$i];
|
||||
|
||||
if (!is_array($token)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (true === $class && T_STRING === $token[0]) {
|
||||
return $namespace.'\\'.$token[1];
|
||||
}
|
||||
|
||||
if (true === $namespace && T_STRING === $token[0]) {
|
||||
$namespace = '';
|
||||
do {
|
||||
$namespace .= $token[1];
|
||||
$token = $tokens[++$i];
|
||||
} while ($i < $count && is_array($token) && in_array($token[0], array(T_NS_SEPARATOR, T_STRING)));
|
||||
}
|
||||
|
||||
if (T_CLASS === $token[0]) {
|
||||
$class = true;
|
||||
}
|
||||
|
||||
if (T_NAMESPACE === $token[0]) {
|
||||
$namespace = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
52
vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php
vendored
Normal file
52
vendor/symfony/routing/Symfony/Component/Routing/Loader/ClosureLoader.php
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Config\Loader\Loader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* ClosureLoader loads routes from a PHP closure.
|
||||
*
|
||||
* The Closure must return a RouteCollection instance.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ClosureLoader extends Loader
|
||||
{
|
||||
/**
|
||||
* Loads a Closure.
|
||||
*
|
||||
* @param \Closure $closure A Closure
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function load($closure, $type = null)
|
||||
{
|
||||
return call_user_func($closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return $resource instanceof \Closure && (!$type || 'closure' === $type);
|
||||
}
|
||||
}
|
62
vendor/symfony/routing/Symfony/Component/Routing/Loader/PhpFileLoader.php
vendored
Normal file
62
vendor/symfony/routing/Symfony/Component/Routing/Loader/PhpFileLoader.php
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* PhpFileLoader loads routes from a PHP file.
|
||||
*
|
||||
* The file must return a RouteCollection instance.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class PhpFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* Loads a PHP file.
|
||||
*
|
||||
* @param string $file A PHP file path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function load($file, $type = null)
|
||||
{
|
||||
// the loader variable is exposed to the included file below
|
||||
$loader = $this;
|
||||
|
||||
$path = $this->locator->locate($file);
|
||||
$this->setCurrentDir(dirname($path));
|
||||
|
||||
$collection = include $path;
|
||||
$collection->addResource(new FileResource($path));
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
|
||||
}
|
||||
}
|
238
vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php
vendored
Normal file
238
vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php
vendored
Normal file
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
|
||||
/**
|
||||
* XmlFileLoader loads XML routing files.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class XmlFileLoader extends FileLoader
|
||||
{
|
||||
const NAMESPACE_URI = 'http://symfony.com/schema/routing';
|
||||
const SCHEME_PATH = '/schema/routing/routing-1.0.xsd';
|
||||
|
||||
/**
|
||||
* Loads an XML file.
|
||||
*
|
||||
* @param string $file An XML file path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When the file cannot be loaded or when the XML cannot be
|
||||
* parsed because it does not validate against the scheme.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function load($file, $type = null)
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
$xml = $this->loadFile($path);
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->addResource(new FileResource($path));
|
||||
|
||||
// process routes and imports
|
||||
foreach ($xml->documentElement->childNodes as $node) {
|
||||
if (!$node instanceof \DOMElement) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->parseNode($collection, $node, $path, $file);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a node from a loaded XML file.
|
||||
*
|
||||
* @param RouteCollection $collection Collection to associate with the node
|
||||
* @param \DOMElement $node Element to parse
|
||||
* @param string $path Full path of the XML file being processed
|
||||
* @param string $file Loaded file name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the XML is invalid
|
||||
*/
|
||||
protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file)
|
||||
{
|
||||
if (self::NAMESPACE_URI !== $node->namespaceURI) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($node->localName) {
|
||||
case 'route':
|
||||
$this->parseRoute($collection, $node, $path);
|
||||
break;
|
||||
case 'import':
|
||||
$this->parseImport($collection, $node, $path, $file);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return is_string($resource) && 'xml' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'xml' === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a route and adds it to the RouteCollection.
|
||||
*
|
||||
* @param RouteCollection $collection RouteCollection instance
|
||||
* @param \DOMElement $node Element to parse that represents a Route
|
||||
* @param string $path Full path of the XML file being processed
|
||||
*
|
||||
* @throws \InvalidArgumentException When the XML is invalid
|
||||
*/
|
||||
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
|
||||
{
|
||||
if ('' === ($id = $node->getAttribute('id')) || (!$node->hasAttribute('pattern') && !$node->hasAttribute('path'))) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
|
||||
}
|
||||
|
||||
if ($node->hasAttribute('pattern')) {
|
||||
if ($node->hasAttribute('path')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
|
||||
}
|
||||
|
||||
$node->setAttribute('path', $node->getAttribute('pattern'));
|
||||
$node->removeAttribute('pattern');
|
||||
}
|
||||
|
||||
$schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
|
||||
$methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);
|
||||
|
||||
$route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods);
|
||||
$collection->add($id, $route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an import and adds the routes in the resource to the RouteCollection.
|
||||
*
|
||||
* @param RouteCollection $collection RouteCollection instance
|
||||
* @param \DOMElement $node Element to parse that represents a Route
|
||||
* @param string $path Full path of the XML file being processed
|
||||
* @param string $file Loaded file name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the XML is invalid
|
||||
*/
|
||||
protected function parseImport(RouteCollection $collection, \DOMElement $node, $path, $file)
|
||||
{
|
||||
if ('' === $resource = $node->getAttribute('resource')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <import> element in file "%s" must have a "resource" attribute.', $path));
|
||||
}
|
||||
|
||||
$type = $node->getAttribute('type');
|
||||
$prefix = $node->getAttribute('prefix');
|
||||
$host = $node->hasAttribute('host') ? $node->getAttribute('host') : null;
|
||||
$schemes = $node->hasAttribute('schemes') ? preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY) : null;
|
||||
$methods = $node->hasAttribute('methods') ? preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY) : null;
|
||||
|
||||
list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);
|
||||
|
||||
$this->setCurrentDir(dirname($path));
|
||||
|
||||
$subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file);
|
||||
/* @var $subCollection RouteCollection */
|
||||
$subCollection->addPrefix($prefix);
|
||||
if (null !== $host) {
|
||||
$subCollection->setHost($host);
|
||||
}
|
||||
if (null !== $schemes) {
|
||||
$subCollection->setSchemes($schemes);
|
||||
}
|
||||
if (null !== $methods) {
|
||||
$subCollection->setMethods($methods);
|
||||
}
|
||||
$subCollection->addDefaults($defaults);
|
||||
$subCollection->addRequirements($requirements);
|
||||
$subCollection->addOptions($options);
|
||||
|
||||
$collection->addCollection($subCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an XML file.
|
||||
*
|
||||
* @param string $file An XML file path
|
||||
*
|
||||
* @return \DOMDocument
|
||||
*
|
||||
* @throws \InvalidArgumentException When loading of XML file fails because of syntax errors
|
||||
* or when the XML structure is not as expected by the scheme -
|
||||
* see validate()
|
||||
*/
|
||||
protected function loadFile($file)
|
||||
{
|
||||
return XmlUtils::loadFile($file, __DIR__.static::SCHEME_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the config elements (default, requirement, option).
|
||||
*
|
||||
* @param \DOMElement $node Element to parse that contains the configs
|
||||
* @param string $path Full path of the XML file being processed
|
||||
*
|
||||
* @return array An array with the defaults as first item, requirements as second and options as third.
|
||||
*
|
||||
* @throws \InvalidArgumentException When the XML is invalid
|
||||
*/
|
||||
private function parseConfigs(\DOMElement $node, $path)
|
||||
{
|
||||
$defaults = array();
|
||||
$requirements = array();
|
||||
$options = array();
|
||||
|
||||
foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) {
|
||||
switch ($n->localName) {
|
||||
case 'default':
|
||||
if ($n->hasAttribute('xsi:nil') && 'true' == $n->getAttribute('xsi:nil')) {
|
||||
$defaults[$n->getAttribute('key')] = null;
|
||||
} else {
|
||||
$defaults[$n->getAttribute('key')] = trim($n->textContent);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'requirement':
|
||||
$requirements[$n->getAttribute('key')] = trim($n->textContent);
|
||||
break;
|
||||
case 'option':
|
||||
$options[$n->getAttribute('key')] = trim($n->textContent);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->localName, $path));
|
||||
}
|
||||
}
|
||||
|
||||
return array($defaults, $requirements, $options);
|
||||
}
|
||||
}
|
212
vendor/symfony/routing/Symfony/Component/Routing/Loader/YamlFileLoader.php
vendored
Normal file
212
vendor/symfony/routing/Symfony/Component/Routing/Loader/YamlFileLoader.php
vendored
Normal file
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
|
||||
/**
|
||||
* YamlFileLoader loads Yaml routing files.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class YamlFileLoader extends FileLoader
|
||||
{
|
||||
private static $availableKeys = array(
|
||||
'resource', 'type', 'prefix', 'pattern', 'path', 'host', 'schemes', 'methods', 'defaults', 'requirements', 'options',
|
||||
);
|
||||
private $yamlParser;
|
||||
|
||||
/**
|
||||
* Loads a Yaml file.
|
||||
*
|
||||
* @param string $file A Yaml file path
|
||||
* @param string|null $type The resource type
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function load($file, $type = null)
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
if (!stream_is_local($path)) {
|
||||
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
|
||||
}
|
||||
|
||||
if (null === $this->yamlParser) {
|
||||
$this->yamlParser = new YamlParser();
|
||||
}
|
||||
|
||||
$config = $this->yamlParser->parse(file_get_contents($path));
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->addResource(new FileResource($path));
|
||||
|
||||
// empty file
|
||||
if (null === $config) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
// not an array
|
||||
if (!is_array($config)) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
|
||||
}
|
||||
|
||||
foreach ($config as $name => $config) {
|
||||
if (isset($config['pattern'])) {
|
||||
if (isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
|
||||
}
|
||||
|
||||
$config['path'] = $config['pattern'];
|
||||
unset($config['pattern']);
|
||||
}
|
||||
|
||||
$this->validate($config, $name, $path);
|
||||
|
||||
if (isset($config['resource'])) {
|
||||
$this->parseImport($collection, $config, $path, $file);
|
||||
} else {
|
||||
$this->parseRoute($collection, $name, $config, $path);
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'yaml' === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a route and adds it to the RouteCollection.
|
||||
*
|
||||
* @param RouteCollection $collection A RouteCollection instance
|
||||
* @param string $name Route name
|
||||
* @param array $config Route definition
|
||||
* @param string $path Full path of the YAML file being processed
|
||||
*/
|
||||
protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
|
||||
{
|
||||
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
|
||||
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
|
||||
$options = isset($config['options']) ? $config['options'] : array();
|
||||
$host = isset($config['host']) ? $config['host'] : '';
|
||||
$schemes = isset($config['schemes']) ? $config['schemes'] : array();
|
||||
$methods = isset($config['methods']) ? $config['methods'] : array();
|
||||
|
||||
$route = new Route($config['path'], $defaults, $requirements, $options, $host, $schemes, $methods);
|
||||
|
||||
$collection->add($name, $route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an import and adds the routes in the resource to the RouteCollection.
|
||||
*
|
||||
* @param RouteCollection $collection A RouteCollection instance
|
||||
* @param array $config Route definition
|
||||
* @param string $path Full path of the YAML file being processed
|
||||
* @param string $file Loaded file name
|
||||
*/
|
||||
protected function parseImport(RouteCollection $collection, array $config, $path, $file)
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : null;
|
||||
$prefix = isset($config['prefix']) ? $config['prefix'] : '';
|
||||
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
|
||||
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
|
||||
$options = isset($config['options']) ? $config['options'] : array();
|
||||
$host = isset($config['host']) ? $config['host'] : null;
|
||||
$schemes = isset($config['schemes']) ? $config['schemes'] : null;
|
||||
$methods = isset($config['methods']) ? $config['methods'] : null;
|
||||
|
||||
$this->setCurrentDir(dirname($path));
|
||||
|
||||
$subCollection = $this->import($config['resource'], $type, false, $file);
|
||||
/* @var $subCollection RouteCollection */
|
||||
$subCollection->addPrefix($prefix);
|
||||
if (null !== $host) {
|
||||
$subCollection->setHost($host);
|
||||
}
|
||||
if (null !== $schemes) {
|
||||
$subCollection->setSchemes($schemes);
|
||||
}
|
||||
if (null !== $methods) {
|
||||
$subCollection->setMethods($methods);
|
||||
}
|
||||
$subCollection->addDefaults($defaults);
|
||||
$subCollection->addRequirements($requirements);
|
||||
$subCollection->addOptions($options);
|
||||
|
||||
$collection->addCollection($subCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the route configuration.
|
||||
*
|
||||
* @param array $config A resource config
|
||||
* @param string $name The config key
|
||||
* @param string $path The loaded file path
|
||||
*
|
||||
* @throws \InvalidArgumentException If one of the provided config keys is not supported,
|
||||
* something is missing or the combination is nonsense
|
||||
*/
|
||||
protected function validate($config, $name, $path)
|
||||
{
|
||||
if (!is_array($config)) {
|
||||
throw new \InvalidArgumentException(sprintf('The definition of "%s" in "%s" must be a YAML array.', $name, $path));
|
||||
}
|
||||
if ($extraKeys = array_diff(array_keys($config), self::$availableKeys)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The routing file "%s" contains unsupported keys for "%s": "%s". Expected one of: "%s".',
|
||||
$path, $name, implode('", "', $extraKeys), implode('", "', self::$availableKeys)
|
||||
));
|
||||
}
|
||||
if (isset($config['resource']) && isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.',
|
||||
$path, $name
|
||||
));
|
||||
}
|
||||
if (!isset($config['resource']) && isset($config['type'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "type" key for the route definition "%s" in "%s" is unsupported. It is only available for imports in combination with the "resource" key.',
|
||||
$name, $path
|
||||
));
|
||||
}
|
||||
if (!isset($config['resource']) && !isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'You must define a "path" for the route "%s" in file "%s".',
|
||||
$name, $path
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
64
vendor/symfony/routing/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd
vendored
Normal file
64
vendor/symfony/routing/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<xsd:schema xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://symfony.com/schema/routing"
|
||||
elementFormDefault="qualified">
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Symfony XML Routing Schema, version 1.0
|
||||
Authors: Fabien Potencier, Tobias Schultze
|
||||
|
||||
This scheme defines the elements and attributes that can be used to define
|
||||
routes. A route maps an HTTP request to a set of configuration variables.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="routes" type="routes" />
|
||||
|
||||
<xsd:complexType name="routes">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="import" type="import" />
|
||||
<xsd:element name="route" type="route" />
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:group name="configs">
|
||||
<xsd:choice>
|
||||
<xsd:element name="default" nillable="true" type="element" />
|
||||
<xsd:element name="requirement" type="element" />
|
||||
<xsd:element name="option" type="element" />
|
||||
</xsd:choice>
|
||||
</xsd:group>
|
||||
|
||||
<xsd:complexType name="route">
|
||||
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
<xsd:attribute name="id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="path" type="xsd:string" />
|
||||
<xsd:attribute name="pattern" type="xsd:string" />
|
||||
<xsd:attribute name="host" type="xsd:string" />
|
||||
<xsd:attribute name="schemes" type="xsd:string" />
|
||||
<xsd:attribute name="methods" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="import">
|
||||
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
<xsd:attribute name="resource" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="prefix" type="xsd:string" />
|
||||
<xsd:attribute name="host" type="xsd:string" />
|
||||
<xsd:attribute name="schemes" type="xsd:string" />
|
||||
<xsd:attribute name="methods" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="element">
|
||||
<xsd:simpleContent>
|
||||
<xsd:extension base="xsd:string">
|
||||
<xsd:attribute name="key" type="xsd:string" use="required" />
|
||||
</xsd:extension>
|
||||
</xsd:simpleContent>
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
94
vendor/symfony/routing/Symfony/Component/Routing/Matcher/ApacheUrlMatcher.php
vendored
Normal file
94
vendor/symfony/routing/Symfony/Component/Routing/Matcher/ApacheUrlMatcher.php
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
|
||||
/**
|
||||
* ApacheUrlMatcher matches URL based on Apache mod_rewrite matching (see ApacheMatcherDumper).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
|
||||
*/
|
||||
class ApacheUrlMatcher extends UrlMatcher
|
||||
{
|
||||
/**
|
||||
* Tries to match a URL based on Apache mod_rewrite matching.
|
||||
*
|
||||
* Returns false if no route matches the URL.
|
||||
*
|
||||
* @param string $pathinfo The pathinfo to be parsed
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws MethodNotAllowedException If the current method is not allowed
|
||||
*/
|
||||
public function match($pathinfo)
|
||||
{
|
||||
$parameters = array();
|
||||
$defaults = array();
|
||||
$allow = array();
|
||||
$route = null;
|
||||
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
$name = $key;
|
||||
|
||||
// skip non-routing variables
|
||||
// this improves performance when $_SERVER contains many usual
|
||||
// variables like HTTP_*, DOCUMENT_ROOT, REQUEST_URI, ...
|
||||
if (false === strpos($name, '_ROUTING_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while (0 === strpos($name, 'REDIRECT_')) {
|
||||
$name = substr($name, 9);
|
||||
}
|
||||
|
||||
// expect _ROUTING_<type>_<name>
|
||||
// or _ROUTING_<type>
|
||||
|
||||
if (0 !== strpos($name, '_ROUTING_')) {
|
||||
continue;
|
||||
}
|
||||
if (false !== $pos = strpos($name, '_', 9)) {
|
||||
$type = substr($name, 9, $pos-9);
|
||||
$name = substr($name, $pos+1);
|
||||
} else {
|
||||
$type = substr($name, 9);
|
||||
}
|
||||
|
||||
if ('param' === $type) {
|
||||
if ('' !== $value) {
|
||||
$parameters[$name] = $value;
|
||||
}
|
||||
} elseif ('default' === $type) {
|
||||
$defaults[$name] = $value;
|
||||
} elseif ('route' === $type) {
|
||||
$route = $value;
|
||||
} elseif ('allow' === $type) {
|
||||
$allow[] = $name;
|
||||
}
|
||||
|
||||
unset($_SERVER[$key]);
|
||||
}
|
||||
|
||||
if (null !== $route) {
|
||||
$parameters['_route'] = $route;
|
||||
|
||||
return $this->mergeDefaults($parameters, $defaults);
|
||||
} elseif (0 < count($allow)) {
|
||||
throw new MethodNotAllowedException($allow);
|
||||
} else {
|
||||
return parent::match($pathinfo);
|
||||
}
|
||||
}
|
||||
}
|
252
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
vendored
Normal file
252
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
vendored
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Dumps a set of Apache mod_rewrite rules.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*/
|
||||
class ApacheMatcherDumper extends MatcherDumper
|
||||
{
|
||||
/**
|
||||
* Dumps a set of Apache mod_rewrite rules.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * script_name: The script name (app.php by default)
|
||||
* * base_uri: The base URI ("" by default)
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string A string to be used as Apache rewrite rules
|
||||
*
|
||||
* @throws \LogicException When the route regex is invalid
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
{
|
||||
$options = array_merge(array(
|
||||
'script_name' => 'app.php',
|
||||
'base_uri' => '',
|
||||
), $options);
|
||||
|
||||
$options['script_name'] = self::escape($options['script_name'], ' ', '\\');
|
||||
|
||||
$rules = array("# skip \"real\" requests\nRewriteCond %{REQUEST_FILENAME} -f\nRewriteRule .* - [QSA,L]");
|
||||
$methodVars = array();
|
||||
$hostRegexUnique = 0;
|
||||
$prevHostRegex = '';
|
||||
|
||||
foreach ($this->getRoutes()->all() as $name => $route) {
|
||||
|
||||
$compiledRoute = $route->compile();
|
||||
$hostRegex = $compiledRoute->getHostRegex();
|
||||
|
||||
if (null !== $hostRegex && $prevHostRegex !== $hostRegex) {
|
||||
$prevHostRegex = $hostRegex;
|
||||
$hostRegexUnique++;
|
||||
|
||||
$rule = array();
|
||||
|
||||
$regex = $this->regexToApacheRegex($hostRegex);
|
||||
$regex = self::escape($regex, ' ', '\\');
|
||||
|
||||
$rule[] = sprintf('RewriteCond %%{HTTP:Host} %s', $regex);
|
||||
|
||||
$variables = array();
|
||||
$variables[] = sprintf('E=__ROUTING_host_%s:1', $hostRegexUnique);
|
||||
|
||||
foreach ($compiledRoute->getHostVariables() as $i => $variable) {
|
||||
$variables[] = sprintf('E=__ROUTING_host_%s_%s:%%%d', $hostRegexUnique, $variable, $i+1);
|
||||
}
|
||||
|
||||
$variables = implode(',', $variables);
|
||||
|
||||
$rule[] = sprintf('RewriteRule .? - [%s]', $variables);
|
||||
|
||||
$rules[] = implode("\n", $rule);
|
||||
}
|
||||
|
||||
$rules[] = $this->dumpRoute($name, $route, $options, $hostRegexUnique);
|
||||
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
$methods = explode('|', strtoupper($req));
|
||||
$methodVars = array_merge($methodVars, $methods);
|
||||
}
|
||||
}
|
||||
if (0 < count($methodVars)) {
|
||||
$rule = array('# 405 Method Not Allowed');
|
||||
$methodVars = array_values(array_unique($methodVars));
|
||||
if (in_array('GET', $methodVars) && !in_array('HEAD', $methodVars)) {
|
||||
$methodVars[] = 'HEAD';
|
||||
}
|
||||
foreach ($methodVars as $i => $methodVar) {
|
||||
$rule[] = sprintf('RewriteCond %%{ENV:_ROUTING__allow_%s} =1%s', $methodVar, isset($methodVars[$i + 1]) ? ' [OR]' : '');
|
||||
}
|
||||
$rule[] = sprintf('RewriteRule .* %s [QSA,L]', $options['script_name']);
|
||||
|
||||
$rules[] = implode("\n", $rule);
|
||||
}
|
||||
|
||||
return implode("\n\n", $rules)."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a single route
|
||||
*
|
||||
* @param string $name Route name
|
||||
* @param Route $route The route
|
||||
* @param array $options Options
|
||||
* @param bool $hostRegexUnique Unique identifier for the host regex
|
||||
*
|
||||
* @return string The compiled route
|
||||
*/
|
||||
private function dumpRoute($name, $route, array $options, $hostRegexUnique)
|
||||
{
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
// prepare the apache regex
|
||||
$regex = $this->regexToApacheRegex($compiledRoute->getRegex());
|
||||
$regex = '^'.self::escape(preg_quote($options['base_uri']).substr($regex, 1), ' ', '\\');
|
||||
|
||||
$methods = $this->getRouteMethods($route);
|
||||
|
||||
$hasTrailingSlash = (!$methods || in_array('HEAD', $methods)) && '/$' === substr($regex, -2) && '^/$' !== $regex;
|
||||
|
||||
$variables = array('E=_ROUTING_route:'.$name);
|
||||
foreach ($compiledRoute->getHostVariables() as $variable) {
|
||||
$variables[] = sprintf('E=_ROUTING_param_%s:%%{ENV:__ROUTING_host_%s_%s}', $variable, $hostRegexUnique, $variable);
|
||||
}
|
||||
foreach ($compiledRoute->getPathVariables() as $i => $variable) {
|
||||
$variables[] = 'E=_ROUTING_param_'.$variable.':%'.($i + 1);
|
||||
}
|
||||
foreach ($route->getDefaults() as $key => $value) {
|
||||
$variables[] = 'E=_ROUTING_default_'.$key.':'.strtr($value, array(
|
||||
':' => '\\:',
|
||||
'=' => '\\=',
|
||||
'\\' => '\\\\',
|
||||
' ' => '\\ ',
|
||||
));
|
||||
}
|
||||
$variables = implode(',', $variables);
|
||||
|
||||
$rule = array("# $name");
|
||||
|
||||
// method mismatch
|
||||
if (0 < count($methods)) {
|
||||
$allow = array();
|
||||
foreach ($methods as $method) {
|
||||
$allow[] = 'E=_ROUTING_allow_'.$method.':1';
|
||||
}
|
||||
|
||||
if ($hostRegex = $compiledRoute->getHostRegex()) {
|
||||
$rule[] = sprintf("RewriteCond %%{ENV:__ROUTING_host_%s} =1", $hostRegexUnique);
|
||||
}
|
||||
|
||||
$rule[] = "RewriteCond %{REQUEST_URI} $regex";
|
||||
$rule[] = sprintf("RewriteCond %%{REQUEST_METHOD} !^(%s)$ [NC]", implode('|', $methods));
|
||||
$rule[] = sprintf('RewriteRule .* - [S=%d,%s]', $hasTrailingSlash ? 2 : 1, implode(',', $allow));
|
||||
}
|
||||
|
||||
// redirect with trailing slash appended
|
||||
if ($hasTrailingSlash) {
|
||||
|
||||
if ($hostRegex = $compiledRoute->getHostRegex()) {
|
||||
$rule[] = sprintf("RewriteCond %%{ENV:__ROUTING_host_%s} =1", $hostRegexUnique);
|
||||
}
|
||||
|
||||
$rule[] = 'RewriteCond %{REQUEST_URI} '.substr($regex, 0, -2).'$';
|
||||
$rule[] = 'RewriteRule .* $0/ [QSA,L,R=301]';
|
||||
}
|
||||
|
||||
// the main rule
|
||||
|
||||
if ($hostRegex = $compiledRoute->getHostRegex()) {
|
||||
$rule[] = sprintf("RewriteCond %%{ENV:__ROUTING_host_%s} =1", $hostRegexUnique);
|
||||
}
|
||||
|
||||
$rule[] = "RewriteCond %{REQUEST_URI} $regex";
|
||||
$rule[] = "RewriteRule .* {$options['script_name']} [QSA,L,$variables]";
|
||||
|
||||
return implode("\n", $rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns methods allowed for a route
|
||||
*
|
||||
* @param Route $route The route
|
||||
*
|
||||
* @return array The methods
|
||||
*/
|
||||
private function getRouteMethods(Route $route)
|
||||
{
|
||||
$methods = array();
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
$methods = explode('|', strtoupper($req));
|
||||
// GET and HEAD are equivalent
|
||||
if (in_array('GET', $methods) && !in_array('HEAD', $methods)) {
|
||||
$methods[] = 'HEAD';
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a regex to make it suitable for mod_rewrite
|
||||
*
|
||||
* @param string $regex The regex
|
||||
*
|
||||
* @return string The converted regex
|
||||
*/
|
||||
private function regexToApacheRegex($regex)
|
||||
{
|
||||
$regexPatternEnd = strrpos($regex, $regex[0]);
|
||||
|
||||
return preg_replace('/\?P<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string.
|
||||
*
|
||||
* @param string $string The string to be escaped
|
||||
* @param string $char The character to be escaped
|
||||
* @param string $with The character to be used for escaping
|
||||
*
|
||||
* @return string The escaped string
|
||||
*/
|
||||
private static function escape($string, $char, $with)
|
||||
{
|
||||
$escaped = false;
|
||||
$output = '';
|
||||
foreach (str_split($string) as $symbol) {
|
||||
if ($escaped) {
|
||||
$output .= $symbol;
|
||||
$escaped = false;
|
||||
continue;
|
||||
}
|
||||
if ($symbol === $char) {
|
||||
$output .= $with.$char;
|
||||
continue;
|
||||
}
|
||||
if ($symbol === $with) {
|
||||
$escaped = true;
|
||||
}
|
||||
$output .= $symbol;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
159
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php
vendored
Normal file
159
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
/**
|
||||
* Collection of routes.
|
||||
*
|
||||
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
|
||||
*/
|
||||
class DumperCollection implements \IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @var DumperCollection|null
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var (DumperCollection|DumperRoute)[]
|
||||
*/
|
||||
private $children = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $attributes = array();
|
||||
|
||||
/**
|
||||
* Returns the children routes and collections.
|
||||
*
|
||||
* @return (DumperCollection|DumperRoute)[] Array of DumperCollection|DumperRoute
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route or collection
|
||||
*
|
||||
* @param DumperRoute|DumperCollection The route or collection
|
||||
*/
|
||||
public function add($child)
|
||||
{
|
||||
if ($child instanceof DumperCollection) {
|
||||
$child->setParent($this);
|
||||
}
|
||||
$this->children[] = $child;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets children.
|
||||
*
|
||||
* @param array $children The children
|
||||
*/
|
||||
public function setAll(array $children)
|
||||
{
|
||||
foreach ($children as $child) {
|
||||
if ($child instanceof DumperCollection) {
|
||||
$child->setParent($this);
|
||||
}
|
||||
}
|
||||
$this->children = $children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the children.
|
||||
*
|
||||
* @return \Iterator The iterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root of the collection.
|
||||
*
|
||||
* @return DumperCollection The root collection
|
||||
*/
|
||||
public function getRoot()
|
||||
{
|
||||
return (null !== $this->parent) ? $this->parent->getRoot() : $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent collection.
|
||||
*
|
||||
* @return DumperCollection|null The parent collection or null if the collection has no parent
|
||||
*/
|
||||
protected function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent collection.
|
||||
*
|
||||
* @param DumperCollection $parent The parent collection
|
||||
*/
|
||||
protected function setParent(DumperCollection $parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the attribute is defined.
|
||||
*
|
||||
* @param string $name The attribute name
|
||||
*
|
||||
* @return Boolean true if the attribute is defined, false otherwise
|
||||
*/
|
||||
public function hasAttribute($name)
|
||||
{
|
||||
return array_key_exists($name, $this->attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an attribute by name.
|
||||
*
|
||||
* @param string $name The attribute name
|
||||
* @param mixed $default Default value is the attribute doesn't exist
|
||||
*
|
||||
* @return mixed The attribute value
|
||||
*/
|
||||
public function getAttribute($name, $default = null)
|
||||
{
|
||||
return $this->hasAttribute($name) ? $this->attributes[$name] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an attribute by name.
|
||||
*
|
||||
* @param string $name The attribute name
|
||||
* @param mixed $value The attribute value
|
||||
*/
|
||||
public function setAttribute($name, $value)
|
||||
{
|
||||
$this->attributes[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets multiple attributes.
|
||||
*
|
||||
* @param array $attributes The attributes
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
}
|
108
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php
vendored
Normal file
108
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
/**
|
||||
* Prefix tree of routes preserving routes order.
|
||||
*
|
||||
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
|
||||
*/
|
||||
class DumperPrefixCollection extends DumperCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $prefix = '';
|
||||
|
||||
/**
|
||||
* Returns the prefix.
|
||||
*
|
||||
* @return string The prefix
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route in the tree.
|
||||
*
|
||||
* @param DumperRoute $route The route
|
||||
*
|
||||
* @return DumperPrefixCollection The node the route was added to
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function addPrefixRoute(DumperRoute $route)
|
||||
{
|
||||
$prefix = $route->getRoute()->compile()->getStaticPrefix();
|
||||
|
||||
// Same prefix, add to current leave
|
||||
if ($this->prefix === $prefix) {
|
||||
$this->add($route);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Prefix starts with route's prefix
|
||||
if ('' === $this->prefix || 0 === strpos($prefix, $this->prefix)) {
|
||||
$collection = new DumperPrefixCollection();
|
||||
$collection->setPrefix(substr($prefix, 0, strlen($this->prefix)+1));
|
||||
$this->add($collection);
|
||||
|
||||
return $collection->addPrefixRoute($route);
|
||||
}
|
||||
|
||||
// No match, fallback to parent (recursively)
|
||||
|
||||
if (null === $parent = $this->getParent()) {
|
||||
throw new \LogicException("The collection root must not have a prefix");
|
||||
}
|
||||
|
||||
return $parent->addPrefixRoute($route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges nodes whose prefix ends with a slash
|
||||
*
|
||||
* Children of a node whose prefix ends with a slash are moved to the parent node
|
||||
*/
|
||||
public function mergeSlashNodes()
|
||||
{
|
||||
$children = array();
|
||||
|
||||
foreach ($this as $child) {
|
||||
if ($child instanceof self) {
|
||||
$child->mergeSlashNodes();
|
||||
if ('/' === substr($child->prefix, -1)) {
|
||||
$children = array_merge($children, $child->all());
|
||||
} else {
|
||||
$children[] = $child;
|
||||
}
|
||||
} else {
|
||||
$children[] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setAll($children);
|
||||
}
|
||||
}
|
64
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperRoute.php
vendored
Normal file
64
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperRoute.php
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Container for a Route.
|
||||
*
|
||||
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
|
||||
*/
|
||||
class DumperRoute
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Route
|
||||
*/
|
||||
private $route;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The route name
|
||||
* @param Route $route The route
|
||||
*/
|
||||
public function __construct($name, Route $route)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the route name.
|
||||
*
|
||||
* @return string The route name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the route.
|
||||
*
|
||||
* @return Route The route
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
return $this->route;
|
||||
}
|
||||
}
|
45
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php
vendored
Normal file
45
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* MatcherDumper is the abstract class for all built-in matcher dumpers.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class MatcherDumper implements MatcherDumperInterface
|
||||
{
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
private $routes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param RouteCollection $routes The RouteCollection to dump
|
||||
*/
|
||||
public function __construct(RouteCollection $routes)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes()
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
}
|
37
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php
vendored
Normal file
37
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/MatcherDumperInterface.php
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
/**
|
||||
* MatcherDumperInterface is the interface that all matcher dumper classes must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface MatcherDumperInterface
|
||||
{
|
||||
/**
|
||||
* Dumps a set of routes to a string representation of executable code
|
||||
* that can then be used to match a request against these routes.
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string Executable code
|
||||
*/
|
||||
public function dump(array $options = array());
|
||||
|
||||
/**
|
||||
* Gets the routes to dump.
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*/
|
||||
public function getRoutes();
|
||||
}
|
378
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
vendored
Normal file
378
vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
vendored
Normal file
|
@ -0,0 +1,378 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* PhpMatcherDumper creates a PHP class able to match URLs for a given set of routes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
|
||||
*/
|
||||
class PhpMatcherDumper extends MatcherDumper
|
||||
{
|
||||
/**
|
||||
* Dumps a set of routes to a PHP class.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * class: The class name
|
||||
* * base_class: The base class name
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string A PHP class representing the matcher class
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
{
|
||||
$options = array_replace(array(
|
||||
'class' => 'ProjectUrlMatcher',
|
||||
'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
|
||||
), $options);
|
||||
|
||||
// trailing slash support is only enabled if we know how to redirect the user
|
||||
$interfaces = class_implements($options['base_class']);
|
||||
$supportsRedirections = isset($interfaces['Symfony\\Component\\Routing\\Matcher\\RedirectableUrlMatcherInterface']);
|
||||
|
||||
return <<<EOF
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
/**
|
||||
* {$options['class']}
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class {$options['class']} extends {$options['base_class']}
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(RequestContext \$context)
|
||||
{
|
||||
\$this->context = \$context;
|
||||
}
|
||||
|
||||
{$this->generateMatchMethod($supportsRedirections)}
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the code for the match method implementing UrlMatcherInterface.
|
||||
*
|
||||
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
|
||||
*
|
||||
* @return string Match method as PHP code
|
||||
*/
|
||||
private function generateMatchMethod($supportsRedirections)
|
||||
{
|
||||
$code = rtrim($this->compileRoutes($this->getRoutes(), $supportsRedirections), "\n");
|
||||
|
||||
return <<<EOF
|
||||
public function match(\$pathinfo)
|
||||
{
|
||||
\$allow = array();
|
||||
\$pathinfo = rawurldecode(\$pathinfo);
|
||||
|
||||
$code
|
||||
|
||||
throw 0 < count(\$allow) ? new MethodNotAllowedException(array_unique(\$allow)) : new ResourceNotFoundException();
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code to match a RouteCollection with all its routes.
|
||||
*
|
||||
* @param RouteCollection $routes A RouteCollection instance
|
||||
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
|
||||
*
|
||||
* @return string PHP code
|
||||
*/
|
||||
private function compileRoutes(RouteCollection $routes, $supportsRedirections)
|
||||
{
|
||||
$fetchedHost = false;
|
||||
|
||||
$groups = $this->groupRoutesByHostRegex($routes);
|
||||
$code = '';
|
||||
|
||||
foreach ($groups as $collection) {
|
||||
if (null !== $regex = $collection->getAttribute('host_regex')) {
|
||||
if (!$fetchedHost) {
|
||||
$code .= " \$host = \$this->context->getHost();\n\n";
|
||||
$fetchedHost = true;
|
||||
}
|
||||
|
||||
$code .= sprintf(" if (preg_match(%s, \$host, \$hostMatches)) {\n", var_export($regex, true));
|
||||
}
|
||||
|
||||
$tree = $this->buildPrefixTree($collection);
|
||||
$groupCode = $this->compilePrefixRoutes($tree, $supportsRedirections);
|
||||
|
||||
if (null !== $regex) {
|
||||
// apply extra indention at each line (except empty ones)
|
||||
$groupCode = preg_replace('/^.{2,}$/m', ' $0', $groupCode);
|
||||
$code .= $groupCode;
|
||||
$code .= " }\n\n";
|
||||
} else {
|
||||
$code .= $groupCode;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code recursively to match a tree of routes
|
||||
*
|
||||
* @param DumperPrefixCollection $collection A DumperPrefixCollection instance
|
||||
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
|
||||
* @param string $parentPrefix Prefix of the parent collection
|
||||
*
|
||||
* @return string PHP code
|
||||
*/
|
||||
private function compilePrefixRoutes(DumperPrefixCollection $collection, $supportsRedirections, $parentPrefix = '')
|
||||
{
|
||||
$code = '';
|
||||
$prefix = $collection->getPrefix();
|
||||
$optimizable = 1 < strlen($prefix) && 1 < count($collection->all());
|
||||
$optimizedPrefix = $parentPrefix;
|
||||
|
||||
if ($optimizable) {
|
||||
$optimizedPrefix = $prefix;
|
||||
|
||||
$code .= sprintf(" if (0 === strpos(\$pathinfo, %s)) {\n", var_export($prefix, true));
|
||||
}
|
||||
|
||||
foreach ($collection as $route) {
|
||||
if ($route instanceof DumperCollection) {
|
||||
$code .= $this->compilePrefixRoutes($route, $supportsRedirections, $optimizedPrefix);
|
||||
} else {
|
||||
$code .= $this->compileRoute($route->getRoute(), $route->getName(), $supportsRedirections, $optimizedPrefix)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($optimizable) {
|
||||
$code .= " }\n\n";
|
||||
// apply extra indention at each line (except empty ones)
|
||||
$code = preg_replace('/^.{2,}$/m', ' $0', $code);
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles a single Route to PHP code used to match it against the path info.
|
||||
*
|
||||
* @param Route $route A Route instance
|
||||
* @param string $name The name of the Route
|
||||
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
|
||||
* @param string|null $parentPrefix The prefix of the parent collection used to optimize the code
|
||||
*
|
||||
* @return string PHP code
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
private function compileRoute(Route $route, $name, $supportsRedirections, $parentPrefix = null)
|
||||
{
|
||||
$code = '';
|
||||
$compiledRoute = $route->compile();
|
||||
$conditions = array();
|
||||
$hasTrailingSlash = false;
|
||||
$matches = false;
|
||||
$hostMatches = false;
|
||||
$methods = array();
|
||||
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
$methods = explode('|', strtoupper($req));
|
||||
// GET and HEAD are equivalent
|
||||
if (in_array('GET', $methods) && !in_array('HEAD', $methods)) {
|
||||
$methods[] = 'HEAD';
|
||||
}
|
||||
}
|
||||
|
||||
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
|
||||
|
||||
if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
|
||||
if ($supportsTrailingSlash && substr($m['url'], -1) === '/') {
|
||||
$conditions[] = sprintf("rtrim(\$pathinfo, '/') === %s", var_export(rtrim(str_replace('\\', '', $m['url']), '/'), true));
|
||||
$hasTrailingSlash = true;
|
||||
} else {
|
||||
$conditions[] = sprintf("\$pathinfo === %s", var_export(str_replace('\\', '', $m['url']), true));
|
||||
}
|
||||
} else {
|
||||
if ($compiledRoute->getStaticPrefix() && $compiledRoute->getStaticPrefix() !== $parentPrefix) {
|
||||
$conditions[] = sprintf("0 === strpos(\$pathinfo, %s)", var_export($compiledRoute->getStaticPrefix(), true));
|
||||
}
|
||||
|
||||
$regex = $compiledRoute->getRegex();
|
||||
if ($supportsTrailingSlash && $pos = strpos($regex, '/$')) {
|
||||
$regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2);
|
||||
$hasTrailingSlash = true;
|
||||
}
|
||||
$conditions[] = sprintf("preg_match(%s, \$pathinfo, \$matches)", var_export($regex, true));
|
||||
|
||||
$matches = true;
|
||||
}
|
||||
|
||||
if ($compiledRoute->getHostVariables()) {
|
||||
$hostMatches = true;
|
||||
}
|
||||
|
||||
$conditions = implode(' && ', $conditions);
|
||||
|
||||
$code .= <<<EOF
|
||||
// $name
|
||||
if ($conditions) {
|
||||
|
||||
EOF;
|
||||
|
||||
if ($methods) {
|
||||
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name);
|
||||
|
||||
if (1 === count($methods)) {
|
||||
$code .= <<<EOF
|
||||
if (\$this->context->getMethod() != '$methods[0]') {
|
||||
\$allow[] = '$methods[0]';
|
||||
goto $gotoname;
|
||||
}
|
||||
|
||||
|
||||
EOF;
|
||||
} else {
|
||||
$methods = implode("', '", $methods);
|
||||
$code .= <<<EOF
|
||||
if (!in_array(\$this->context->getMethod(), array('$methods'))) {
|
||||
\$allow = array_merge(\$allow, array('$methods'));
|
||||
goto $gotoname;
|
||||
}
|
||||
|
||||
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasTrailingSlash) {
|
||||
$code .= <<<EOF
|
||||
if (substr(\$pathinfo, -1) !== '/') {
|
||||
return \$this->redirect(\$pathinfo.'/', '$name');
|
||||
}
|
||||
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
if ($scheme = $route->getRequirement('_scheme')) {
|
||||
if (!$supportsRedirections) {
|
||||
throw new \LogicException('The "_scheme" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
|
||||
}
|
||||
|
||||
$code .= <<<EOF
|
||||
if (\$this->context->getScheme() !== '$scheme') {
|
||||
return \$this->redirect(\$pathinfo, '$name', '$scheme');
|
||||
}
|
||||
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
// optimize parameters array
|
||||
if ($matches || $hostMatches) {
|
||||
$vars = array();
|
||||
if ($hostMatches) {
|
||||
$vars[] = '$hostMatches';
|
||||
}
|
||||
if ($matches) {
|
||||
$vars[] = '$matches';
|
||||
}
|
||||
$vars[] = "array('_route' => '$name')";
|
||||
|
||||
$code .= sprintf(" return \$this->mergeDefaults(array_replace(%s), %s);\n"
|
||||
, implode(', ', $vars), str_replace("\n", '', var_export($route->getDefaults(), true)));
|
||||
|
||||
} elseif ($route->getDefaults()) {
|
||||
$code .= sprintf(" return %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true)));
|
||||
} else {
|
||||
$code .= sprintf(" return array('_route' => '%s');\n", $name);
|
||||
}
|
||||
$code .= " }\n";
|
||||
|
||||
if ($methods) {
|
||||
$code .= " $gotoname:\n";
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups consecutive routes having the same host regex.
|
||||
*
|
||||
* The result is a collection of collections of routes having the same host regex.
|
||||
*
|
||||
* @param RouteCollection $routes A flat RouteCollection
|
||||
*
|
||||
* @return DumperCollection A collection with routes grouped by host regex in sub-collections
|
||||
*/
|
||||
private function groupRoutesByHostRegex(RouteCollection $routes)
|
||||
{
|
||||
$groups = new DumperCollection();
|
||||
|
||||
$currentGroup = new DumperCollection();
|
||||
$currentGroup->setAttribute('host_regex', null);
|
||||
$groups->add($currentGroup);
|
||||
|
||||
foreach ($routes as $name => $route) {
|
||||
$hostRegex = $route->compile()->getHostRegex();
|
||||
if ($currentGroup->getAttribute('host_regex') !== $hostRegex) {
|
||||
$currentGroup = new DumperCollection();
|
||||
$currentGroup->setAttribute('host_regex', $hostRegex);
|
||||
$groups->add($currentGroup);
|
||||
}
|
||||
$currentGroup->add(new DumperRoute($name, $route));
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organizes the routes into a prefix tree.
|
||||
*
|
||||
* Routes order is preserved such that traversing the tree will traverse the
|
||||
* routes in the origin order.
|
||||
*
|
||||
* @param DumperCollection $collection A collection of routes
|
||||
*
|
||||
* @return DumperPrefixCollection
|
||||
*/
|
||||
private function buildPrefixTree(DumperCollection $collection)
|
||||
{
|
||||
$tree = new DumperPrefixCollection();
|
||||
$current = $tree;
|
||||
|
||||
foreach ($collection as $route) {
|
||||
$current = $current->addPrefixRoute($route);
|
||||
}
|
||||
|
||||
$tree->mergeSlashNodes();
|
||||
|
||||
return $tree;
|
||||
}
|
||||
}
|
61
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php
vendored
Normal file
61
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function handleRouteRequirements($pathinfo, $name, Route $route)
|
||||
{
|
||||
// check HTTP scheme requirement
|
||||
$scheme = $route->getRequirement('_scheme');
|
||||
if ($scheme && $this->context->getScheme() !== $scheme) {
|
||||
return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
|
||||
}
|
||||
|
||||
return array(self::REQUIREMENT_MATCH, null);
|
||||
}
|
||||
}
|
35
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php
vendored
Normal file
35
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
/**
|
||||
* RedirectableUrlMatcherInterface knows how to redirect the user.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface RedirectableUrlMatcherInterface
|
||||
{
|
||||
/**
|
||||
* Redirects the user to another URL.
|
||||
*
|
||||
* @param string $path The path info to redirect to.
|
||||
* @param string $route The route name that matched
|
||||
* @param string|null $scheme The URL scheme (null to keep the current one)
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function redirect($path, $route, $scheme = null);
|
||||
}
|
39
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RequestMatcherInterface.php
vendored
Normal file
39
vendor/symfony/routing/Symfony/Component/Routing/Matcher/RequestMatcherInterface.php
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
|
||||
/**
|
||||
* RequestMatcherInterface is the interface that all request matcher classes must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface RequestMatcherInterface
|
||||
{
|
||||
/**
|
||||
* Tries to match a request with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param Request $request The request to match
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If no matching resource could be found
|
||||
* @throws MethodNotAllowedException If a matching resource was found but the request method is not allowed
|
||||
*/
|
||||
public function matchRequest(Request $request);
|
||||
}
|
121
vendor/symfony/routing/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
vendored
Normal file
121
vendor/symfony/routing/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
|
||||
/**
|
||||
* TraceableUrlMatcher helps debug path info matching by tracing the match.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TraceableUrlMatcher extends UrlMatcher
|
||||
{
|
||||
const ROUTE_DOES_NOT_MATCH = 0;
|
||||
const ROUTE_ALMOST_MATCHES = 1;
|
||||
const ROUTE_MATCHES = 2;
|
||||
|
||||
protected $traces;
|
||||
|
||||
public function getTraces($pathinfo)
|
||||
{
|
||||
$this->traces = array();
|
||||
|
||||
try {
|
||||
$this->match($pathinfo);
|
||||
} catch (ExceptionInterface $e) {
|
||||
}
|
||||
|
||||
return $this->traces;
|
||||
}
|
||||
|
||||
protected function matchCollection($pathinfo, RouteCollection $routes)
|
||||
{
|
||||
foreach ($routes as $name => $route) {
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
|
||||
// does it match without any requirements?
|
||||
$r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
|
||||
$cr = $r->compile();
|
||||
if (!preg_match($cr->getRegex(), $pathinfo)) {
|
||||
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($route->getRequirements() as $n => $regex) {
|
||||
$r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
|
||||
$cr = $r->compile();
|
||||
|
||||
if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
|
||||
$this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// check host requirement
|
||||
$hostMatches = array();
|
||||
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
|
||||
$this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// check HTTP method requirement
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
// HEAD and GET are equivalent as per RFC
|
||||
if ('HEAD' === $method = $this->context->getMethod()) {
|
||||
$method = 'GET';
|
||||
}
|
||||
|
||||
if (!in_array($method, $req = explode('|', strtoupper($req)))) {
|
||||
$this->allow = array_merge($this->allow, $req);
|
||||
|
||||
$this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// check HTTP scheme requirement
|
||||
if ($scheme = $route->getRequirement('_scheme')) {
|
||||
if ($this->context->getScheme() !== $scheme) {
|
||||
$this->addTrace(sprintf('Scheme "%s" does not match the requirement ("%s"); the user will be redirected', $this->context->getScheme(), $scheme), self::ROUTE_ALMOST_MATCHES, $name, $route);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)
|
||||
{
|
||||
$this->traces[] = array(
|
||||
'log' => $log,
|
||||
'name' => $name,
|
||||
'level' => $level,
|
||||
'path' => null !== $route ? $route->getPath() : null,
|
||||
);
|
||||
}
|
||||
}
|
208
vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php
vendored
Normal file
208
vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php
vendored
Normal file
|
@ -0,0 +1,208 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* UrlMatcher matches URL based on a set of routes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class UrlMatcher implements UrlMatcherInterface
|
||||
{
|
||||
const REQUIREMENT_MATCH = 0;
|
||||
const REQUIREMENT_MISMATCH = 1;
|
||||
const ROUTE_MATCH = 2;
|
||||
|
||||
/**
|
||||
* @var RequestContext
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $allow = array();
|
||||
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
protected $routes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param RouteCollection $routes A RouteCollection instance
|
||||
* @param RequestContext $context The context
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct(RouteCollection $routes, RequestContext $context)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContext(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to match a URL with a set of routes.
|
||||
*
|
||||
* @param string $pathinfo The path info to be parsed
|
||||
* @param RouteCollection $routes The set of routes
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If the resource could not be found
|
||||
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
||||
*/
|
||||
protected function matchCollection($pathinfo, RouteCollection $routes)
|
||||
{
|
||||
foreach ($routes as $name => $route) {
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
|
||||
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;
|
||||
}
|
||||
|
||||
// check HTTP method requirement
|
||||
if ($req = $route->getRequirement('_method')) {
|
||||
// HEAD and GET are equivalent as per RFC
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of values to use as request attributes.
|
||||
*
|
||||
* As this method requires the Route object, it is not available
|
||||
* in matchers that do not have access to the matched Route instance
|
||||
* (like the PHP and Apache matcher dumpers).
|
||||
*
|
||||
* @param Route $route The route we are matching against
|
||||
* @param string $name The name of the route
|
||||
* @param array $attributes An array of attributes from the matcher
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*/
|
||||
protected function getAttributes(Route $route, $name, array $attributes)
|
||||
{
|
||||
$attributes['_route'] = $name;
|
||||
|
||||
return $this->mergeDefaults($attributes, $route->getDefaults());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles specific route requirements.
|
||||
*
|
||||
* @param string $pathinfo The path
|
||||
* @param string $name The route name
|
||||
* @param Route $route The route
|
||||
*
|
||||
* @return array The first element represents the status, the second contains additional information
|
||||
*/
|
||||
protected function handleRouteRequirements($pathinfo, $name, Route $route)
|
||||
{
|
||||
// check HTTP scheme requirement
|
||||
$scheme = $route->getRequirement('_scheme');
|
||||
$status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
|
||||
|
||||
return array($status, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get merged default parameters.
|
||||
*
|
||||
* @param array $params The parameters
|
||||
* @param array $defaults The defaults
|
||||
*
|
||||
* @return array Merged default parameters
|
||||
*/
|
||||
protected function mergeDefaults($params, $defaults)
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
if (!is_int($key)) {
|
||||
$defaults[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
}
|
43
vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcherInterface.php
vendored
Normal file
43
vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcherInterface.php
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\RequestContextAwareInterface;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
|
||||
/**
|
||||
* UrlMatcherInterface is the interface that all URL matcher classes must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface UrlMatcherInterface extends RequestContextAwareInterface
|
||||
{
|
||||
/**
|
||||
* Tries to match a URL path with a set of routes.
|
||||
*
|
||||
* If the matcher can not find information, it must throw one of the exceptions documented
|
||||
* below.
|
||||
*
|
||||
* @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @throws ResourceNotFoundException If the resource could not be found
|
||||
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function match($pathinfo);
|
||||
}
|
34
vendor/symfony/routing/Symfony/Component/Routing/README.md
vendored
Normal file
34
vendor/symfony/routing/Symfony/Component/Routing/README.md
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
Routing Component
|
||||
=================
|
||||
|
||||
Routing associates a request with the code that will convert it to a response.
|
||||
|
||||
The example below demonstrates how you can set up a fully working routing
|
||||
system:
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('hello', new Route('/hello', array('controller' => 'foo')));
|
||||
|
||||
$context = new RequestContext();
|
||||
|
||||
// this is optional and can be done without a Request instance
|
||||
$context->fromRequest(Request::createFromGlobals());
|
||||
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
|
||||
$parameters = $matcher->match('/hello');
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
$ cd path/to/Symfony/Component/Routing/
|
||||
$ composer.phar install --dev
|
||||
$ phpunit
|
315
vendor/symfony/routing/Symfony/Component/Routing/RequestContext.php
vendored
Normal file
315
vendor/symfony/routing/Symfony/Component/Routing/RequestContext.php
vendored
Normal file
|
@ -0,0 +1,315 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Holds information about the current request.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class RequestContext
|
||||
{
|
||||
private $baseUrl;
|
||||
private $pathInfo;
|
||||
private $method;
|
||||
private $host;
|
||||
private $scheme;
|
||||
private $httpPort;
|
||||
private $httpsPort;
|
||||
private $queryString;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $parameters = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $baseUrl The base URL
|
||||
* @param string $method The HTTP method
|
||||
* @param string $host The HTTP host name
|
||||
* @param string $scheme The HTTP scheme
|
||||
* @param integer $httpPort The HTTP port
|
||||
* @param integer $httpsPort The HTTPS port
|
||||
* @param string $path The path
|
||||
* @param string $queryString The query string
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base URL.
|
||||
*
|
||||
* @return string The base URL
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base URL.
|
||||
*
|
||||
* @param string $baseUrl The base URL
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setBaseUrl($baseUrl)
|
||||
{
|
||||
$this->baseUrl = $baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path info.
|
||||
*
|
||||
* @return string The path info
|
||||
*/
|
||||
public function getPathInfo()
|
||||
{
|
||||
return $this->pathInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path info.
|
||||
*
|
||||
* @param string $pathInfo The path info
|
||||
*/
|
||||
public function setPathInfo($pathInfo)
|
||||
{
|
||||
$this->pathInfo = $pathInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP method.
|
||||
*
|
||||
* The method is always an uppercased string.
|
||||
*
|
||||
* @return string The HTTP method
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP method.
|
||||
*
|
||||
* @param string $method The HTTP method
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = strtoupper($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP host.
|
||||
*
|
||||
* @return string The HTTP host
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP host.
|
||||
*
|
||||
* @param string $host The HTTP host
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP scheme.
|
||||
*
|
||||
* @return string The HTTP scheme
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP scheme.
|
||||
*
|
||||
* @param string $scheme The HTTP scheme
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setScheme($scheme)
|
||||
{
|
||||
$this->scheme = strtolower($scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP port.
|
||||
*
|
||||
* @return string The HTTP port
|
||||
*/
|
||||
public function getHttpPort()
|
||||
{
|
||||
return $this->httpPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP port.
|
||||
*
|
||||
* @param string $httpPort The HTTP port
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setHttpPort($httpPort)
|
||||
{
|
||||
$this->httpPort = $httpPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTPS port.
|
||||
*
|
||||
* @return string The HTTPS port
|
||||
*/
|
||||
public function getHttpsPort()
|
||||
{
|
||||
return $this->httpsPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTPS port.
|
||||
*
|
||||
* @param string $httpsPort The HTTPS port
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setHttpsPort($httpsPort)
|
||||
{
|
||||
$this->httpsPort = $httpsPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the query string.
|
||||
*
|
||||
* @return string The query string
|
||||
*/
|
||||
public function getQueryString()
|
||||
{
|
||||
return $this->queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query string.
|
||||
*
|
||||
* @param string $queryString The query string
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setQueryString($queryString)
|
||||
{
|
||||
$this->queryString = $queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parameters.
|
||||
*
|
||||
* @return array The parameters
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameters.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $parameters The parameters
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setParameters(array $parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a parameter value.
|
||||
*
|
||||
* @param string $name A parameter name
|
||||
*
|
||||
* @return mixed The parameter value
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a parameter value is set for the given parameter.
|
||||
*
|
||||
* @param string $name A parameter name
|
||||
*
|
||||
* @return Boolean true if the parameter value is set, false otherwise
|
||||
*/
|
||||
public function hasParameter($name)
|
||||
{
|
||||
return array_key_exists($name, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter value.
|
||||
*
|
||||
* @param string $name A parameter name
|
||||
* @param mixed $parameter The parameter value
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setParameter($name, $parameter)
|
||||
{
|
||||
$this->parameters[$name] = $parameter;
|
||||
}
|
||||
}
|
36
vendor/symfony/routing/Symfony/Component/Routing/RequestContextAwareInterface.php
vendored
Normal file
36
vendor/symfony/routing/Symfony/Component/Routing/RequestContextAwareInterface.php
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
interface RequestContextAwareInterface
|
||||
{
|
||||
/**
|
||||
* Sets the request context.
|
||||
*
|
||||
* @param RequestContext $context The context
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setContext(RequestContext $context);
|
||||
|
||||
/**
|
||||
* Gets the request context.
|
||||
*
|
||||
* @return RequestContext The context
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getContext();
|
||||
}
|
594
vendor/symfony/routing/Symfony/Component/Routing/Route.php
vendored
Normal file
594
vendor/symfony/routing/Symfony/Component/Routing/Route.php
vendored
Normal file
|
@ -0,0 +1,594 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
/**
|
||||
* A Route describes a route and its parameters.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class Route implements \Serializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path = '/';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $schemes = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $methods = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $defaults = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $requirements = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = array();
|
||||
|
||||
/**
|
||||
* @var null|RouteCompiler
|
||||
*/
|
||||
private $compiled;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * compiler_class: A class name able to compile this route instance (RouteCompiler by default)
|
||||
*
|
||||
* @param string $path The path pattern to match
|
||||
* @param array $defaults An array of default parameter values
|
||||
* @param array $requirements An array of requirements for parameters (regexes)
|
||||
* @param array $options An array of options
|
||||
* @param string $host The host pattern to match
|
||||
* @param string|array $schemes A required URI scheme or an array of restricted schemes
|
||||
* @param string|array $methods A required HTTP method or an array of restricted methods
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($path, array $defaults = array(), array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array())
|
||||
{
|
||||
$this->setPath($path);
|
||||
$this->setDefaults($defaults);
|
||||
$this->setRequirements($requirements);
|
||||
$this->setOptions($options);
|
||||
$this->setHost($host);
|
||||
// The conditions make sure that an initial empty $schemes/$methods does not override the corresponding requirement.
|
||||
// They can be removed when the BC layer is removed.
|
||||
if ($schemes) {
|
||||
$this->setSchemes($schemes);
|
||||
}
|
||||
if ($methods) {
|
||||
$this->setMethods($methods);
|
||||
}
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
'path' => $this->path,
|
||||
'host' => $this->host,
|
||||
'defaults' => $this->defaults,
|
||||
'requirements' => $this->requirements,
|
||||
'options' => $this->options,
|
||||
'schemes' => $this->schemes,
|
||||
'methods' => $this->methods,
|
||||
));
|
||||
}
|
||||
|
||||
public function unserialize($data)
|
||||
{
|
||||
$data = unserialize($data);
|
||||
$this->path = $data['path'];
|
||||
$this->host = $data['host'];
|
||||
$this->defaults = $data['defaults'];
|
||||
$this->requirements = $data['requirements'];
|
||||
$this->options = $data['options'];
|
||||
$this->schemes = $data['schemes'];
|
||||
$this->methods = $data['methods'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the path.
|
||||
*
|
||||
* @return string The pattern
|
||||
*
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use getPath instead.
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pattern for the path.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $pattern The path pattern
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
return $this->setPath($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the path.
|
||||
*
|
||||
* @return string The path pattern
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pattern for the path.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $pattern The path pattern
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setPath($pattern)
|
||||
{
|
||||
// A pattern must start with a slash and must not have multiple slashes at the beginning because the
|
||||
// generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
|
||||
$this->path = '/'.ltrim(trim($pattern), '/');
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the host.
|
||||
*
|
||||
* @return string The host pattern
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pattern for the host.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $pattern The host pattern
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setHost($pattern)
|
||||
{
|
||||
$this->host = (string) $pattern;
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lowercased schemes this route is restricted to.
|
||||
* So an empty array means that any scheme is allowed.
|
||||
*
|
||||
* @return array The schemes
|
||||
*/
|
||||
public function getSchemes()
|
||||
{
|
||||
return $this->schemes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the schemes (e.g. 'https') this route is restricted to.
|
||||
* So an empty array means that any scheme is allowed.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string|array $schemes The scheme or an array of schemes
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setSchemes($schemes)
|
||||
{
|
||||
$this->schemes = array_map('strtolower', (array) $schemes);
|
||||
|
||||
// this is to keep BC and will be removed in a future version
|
||||
if ($this->schemes) {
|
||||
$this->requirements['_scheme'] = implode('|', $this->schemes);
|
||||
} else {
|
||||
unset($this->requirements['_scheme']);
|
||||
}
|
||||
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the uppercased HTTP methods this route is restricted to.
|
||||
* So an empty array means that any method is allowed.
|
||||
*
|
||||
* @return array The schemes
|
||||
*/
|
||||
public function getMethods()
|
||||
{
|
||||
return $this->methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP methods (e.g. 'POST') this route is restricted to.
|
||||
* So an empty array means that any method is allowed.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string|array $methods The method or an array of methods
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setMethods($methods)
|
||||
{
|
||||
$this->methods = array_map('strtoupper', (array) $methods);
|
||||
|
||||
// this is to keep BC and will be removed in a future version
|
||||
if ($this->methods) {
|
||||
$this->requirements['_method'] = implode('|', $this->methods);
|
||||
} else {
|
||||
unset($this->requirements['_method']);
|
||||
}
|
||||
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options.
|
||||
*
|
||||
* @return array The options
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the options.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array(
|
||||
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
|
||||
);
|
||||
|
||||
return $this->addOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds options.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function addOptions(array $options)
|
||||
{
|
||||
foreach ($options as $name => $option) {
|
||||
$this->options[$name] = $option;
|
||||
}
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option value.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $name An option name
|
||||
* @param mixed $value The option value
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
$this->options[$name] = $value;
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option value.
|
||||
*
|
||||
* @param string $name An option name
|
||||
*
|
||||
* @return mixed The option value or null when not given
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
return isset($this->options[$name]) ? $this->options[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an option has been set
|
||||
*
|
||||
* @param string $name An option name
|
||||
*
|
||||
* @return Boolean true if the option is set, false otherwise
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return array_key_exists($name, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the defaults.
|
||||
*
|
||||
* @return array The defaults
|
||||
*/
|
||||
public function getDefaults()
|
||||
{
|
||||
return $this->defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the defaults.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $defaults The defaults
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setDefaults(array $defaults)
|
||||
{
|
||||
$this->defaults = array();
|
||||
|
||||
return $this->addDefaults($defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds defaults.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $defaults The defaults
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function addDefaults(array $defaults)
|
||||
{
|
||||
foreach ($defaults as $name => $default) {
|
||||
$this->defaults[$name] = $default;
|
||||
}
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a default value.
|
||||
*
|
||||
* @param string $name A variable name
|
||||
*
|
||||
* @return mixed The default value or null when not given
|
||||
*/
|
||||
public function getDefault($name)
|
||||
{
|
||||
return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a default value is set for the given variable.
|
||||
*
|
||||
* @param string $name A variable name
|
||||
*
|
||||
* @return Boolean true if the default value is set, false otherwise
|
||||
*/
|
||||
public function hasDefault($name)
|
||||
{
|
||||
return array_key_exists($name, $this->defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a default value.
|
||||
*
|
||||
* @param string $name A variable name
|
||||
* @param mixed $default The default value
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDefault($name, $default)
|
||||
{
|
||||
$this->defaults[$name] = $default;
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirements.
|
||||
*
|
||||
* @return array The requirements
|
||||
*/
|
||||
public function getRequirements()
|
||||
{
|
||||
return $this->requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the requirements.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $requirements The requirements
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setRequirements(array $requirements)
|
||||
{
|
||||
$this->requirements = array();
|
||||
|
||||
return $this->addRequirements($requirements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds requirements.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $requirements The requirements
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function addRequirements(array $requirements)
|
||||
{
|
||||
foreach ($requirements as $key => $regex) {
|
||||
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
|
||||
}
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirement for the given key.
|
||||
*
|
||||
* @param string $key The key
|
||||
*
|
||||
* @return string|null The regex or null when not given
|
||||
*/
|
||||
public function getRequirement($key)
|
||||
{
|
||||
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a requirement is set for the given key.
|
||||
*
|
||||
* @param string $key A variable name
|
||||
*
|
||||
* @return Boolean true if a requirement is specified, false otherwise
|
||||
*/
|
||||
public function hasRequirement($key)
|
||||
{
|
||||
return array_key_exists($key, $this->requirements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a requirement for the given key.
|
||||
*
|
||||
* @param string $key The key
|
||||
* @param string $regex The regex
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setRequirement($key, $regex)
|
||||
{
|
||||
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the route.
|
||||
*
|
||||
* @return CompiledRoute A CompiledRoute instance
|
||||
*
|
||||
* @throws \LogicException If the Route cannot be compiled because the
|
||||
* path or host pattern is invalid
|
||||
*
|
||||
* @see RouteCompiler which is responsible for the compilation process
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
if (null !== $this->compiled) {
|
||||
return $this->compiled;
|
||||
}
|
||||
|
||||
$class = $this->getOption('compiler_class');
|
||||
|
||||
return $this->compiled = $class::compile($this);
|
||||
}
|
||||
|
||||
private function sanitizeRequirement($key, $regex)
|
||||
{
|
||||
if (!is_string($regex)) {
|
||||
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key));
|
||||
}
|
||||
|
||||
if ('' !== $regex && '^' === $regex[0]) {
|
||||
$regex = (string) substr($regex, 1); // returns false for a single character
|
||||
}
|
||||
|
||||
if ('$' === substr($regex, -1)) {
|
||||
$regex = substr($regex, 0, -1);
|
||||
}
|
||||
|
||||
if ('' === $regex) {
|
||||
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key));
|
||||
}
|
||||
|
||||
// this is to keep BC and will be removed in a future version
|
||||
if ('_scheme' === $key) {
|
||||
$this->setSchemes(explode('|', $regex));
|
||||
} elseif ('_method' === $key) {
|
||||
$this->setMethods(explode('|', $regex));
|
||||
}
|
||||
|
||||
return $regex;
|
||||
}
|
||||
}
|
271
vendor/symfony/routing/Symfony/Component/Routing/RouteCollection.php
vendored
Normal file
271
vendor/symfony/routing/Symfony/Component/Routing/RouteCollection.php
vendored
Normal file
|
@ -0,0 +1,271 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
use Symfony\Component\Config\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* A RouteCollection represents a set of Route instances.
|
||||
*
|
||||
* When adding a route at the end of the collection, an existing route
|
||||
* with the same name is removed first. So there can only be one route
|
||||
* with a given name.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class RouteCollection implements \IteratorAggregate, \Countable
|
||||
{
|
||||
/**
|
||||
* @var Route[]
|
||||
*/
|
||||
private $routes = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $resources = array();
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->routes as $name => $route) {
|
||||
$this->routes[$name] = clone $route;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current RouteCollection as an Iterator that includes all routes.
|
||||
*
|
||||
* It implements \IteratorAggregate.
|
||||
*
|
||||
* @see all()
|
||||
*
|
||||
* @return \ArrayIterator An \ArrayIterator object for iterating over routes
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->routes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of Routes in this collection.
|
||||
*
|
||||
* @return int The number of routes
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->routes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route.
|
||||
*
|
||||
* @param string $name The route name
|
||||
* @param Route $route A Route instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function add($name, Route $route)
|
||||
{
|
||||
unset($this->routes[$name]);
|
||||
|
||||
$this->routes[$name] = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all routes in this collection.
|
||||
*
|
||||
* @return Route[] An array of routes
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a route by name.
|
||||
*
|
||||
* @param string $name The route name
|
||||
*
|
||||
* @return Route|null A Route instance or null when not found
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
return isset($this->routes[$name]) ? $this->routes[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a route or an array of routes by name from the collection
|
||||
*
|
||||
* @param string|array $name The route name or an array of route names
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
foreach ((array) $name as $n) {
|
||||
unset($this->routes[$n]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a route collection at the end of the current set by appending all
|
||||
* routes of the added collection.
|
||||
*
|
||||
* @param RouteCollection $collection A RouteCollection instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addCollection(RouteCollection $collection)
|
||||
{
|
||||
// we need to remove all routes with the same names first because just replacing them
|
||||
// would not place the new route at the end of the merged array
|
||||
foreach ($collection->all() as $name => $route) {
|
||||
unset($this->routes[$name]);
|
||||
$this->routes[$name] = $route;
|
||||
}
|
||||
|
||||
$this->resources = array_merge($this->resources, $collection->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a prefix to the path of all child routes.
|
||||
*
|
||||
* @param string $prefix An optional prefix to add before each pattern of the route collection
|
||||
* @param array $defaults An array of default values
|
||||
* @param array $requirements An array of requirements
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
|
||||
{
|
||||
$prefix = trim(trim($prefix), '/');
|
||||
|
||||
if ('' === $prefix) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->routes as $route) {
|
||||
$route->setPath('/'.$prefix.$route->getPath());
|
||||
$route->addDefaults($defaults);
|
||||
$route->addRequirements($requirements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host pattern on all routes.
|
||||
*
|
||||
* @param string $pattern The pattern
|
||||
* @param array $defaults An array of default values
|
||||
* @param array $requirements An array of requirements
|
||||
*/
|
||||
public function setHost($pattern, array $defaults = array(), array $requirements = array())
|
||||
{
|
||||
foreach ($this->routes as $route) {
|
||||
$route->setHost($pattern);
|
||||
$route->addDefaults($defaults);
|
||||
$route->addRequirements($requirements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds defaults to all routes.
|
||||
*
|
||||
* An existing default value under the same name in a route will be overridden.
|
||||
*
|
||||
* @param array $defaults An array of default values
|
||||
*/
|
||||
public function addDefaults(array $defaults)
|
||||
{
|
||||
if ($defaults) {
|
||||
foreach ($this->routes as $route) {
|
||||
$route->addDefaults($defaults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds requirements to all routes.
|
||||
*
|
||||
* An existing requirement under the same name in a route will be overridden.
|
||||
*
|
||||
* @param array $requirements An array of requirements
|
||||
*/
|
||||
public function addRequirements(array $requirements)
|
||||
{
|
||||
if ($requirements) {
|
||||
foreach ($this->routes as $route) {
|
||||
$route->addRequirements($requirements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds options to all routes.
|
||||
*
|
||||
* An existing option value under the same name in a route will be overridden.
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*/
|
||||
public function addOptions(array $options)
|
||||
{
|
||||
if ($options) {
|
||||
foreach ($this->routes as $route) {
|
||||
$route->addOptions($options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the schemes (e.g. 'https') all child routes are restricted to.
|
||||
*
|
||||
* @param string|array $schemes The scheme or an array of schemes
|
||||
*/
|
||||
public function setSchemes($schemes)
|
||||
{
|
||||
foreach ($this->routes as $route) {
|
||||
$route->setSchemes($schemes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP methods (e.g. 'POST') all child routes are restricted to.
|
||||
*
|
||||
* @param string|array $methods The method or an array of methods
|
||||
*/
|
||||
public function setMethods($methods)
|
||||
{
|
||||
foreach ($this->routes as $route) {
|
||||
$route->setMethods($methods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of resources loaded to build this collection.
|
||||
*
|
||||
* @return ResourceInterface[] An array of resources
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
return array_unique($this->resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a resource for this collection.
|
||||
*
|
||||
* @param ResourceInterface $resource A resource instance
|
||||
*/
|
||||
public function addResource(ResourceInterface $resource)
|
||||
{
|
||||
$this->resources[] = $resource;
|
||||
}
|
||||
}
|
233
vendor/symfony/routing/Symfony/Component/Routing/RouteCompiler.php
vendored
Normal file
233
vendor/symfony/routing/Symfony/Component/Routing/RouteCompiler.php
vendored
Normal file
|
@ -0,0 +1,233 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
/**
|
||||
* RouteCompiler compiles Route instances to CompiledRoute instances.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
class RouteCompiler implements RouteCompilerInterface
|
||||
{
|
||||
const REGEX_DELIMITER = '#';
|
||||
|
||||
/**
|
||||
* This string defines the characters that are automatically considered separators in front of
|
||||
* optional placeholders (with default and no static text following). Such a single separator
|
||||
* can be left out together with the optional placeholder from matching and generating URLs.
|
||||
*/
|
||||
const SEPARATORS = '/,;.:-_~+*=@|';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws \LogicException If a variable is referenced more than once
|
||||
* @throws \DomainException If a variable name is numeric because PHP raises an error for such
|
||||
* subpatterns in PCRE and thus would break matching, e.g. "(?P<123>.+)".
|
||||
*/
|
||||
public static function compile(Route $route)
|
||||
{
|
||||
$staticPrefix = null;
|
||||
$hostVariables = array();
|
||||
$pathVariables = array();
|
||||
$variables = array();
|
||||
$tokens = array();
|
||||
$regex = null;
|
||||
$hostRegex = null;
|
||||
$hostTokens = array();
|
||||
|
||||
if ('' !== $host = $route->getHost()) {
|
||||
$result = self::compilePattern($route, $host, true);
|
||||
|
||||
$hostVariables = $result['variables'];
|
||||
$variables = array_merge($variables, $hostVariables);
|
||||
|
||||
$hostTokens = $result['tokens'];
|
||||
$hostRegex = $result['regex'];
|
||||
}
|
||||
|
||||
$path = $route->getPath();
|
||||
|
||||
$result = self::compilePattern($route, $path, false);
|
||||
|
||||
$staticPrefix = $result['staticPrefix'];
|
||||
|
||||
$pathVariables = $result['variables'];
|
||||
$variables = array_merge($variables, $pathVariables);
|
||||
|
||||
$tokens = $result['tokens'];
|
||||
$regex = $result['regex'];
|
||||
|
||||
return new CompiledRoute(
|
||||
$staticPrefix,
|
||||
$regex,
|
||||
$tokens,
|
||||
$pathVariables,
|
||||
$hostRegex,
|
||||
$hostTokens,
|
||||
$hostVariables,
|
||||
array_unique($variables)
|
||||
);
|
||||
}
|
||||
|
||||
private static function compilePattern(Route $route, $pattern, $isHost)
|
||||
{
|
||||
$tokens = array();
|
||||
$variables = array();
|
||||
$matches = array();
|
||||
$pos = 0;
|
||||
$defaultSeparator = $isHost ? '.' : '/';
|
||||
|
||||
// Match all variables enclosed in "{}" and iterate over them. But we only want to match the innermost variable
|
||||
// in case of nested "{}", e.g. {foo{bar}}. This in ensured because \w does not match "{" or "}" itself.
|
||||
preg_match_all('#\{\w+\}#', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$varName = substr($match[0][0], 1, -1);
|
||||
// get all static text preceding the current variable
|
||||
$precedingText = substr($pattern, $pos, $match[0][1] - $pos);
|
||||
$pos = $match[0][1] + strlen($match[0][0]);
|
||||
$precedingChar = strlen($precedingText) > 0 ? substr($precedingText, -1) : '';
|
||||
$isSeparator = '' !== $precedingChar && false !== strpos(static::SEPARATORS, $precedingChar);
|
||||
|
||||
if (is_numeric($varName)) {
|
||||
throw new \DomainException(sprintf('Variable name "%s" cannot be numeric in route pattern "%s". Please use a different name.', $varName, $pattern));
|
||||
}
|
||||
if (in_array($varName, $variables)) {
|
||||
throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName));
|
||||
}
|
||||
|
||||
if ($isSeparator && strlen($precedingText) > 1) {
|
||||
$tokens[] = array('text', substr($precedingText, 0, -1));
|
||||
} elseif (!$isSeparator && strlen($precedingText) > 0) {
|
||||
$tokens[] = array('text', $precedingText);
|
||||
}
|
||||
|
||||
$regexp = $route->getRequirement($varName);
|
||||
if (null === $regexp) {
|
||||
$followingPattern = (string) substr($pattern, $pos);
|
||||
// Find the next static character after the variable that functions as a separator. By default, this separator and '/'
|
||||
// are disallowed for the variable. This default requirement makes sure that optional variables can be matched at all
|
||||
// and that the generating-matching-combination of URLs unambiguous, i.e. the params used for generating the URL are
|
||||
// the same that will be matched. Example: new Route('/{page}.{_format}', array('_format' => 'html'))
|
||||
// If {page} would also match the separating dot, {_format} would never match as {page} will eagerly consume everything.
|
||||
// Also even if {_format} was not optional the requirement prevents that {page} matches something that was originally
|
||||
// part of {_format} when generating the URL, e.g. _format = 'mobile.html'.
|
||||
$nextSeparator = self::findNextSeparator($followingPattern);
|
||||
$regexp = sprintf(
|
||||
'[^%s%s]+',
|
||||
preg_quote($defaultSeparator, self::REGEX_DELIMITER),
|
||||
$defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator, self::REGEX_DELIMITER) : ''
|
||||
);
|
||||
if (('' !== $nextSeparator && !preg_match('#^\{\w+\}#', $followingPattern)) || '' === $followingPattern) {
|
||||
// When we have a separator, which is disallowed for the variable, we can optimize the regex with a possessive
|
||||
// quantifier. This prevents useless backtracking of PCRE and improves performance by 20% for matching those patterns.
|
||||
// Given the above example, there is no point in backtracking into {page} (that forbids the dot) when a dot must follow
|
||||
// after it. This optimization cannot be applied when the next char is no real separator or when the next variable is
|
||||
// directly adjacent, e.g. '/{x}{y}'.
|
||||
$regexp .= '+';
|
||||
}
|
||||
}
|
||||
|
||||
$tokens[] = array('variable', $isSeparator ? $precedingChar : '', $regexp, $varName);
|
||||
$variables[] = $varName;
|
||||
}
|
||||
|
||||
if ($pos < strlen($pattern)) {
|
||||
$tokens[] = array('text', substr($pattern, $pos));
|
||||
}
|
||||
|
||||
// find the first optional token
|
||||
$firstOptional = PHP_INT_MAX;
|
||||
if (!$isHost) {
|
||||
for ($i = count($tokens) - 1; $i >= 0; $i--) {
|
||||
$token = $tokens[$i];
|
||||
if ('variable' === $token[0] && $route->hasDefault($token[3])) {
|
||||
$firstOptional = $i;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// compute the matching regexp
|
||||
$regexp = '';
|
||||
for ($i = 0, $nbToken = count($tokens); $i < $nbToken; $i++) {
|
||||
$regexp .= self::computeRegexp($tokens, $i, $firstOptional);
|
||||
}
|
||||
|
||||
return array(
|
||||
'staticPrefix' => 'text' === $tokens[0][0] ? $tokens[0][1] : '',
|
||||
'regex' => self::REGEX_DELIMITER.'^'.$regexp.'$'.self::REGEX_DELIMITER.'s',
|
||||
'tokens' => array_reverse($tokens),
|
||||
'variables' => $variables,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next static character in the Route pattern that will serve as a separator.
|
||||
*
|
||||
* @param string $pattern The route pattern
|
||||
*
|
||||
* @return string The next static character that functions as separator (or empty string when none available)
|
||||
*/
|
||||
private static function findNextSeparator($pattern)
|
||||
{
|
||||
if ('' == $pattern) {
|
||||
// return empty string if pattern is empty or false (false which can be returned by substr)
|
||||
return '';
|
||||
}
|
||||
// first remove all placeholders from the pattern so we can find the next real static character
|
||||
$pattern = preg_replace('#\{\w+\}#', '', $pattern);
|
||||
|
||||
return isset($pattern[0]) && false !== strpos(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the regexp used to match a specific token. It can be static text or a subpattern.
|
||||
*
|
||||
* @param array $tokens The route tokens
|
||||
* @param integer $index The index of the current token
|
||||
* @param integer $firstOptional The index of the first optional token
|
||||
*
|
||||
* @return string The regexp pattern for a single token
|
||||
*/
|
||||
private static function computeRegexp(array $tokens, $index, $firstOptional)
|
||||
{
|
||||
$token = $tokens[$index];
|
||||
if ('text' === $token[0]) {
|
||||
// Text tokens
|
||||
return preg_quote($token[1], self::REGEX_DELIMITER);
|
||||
} else {
|
||||
// Variable tokens
|
||||
if (0 === $index && 0 === $firstOptional) {
|
||||
// When the only token is an optional variable token, the separator is required
|
||||
return sprintf('%s(?P<%s>%s)?', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
|
||||
} else {
|
||||
$regexp = sprintf('%s(?P<%s>%s)', preg_quote($token[1], self::REGEX_DELIMITER), $token[3], $token[2]);
|
||||
if ($index >= $firstOptional) {
|
||||
// Enclose each optional token in a subpattern to make it optional.
|
||||
// "?:" means it is non-capturing, i.e. the portion of the subject string that
|
||||
// matched the optional subpattern is not passed back.
|
||||
$regexp = "(?:$regexp";
|
||||
$nbTokens = count($tokens);
|
||||
if ($nbTokens - 1 == $index) {
|
||||
// Close the optional subpatterns
|
||||
$regexp .= str_repeat(")?", $nbTokens - $firstOptional - (0 === $firstOptional ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
return $regexp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
vendor/symfony/routing/Symfony/Component/Routing/RouteCompilerInterface.php
vendored
Normal file
32
vendor/symfony/routing/Symfony/Component/Routing/RouteCompilerInterface.php
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
/**
|
||||
* RouteCompilerInterface is the interface that all RouteCompiler classes must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface RouteCompilerInterface
|
||||
{
|
||||
/**
|
||||
* Compiles the current route instance.
|
||||
*
|
||||
* @param Route $route A Route instance
|
||||
*
|
||||
* @return CompiledRoute A CompiledRoute instance
|
||||
*
|
||||
* @throws \LogicException If the Route cannot be compiled because the
|
||||
* path or host pattern is invalid
|
||||
*/
|
||||
public static function compile(Route $route);
|
||||
}
|
289
vendor/symfony/routing/Symfony/Component/Routing/Router.php
vendored
Normal file
289
vendor/symfony/routing/Symfony/Component/Routing/Router.php
vendored
Normal file
|
@ -0,0 +1,289 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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\Matcher\UrlMatcherInterface;
|
||||
|
||||
/**
|
||||
* The Router class is an example of the integration of all pieces of the
|
||||
* routing system for easier use.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Router implements RouterInterface
|
||||
{
|
||||
/**
|
||||
* @var UrlMatcherInterface|null
|
||||
*/
|
||||
protected $matcher;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface|null
|
||||
*/
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
* @var RequestContext
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var LoaderInterface
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* @var RouteCollection|null
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* @var LoggerInterface|null
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param LoaderInterface $loader A LoaderInterface instance
|
||||
* @param mixed $resource The main resource to load
|
||||
* @param array $options An array of options
|
||||
* @param RequestContext $context The context
|
||||
* @param LoggerInterface $logger A logger instance
|
||||
*/
|
||||
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 = null === $context ? new RequestContext() : $context;
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets options.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * cache_dir: The cache directory (or null to disable caching)
|
||||
* * debug: Whether to enable debugging or not (false by default)
|
||||
* * resource_type: Type hint for the main resource (optional)
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @throws \InvalidArgumentException When unsupported option is provided
|
||||
*/
|
||||
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,
|
||||
);
|
||||
|
||||
// check option names and live merge, if errors are encountered Exception will be thrown
|
||||
$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)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option.
|
||||
*
|
||||
* @param string $key The key
|
||||
* @param mixed $value The value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an option value.
|
||||
*
|
||||
* @param string $key The key
|
||||
*
|
||||
* @return mixed The value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteCollection()
|
||||
{
|
||||
if (null === $this->collection) {
|
||||
$this->collection = $this->loader->load($this->resource, $this->options['resource_type']);
|
||||
}
|
||||
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContext(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
|
||||
if (null !== $this->matcher) {
|
||||
$this->getMatcher()->setContext($context);
|
||||
}
|
||||
if (null !== $this->generator) {
|
||||
$this->getGenerator()->setContext($context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
return $this->getGenerator()->generate($name, $parameters, $referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function match($pathinfo)
|
||||
{
|
||||
return $this->getMatcher()->match($pathinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UrlMatcher instance associated with this Router.
|
||||
*
|
||||
* @return UrlMatcherInterface A UrlMatcherInterface instance
|
||||
*/
|
||||
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($class)) {
|
||||
$dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UrlGenerator instance associated with this Router.
|
||||
*
|
||||
* @return UrlGeneratorInterface A UrlGeneratorInterface instance
|
||||
*/
|
||||
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($class)) {
|
||||
$dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
32
vendor/symfony/routing/Symfony/Component/Routing/RouterInterface.php
vendored
Normal file
32
vendor/symfony/routing/Symfony/Component/Routing/RouterInterface.php
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing;
|
||||
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
||||
|
||||
/**
|
||||
* RouterInterface is the interface that all Router classes must implement.
|
||||
*
|
||||
* This interface is the concatenation of UrlMatcherInterface and UrlGeneratorInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface RouterInterface extends UrlMatcherInterface, UrlGeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Gets the RouteCollection instance associated with this Router.
|
||||
*
|
||||
* @return RouteCollection A RouteCollection instance
|
||||
*/
|
||||
public function getRouteCollection();
|
||||
}
|
49
vendor/symfony/routing/Symfony/Component/Routing/Tests/Annotation/RouteTest.php
vendored
Normal file
49
vendor/symfony/routing/Symfony/Component/Routing/Tests/Annotation/RouteTest.php
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Annotation;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testInvalidRouteParameter()
|
||||
{
|
||||
$route = new Route(array('foo' => 'bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidParameters
|
||||
*/
|
||||
public function testRouteParameters($parameter, $value, $getter)
|
||||
{
|
||||
$route = new Route(array($parameter => $value));
|
||||
$this->assertEquals($route->$getter(), $value);
|
||||
}
|
||||
|
||||
public function getValidParameters()
|
||||
{
|
||||
return array(
|
||||
array('value', '/Blog', 'getPattern'),
|
||||
array('value', '/Blog', 'getPath'),
|
||||
array('requirements', array('_method' => 'GET'), 'getRequirements'),
|
||||
array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'),
|
||||
array('name', 'blog_index', 'getName'),
|
||||
array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults'),
|
||||
array('schemes', array('https'), 'getSchemes'),
|
||||
array('methods', array('GET', 'POST'), 'getMethods'),
|
||||
array('host', array('{locale}.example.com'), 'getHost')
|
||||
);
|
||||
}
|
||||
}
|
26
vendor/symfony/routing/Symfony/Component/Routing/Tests/CompiledRouteTest.php
vendored
Normal file
26
vendor/symfony/routing/Symfony/Component/Routing/Tests/CompiledRouteTest.php
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests;
|
||||
|
||||
use Symfony\Component\Routing\CompiledRoute;
|
||||
|
||||
class CompiledRouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAccessors()
|
||||
{
|
||||
$compiled = new CompiledRoute('prefix', 'regex', array('tokens'), array(), array(), array(), array(), array('variables'));
|
||||
$this->assertEquals('prefix', $compiled->getStaticPrefix(), '__construct() takes a static prefix as its second argument');
|
||||
$this->assertEquals('regex', $compiled->getRegex(), '__construct() takes a regexp as its third argument');
|
||||
$this->assertEquals(array('tokens'), $compiled->getTokens(), '__construct() takes an array of tokens as its fourth argument');
|
||||
$this->assertEquals(array('variables'), $compiled->getVariables(), '__construct() takes an array of variables as its ninth argument');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
|
||||
|
||||
abstract class AbstractClass
|
||||
{
|
||||
}
|
19
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php
vendored
Normal file
19
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
|
||||
|
||||
class BarClass
|
||||
{
|
||||
public function routeAction($arg1, $arg2 = 'defaultValue2', $arg3 = 'defaultValue3')
|
||||
{
|
||||
}
|
||||
}
|
16
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooClass.php
vendored
Normal file
16
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/FooClass.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
|
||||
|
||||
class FooClass
|
||||
{
|
||||
}
|
26
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php
vendored
Normal file
26
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/CustomXmlFileLoader.php
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Routing\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
|
||||
/**
|
||||
* XmlFileLoader with schema validation turned off
|
||||
*/
|
||||
class CustomXmlFileLoader extends XmlFileLoader
|
||||
{
|
||||
protected function loadFile($file)
|
||||
{
|
||||
return XmlUtils::loadFile($file, function() { return true; });
|
||||
}
|
||||
}
|
30
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php
vendored
Normal file
30
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/RedirectableUrlMatcher.php
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
|
||||
{
|
||||
public function redirect($path, $route, $scheme = null)
|
||||
{
|
||||
return array(
|
||||
'_controller' => 'Some controller reference...',
|
||||
'path' => $path,
|
||||
'scheme' => $scheme,
|
||||
);
|
||||
}
|
||||
}
|
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/annotated.php
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/annotated.php
vendored
Normal file
163
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache
vendored
Normal file
163
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.apache
vendored
Normal file
|
@ -0,0 +1,163 @@
|
|||
# skip "real" requests
|
||||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteRule .* - [QSA,L]
|
||||
|
||||
# foo
|
||||
RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foo,E=_ROUTING_param_bar:%1,E=_ROUTING_default_def:test]
|
||||
|
||||
# foobar
|
||||
RewriteCond %{REQUEST_URI} ^/foo(?:/([^/]++))?$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foobar,E=_ROUTING_param_bar:%1,E=_ROUTING_default_bar:toto]
|
||||
|
||||
# bar
|
||||
RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$
|
||||
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC]
|
||||
RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1]
|
||||
RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:bar,E=_ROUTING_param_foo:%1]
|
||||
|
||||
# baragain
|
||||
RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$
|
||||
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$ [NC]
|
||||
RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_POST:1,E=_ROUTING_allow_HEAD:1]
|
||||
RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baragain,E=_ROUTING_param_foo:%1]
|
||||
|
||||
# baz
|
||||
RewriteCond %{REQUEST_URI} ^/test/baz$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz]
|
||||
|
||||
# baz2
|
||||
RewriteCond %{REQUEST_URI} ^/test/baz\.html$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz2]
|
||||
|
||||
# baz3
|
||||
RewriteCond %{REQUEST_URI} ^/test/baz3$
|
||||
RewriteRule .* $0/ [QSA,L,R=301]
|
||||
RewriteCond %{REQUEST_URI} ^/test/baz3/$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz3]
|
||||
|
||||
# baz4
|
||||
RewriteCond %{REQUEST_URI} ^/test/([^/]++)$
|
||||
RewriteRule .* $0/ [QSA,L,R=301]
|
||||
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz4,E=_ROUTING_param_foo:%1]
|
||||
|
||||
# baz5
|
||||
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
|
||||
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC]
|
||||
RewriteRule .* - [S=2,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1]
|
||||
RewriteCond %{REQUEST_URI} ^/test/([^/]++)$
|
||||
RewriteRule .* $0/ [QSA,L,R=301]
|
||||
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5,E=_ROUTING_param_foo:%1]
|
||||
|
||||
# baz5unsafe
|
||||
RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$
|
||||
RewriteCond %{REQUEST_METHOD} !^(POST)$ [NC]
|
||||
RewriteRule .* - [S=1,E=_ROUTING_allow_POST:1]
|
||||
RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5unsafe,E=_ROUTING_param_foo:%1]
|
||||
|
||||
# baz6
|
||||
RewriteCond %{REQUEST_URI} ^/test/baz$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz6,E=_ROUTING_default_foo:bar\ baz]
|
||||
|
||||
# baz7
|
||||
RewriteCond %{REQUEST_URI} ^/te\ st/baz$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz7]
|
||||
|
||||
# baz8
|
||||
RewriteCond %{REQUEST_URI} ^/te\\\ st/baz$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz8]
|
||||
|
||||
# baz9
|
||||
RewriteCond %{REQUEST_URI} ^/test/(te\\\ st)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz9,E=_ROUTING_param_baz:%1]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^a\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_1:1]
|
||||
|
||||
# route1
|
||||
RewriteCond %{ENV:__ROUTING_host_1} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route1$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route1]
|
||||
|
||||
# route2
|
||||
RewriteCond %{ENV:__ROUTING_host_1} =1
|
||||
RewriteCond %{REQUEST_URI} ^/c2/route2$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route2]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^b\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_2:1]
|
||||
|
||||
# route3
|
||||
RewriteCond %{ENV:__ROUTING_host_2} =1
|
||||
RewriteCond %{REQUEST_URI} ^/c2/route3$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route3]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^a\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_3:1]
|
||||
|
||||
# route4
|
||||
RewriteCond %{ENV:__ROUTING_host_3} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route4$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route4]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^c\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_4:1]
|
||||
|
||||
# route5
|
||||
RewriteCond %{ENV:__ROUTING_host_4} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route5$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route5]
|
||||
|
||||
# route6
|
||||
RewriteCond %{REQUEST_URI} ^/route6$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route6]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^([^\.]++)\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_5:1,E=__ROUTING_host_5_var1:%1]
|
||||
|
||||
# route11
|
||||
RewriteCond %{ENV:__ROUTING_host_5} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route11$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route11,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1}]
|
||||
|
||||
# route12
|
||||
RewriteCond %{ENV:__ROUTING_host_5} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route12$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route12,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_default_var1:val]
|
||||
|
||||
# route13
|
||||
RewriteCond %{ENV:__ROUTING_host_5} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route13/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route13,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1]
|
||||
|
||||
# route14
|
||||
RewriteCond %{ENV:__ROUTING_host_5} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route14/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route14,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val]
|
||||
|
||||
RewriteCond %{HTTP:Host} ^c\.example\.com$
|
||||
RewriteRule .? - [E=__ROUTING_host_6:1]
|
||||
|
||||
# route15
|
||||
RewriteCond %{ENV:__ROUTING_host_6} =1
|
||||
RewriteCond %{REQUEST_URI} ^/route15/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route15,E=_ROUTING_param_name:%1]
|
||||
|
||||
# route16
|
||||
RewriteCond %{REQUEST_URI} ^/route16/([^/]++)$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route16,E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val]
|
||||
|
||||
# route17
|
||||
RewriteCond %{REQUEST_URI} ^/route17$
|
||||
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route17]
|
||||
|
||||
# 405 Method Not Allowed
|
||||
RewriteCond %{ENV:_ROUTING__allow_GET} =1 [OR]
|
||||
RewriteCond %{ENV:_ROUTING__allow_HEAD} =1 [OR]
|
||||
RewriteCond %{ENV:_ROUTING__allow_POST} =1
|
||||
RewriteRule .* app.php [QSA,L]
|
310
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
vendored
Normal file
310
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
vendored
Normal file
|
@ -0,0 +1,310 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
/**
|
||||
* ProjectUrlMatcher
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function match($pathinfo)
|
||||
{
|
||||
$allow = array();
|
||||
$pathinfo = rawurldecode($pathinfo);
|
||||
|
||||
// foo
|
||||
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/bar')) {
|
||||
// bar
|
||||
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
|
||||
$allow = array_merge($allow, array('GET', 'HEAD'));
|
||||
goto not_bar;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
|
||||
}
|
||||
not_bar:
|
||||
|
||||
// barhead
|
||||
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
|
||||
$allow = array_merge($allow, array('GET', 'HEAD'));
|
||||
goto not_barhead;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
|
||||
}
|
||||
not_barhead:
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/test')) {
|
||||
if (0 === strpos($pathinfo, '/test/baz')) {
|
||||
// baz
|
||||
if ($pathinfo === '/test/baz') {
|
||||
return array('_route' => 'baz');
|
||||
}
|
||||
|
||||
// baz2
|
||||
if ($pathinfo === '/test/baz.html') {
|
||||
return array('_route' => 'baz2');
|
||||
}
|
||||
|
||||
// baz3
|
||||
if ($pathinfo === '/test/baz3/') {
|
||||
return array('_route' => 'baz3');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// baz4
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
|
||||
}
|
||||
|
||||
// baz5
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||
if ($this->context->getMethod() != 'POST') {
|
||||
$allow[] = 'POST';
|
||||
goto not_baz5;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
|
||||
}
|
||||
not_baz5:
|
||||
|
||||
// baz.baz6
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||
if ($this->context->getMethod() != 'PUT') {
|
||||
$allow[] = 'PUT';
|
||||
goto not_bazbaz6;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
|
||||
}
|
||||
not_bazbaz6:
|
||||
|
||||
}
|
||||
|
||||
// foofoo
|
||||
if ($pathinfo === '/foofoo') {
|
||||
return array ( 'def' => 'test', '_route' => 'foofoo',);
|
||||
}
|
||||
|
||||
// quoter
|
||||
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
|
||||
}
|
||||
|
||||
// space
|
||||
if ($pathinfo === '/spa ce') {
|
||||
return array('_route' => 'space');
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a')) {
|
||||
if (0 === strpos($pathinfo, '/a/b\'b')) {
|
||||
// foo1
|
||||
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
|
||||
}
|
||||
|
||||
// bar1
|
||||
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// overridden
|
||||
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a/b\'b')) {
|
||||
// foo2
|
||||
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
|
||||
}
|
||||
|
||||
// bar2
|
||||
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/multi')) {
|
||||
// helloWorld
|
||||
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
|
||||
}
|
||||
|
||||
// overridden2
|
||||
if ($pathinfo === '/multi/new') {
|
||||
return array('_route' => 'overridden2');
|
||||
}
|
||||
|
||||
// hey
|
||||
if ($pathinfo === '/multi/hey/') {
|
||||
return array('_route' => 'hey');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// foo3
|
||||
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
|
||||
}
|
||||
|
||||
// bar3
|
||||
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/aba')) {
|
||||
// ababa
|
||||
if ($pathinfo === '/ababa') {
|
||||
return array('_route' => 'ababa');
|
||||
}
|
||||
|
||||
// foo4
|
||||
if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$host = $this->context->getHost();
|
||||
|
||||
if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route1
|
||||
if ($pathinfo === '/route1') {
|
||||
return array('_route' => 'route1');
|
||||
}
|
||||
|
||||
// route2
|
||||
if ($pathinfo === '/c2/route2') {
|
||||
return array('_route' => 'route2');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^b\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route3
|
||||
if ($pathinfo === '/c2/route3') {
|
||||
return array('_route' => 'route3');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route4
|
||||
if ($pathinfo === '/route4') {
|
||||
return array('_route' => 'route4');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route5
|
||||
if ($pathinfo === '/route5') {
|
||||
return array('_route' => 'route5');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// route6
|
||||
if ($pathinfo === '/route6') {
|
||||
return array('_route' => 'route6');
|
||||
}
|
||||
|
||||
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
if (0 === strpos($pathinfo, '/route1')) {
|
||||
// route11
|
||||
if ($pathinfo === '/route11') {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ());
|
||||
}
|
||||
|
||||
// route12
|
||||
if ($pathinfo === '/route12') {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
// route13
|
||||
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ());
|
||||
}
|
||||
|
||||
// route14
|
||||
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route15
|
||||
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/route1')) {
|
||||
// route16
|
||||
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
// route17
|
||||
if ($pathinfo === '/route17') {
|
||||
return array('_route' => 'route17');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a')) {
|
||||
// a
|
||||
if ($pathinfo === '/a/a...') {
|
||||
return array('_route' => 'a');
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a/b')) {
|
||||
// b
|
||||
if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
|
||||
}
|
||||
|
||||
// c
|
||||
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
|
||||
}
|
||||
}
|
7
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.apache
vendored
Normal file
7
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.apache
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# skip "real" requests
|
||||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteRule .* - [QSA,L]
|
||||
|
||||
# foo
|
||||
RewriteCond %{REQUEST_URI} ^/foo$
|
||||
RewriteRule .* ap\ p_d\ ev.php [QSA,L,E=_ROUTING_route:foo]
|
340
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
vendored
Normal file
340
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
vendored
Normal file
|
@ -0,0 +1,340 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
/**
|
||||
* ProjectUrlMatcher
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function match($pathinfo)
|
||||
{
|
||||
$allow = array();
|
||||
$pathinfo = rawurldecode($pathinfo);
|
||||
|
||||
// foo
|
||||
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/bar')) {
|
||||
// bar
|
||||
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
|
||||
$allow = array_merge($allow, array('GET', 'HEAD'));
|
||||
goto not_bar;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
|
||||
}
|
||||
not_bar:
|
||||
|
||||
// barhead
|
||||
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
|
||||
$allow = array_merge($allow, array('GET', 'HEAD'));
|
||||
goto not_barhead;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
|
||||
}
|
||||
not_barhead:
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/test')) {
|
||||
if (0 === strpos($pathinfo, '/test/baz')) {
|
||||
// baz
|
||||
if ($pathinfo === '/test/baz') {
|
||||
return array('_route' => 'baz');
|
||||
}
|
||||
|
||||
// baz2
|
||||
if ($pathinfo === '/test/baz.html') {
|
||||
return array('_route' => 'baz2');
|
||||
}
|
||||
|
||||
// baz3
|
||||
if (rtrim($pathinfo, '/') === '/test/baz3') {
|
||||
if (substr($pathinfo, -1) !== '/') {
|
||||
return $this->redirect($pathinfo.'/', 'baz3');
|
||||
}
|
||||
|
||||
return array('_route' => 'baz3');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// baz4
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/?$#s', $pathinfo, $matches)) {
|
||||
if (substr($pathinfo, -1) !== '/') {
|
||||
return $this->redirect($pathinfo.'/', 'baz4');
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
|
||||
}
|
||||
|
||||
// baz5
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||
if ($this->context->getMethod() != 'POST') {
|
||||
$allow[] = 'POST';
|
||||
goto not_baz5;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
|
||||
}
|
||||
not_baz5:
|
||||
|
||||
// baz.baz6
|
||||
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
|
||||
if ($this->context->getMethod() != 'PUT') {
|
||||
$allow[] = 'PUT';
|
||||
goto not_bazbaz6;
|
||||
}
|
||||
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
|
||||
}
|
||||
not_bazbaz6:
|
||||
|
||||
}
|
||||
|
||||
// foofoo
|
||||
if ($pathinfo === '/foofoo') {
|
||||
return array ( 'def' => 'test', '_route' => 'foofoo',);
|
||||
}
|
||||
|
||||
// quoter
|
||||
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
|
||||
}
|
||||
|
||||
// space
|
||||
if ($pathinfo === '/spa ce') {
|
||||
return array('_route' => 'space');
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a')) {
|
||||
if (0 === strpos($pathinfo, '/a/b\'b')) {
|
||||
// foo1
|
||||
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
|
||||
}
|
||||
|
||||
// bar1
|
||||
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// overridden
|
||||
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a/b\'b')) {
|
||||
// foo2
|
||||
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
|
||||
}
|
||||
|
||||
// bar2
|
||||
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/multi')) {
|
||||
// helloWorld
|
||||
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
|
||||
}
|
||||
|
||||
// overridden2
|
||||
if ($pathinfo === '/multi/new') {
|
||||
return array('_route' => 'overridden2');
|
||||
}
|
||||
|
||||
// hey
|
||||
if (rtrim($pathinfo, '/') === '/multi/hey') {
|
||||
if (substr($pathinfo, -1) !== '/') {
|
||||
return $this->redirect($pathinfo.'/', 'hey');
|
||||
}
|
||||
|
||||
return array('_route' => 'hey');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// foo3
|
||||
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
|
||||
}
|
||||
|
||||
// bar3
|
||||
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/aba')) {
|
||||
// ababa
|
||||
if ($pathinfo === '/ababa') {
|
||||
return array('_route' => 'ababa');
|
||||
}
|
||||
|
||||
// foo4
|
||||
if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$host = $this->context->getHost();
|
||||
|
||||
if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route1
|
||||
if ($pathinfo === '/route1') {
|
||||
return array('_route' => 'route1');
|
||||
}
|
||||
|
||||
// route2
|
||||
if ($pathinfo === '/c2/route2') {
|
||||
return array('_route' => 'route2');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^b\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route3
|
||||
if ($pathinfo === '/c2/route3') {
|
||||
return array('_route' => 'route3');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^a\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route4
|
||||
if ($pathinfo === '/route4') {
|
||||
return array('_route' => 'route4');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route5
|
||||
if ($pathinfo === '/route5') {
|
||||
return array('_route' => 'route5');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// route6
|
||||
if ($pathinfo === '/route6') {
|
||||
return array('_route' => 'route6');
|
||||
}
|
||||
|
||||
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
if (0 === strpos($pathinfo, '/route1')) {
|
||||
// route11
|
||||
if ($pathinfo === '/route11') {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ());
|
||||
}
|
||||
|
||||
// route12
|
||||
if ($pathinfo === '/route12') {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
// route13
|
||||
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ());
|
||||
}
|
||||
|
||||
// route14
|
||||
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (preg_match('#^c\\.example\\.com$#s', $host, $hostMatches)) {
|
||||
// route15
|
||||
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/route1')) {
|
||||
// route16
|
||||
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
|
||||
}
|
||||
|
||||
// route17
|
||||
if ($pathinfo === '/route17') {
|
||||
return array('_route' => 'route17');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a')) {
|
||||
// a
|
||||
if ($pathinfo === '/a/a...') {
|
||||
return array('_route' => 'a');
|
||||
}
|
||||
|
||||
if (0 === strpos($pathinfo, '/a/b')) {
|
||||
// b
|
||||
if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
|
||||
}
|
||||
|
||||
// c
|
||||
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// secure
|
||||
if ($pathinfo === '/secure') {
|
||||
if ($this->context->getScheme() !== 'https') {
|
||||
return $this->redirect($pathinfo, 'secure', 'https');
|
||||
}
|
||||
|
||||
return array('_route' => 'secure');
|
||||
}
|
||||
|
||||
// nonsecure
|
||||
if ($pathinfo === '/nonsecure') {
|
||||
if ($this->context->getScheme() !== 'http') {
|
||||
return $this->redirect($pathinfo, 'nonsecure', 'http');
|
||||
}
|
||||
|
||||
return array('_route' => 'nonsecure');
|
||||
}
|
||||
|
||||
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
|
||||
}
|
||||
}
|
43
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php
vendored
Normal file
43
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
/**
|
||||
* ProjectUrlMatcher
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct(RequestContext $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function match($pathinfo)
|
||||
{
|
||||
$allow = array();
|
||||
$pathinfo = rawurldecode($pathinfo);
|
||||
|
||||
if (0 === strpos($pathinfo, '/rootprefix')) {
|
||||
// static
|
||||
if ($pathinfo === '/rootprefix/test') {
|
||||
return array('_route' => 'static');
|
||||
}
|
||||
|
||||
// dynamic
|
||||
if (preg_match('#^/rootprefix/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
|
||||
return $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
|
||||
}
|
||||
}
|
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/empty.yml
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/empty.yml
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo.xml
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo.xml
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo1.xml
vendored
Normal file
0
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/foo1.xml
vendored
Normal file
2
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/incomplete.yml
vendored
Normal file
2
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/incomplete.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
blog_show:
|
||||
defaults: { _controller: MyBlogBundle:Blog:show }
|
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml
vendored
Normal file
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_id.xml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route path="/test"></route>
|
||||
</routes>
|
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml
vendored
Normal file
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/missing_path.xml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="myroute"></route>
|
||||
</routes>
|
13
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml
vendored
Normal file
13
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/namespaceprefix.xml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<r:routes xmlns:r="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<r:route id="blog_show" path="/blog/{slug}" host="{_locale}.example.com">
|
||||
<r:default key="_controller">MyBundle:Blog:show</r:default>
|
||||
<requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement>
|
||||
<r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement>
|
||||
<r:option key="compiler_class">RouteCompiler</r:option>
|
||||
</r:route>
|
||||
</r:routes>
|
|
@ -0,0 +1,3 @@
|
|||
blog_show:
|
||||
resource: validpattern.yml
|
||||
path: /test
|
|
@ -0,0 +1,3 @@
|
|||
blog_show:
|
||||
path: /blog/{slug}
|
||||
type: custom
|
11
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.xml
vendored
Normal file
11
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.xml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="blog_show" path="/blog/{slug}">
|
||||
<default key="_controller">MyBundle:Blog:show</default>
|
||||
<requirement key="_method">GET</requirement>
|
||||
<!-- </route> -->
|
||||
</routes>
|
1
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.yml
vendored
Normal file
1
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
foo
|
1
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid2.yml
vendored
Normal file
1
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalid2.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
route: string
|
3
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidkeys.yml
vendored
Normal file
3
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidkeys.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
someroute:
|
||||
resource: path/to/some.yml
|
||||
name_prefix: test_
|
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidnode.xml
vendored
Normal file
8
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidnode.xml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<foo>bar</foo>
|
||||
</routes>
|
13
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidroute.xml
vendored
Normal file
13
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/nonvalidroute.xml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="blog_show" path="/blog/{slug}">
|
||||
<default key="_controller">MyBundle:Blog:show</default>
|
||||
<requirement key="_method">GET</requirement>
|
||||
<option key="compiler_class">RouteCompiler</option>
|
||||
<foo key="bar">baz</foo>
|
||||
</route>
|
||||
</routes>
|
2
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml
vendored
Normal file
2
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/special_route_name.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
"#$péß^a|":
|
||||
path: "true"
|
23
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.php
vendored
Normal file
23
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('blog_show', new Route(
|
||||
'/blog/{slug}',
|
||||
array('_controller' => 'MyBlogBundle:Blog:show'),
|
||||
array('locale' => '\w+'),
|
||||
array('compiler_class' => 'RouteCompiler'),
|
||||
'{locale}.example.com',
|
||||
array('https'),
|
||||
array('GET','POST','put','OpTiOnS')
|
||||
));
|
||||
$collection->add('blog_show_legacy', new Route(
|
||||
'/blog/{slug}',
|
||||
array('_controller' => 'MyBlogBundle:Blog:show'),
|
||||
array('_method' => 'GET|POST|put|OpTiOnS', '_scheme' => 'https', 'locale' => '\w+',),
|
||||
array('compiler_class' => 'RouteCompiler'),
|
||||
'{locale}.example.com'
|
||||
));
|
||||
|
||||
return $collection;
|
21
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml
vendored
Normal file
21
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET|POST put,OpTiOnS" schemes="hTTps">
|
||||
<default key="_controller">MyBundle:Blog:show</default>
|
||||
<requirement key="locale">\w+</requirement>
|
||||
<option key="compiler_class">RouteCompiler</option>
|
||||
</route>
|
||||
|
||||
<route id="blog_show_legacy" pattern="/blog/{slug}" host="{locale}.example.com">
|
||||
<default key="_controller">MyBundle:Blog:show</default>
|
||||
<default key="slug" xsi:nil="true" />
|
||||
<requirement key="_method">GET|POST|put|OpTiOnS</requirement>
|
||||
<requirement key="_scheme">hTTps</requirement>
|
||||
<requirement key="locale">\w+</requirement>
|
||||
<option key="compiler_class">RouteCompiler</option>
|
||||
</route>
|
||||
</routes>
|
17
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml
vendored
Normal file
17
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
blog_show:
|
||||
path: /blog/{slug}
|
||||
defaults: { _controller: "MyBundle:Blog:show" }
|
||||
host: "{locale}.example.com"
|
||||
requirements: { 'locale': '\w+' }
|
||||
methods: ['GET','POST','put','OpTiOnS']
|
||||
schemes: ['https']
|
||||
options:
|
||||
compiler_class: RouteCompiler
|
||||
|
||||
blog_show_legacy:
|
||||
pattern: /blog/{slug}
|
||||
defaults: { _controller: "MyBundle:Blog:show" }
|
||||
host: "{locale}.example.com"
|
||||
requirements: { '_method': 'GET|POST|put|OpTiOnS', _scheme: https, 'locale': '\w+' }
|
||||
options:
|
||||
compiler_class: RouteCompiler
|
12
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.xml
vendored
Normal file
12
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.xml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<import resource="validpattern.xml" prefix="/{foo}" host="">
|
||||
<default key="foo">123</default>
|
||||
<requirement key="foo">\d+</requirement>
|
||||
<option key="foo">bar</option>
|
||||
</import>
|
||||
</routes>
|
7
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.yml
vendored
Normal file
7
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/validresource.yml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
_blog:
|
||||
resource: validpattern.yml
|
||||
prefix: /{foo}
|
||||
defaults: { 'foo': '123' }
|
||||
requirements: { 'foo': '\d+' }
|
||||
options: { 'foo': 'bar' }
|
||||
host: ""
|
3
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/withdoctype.xml
vendored
Normal file
3
vendor/symfony/routing/Symfony/Component/Routing/Tests/Fixtures/withdoctype.xml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE foo>
|
||||
<foo></foo>
|
117
vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php
vendored
Normal file
117
vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Generator\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var RouteCollection
|
||||
*/
|
||||
private $routeCollection;
|
||||
|
||||
/**
|
||||
* @var PhpGeneratorDumper
|
||||
*/
|
||||
private $generatorDumper;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $testTmpFilepath;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->routeCollection = new RouteCollection();
|
||||
$this->generatorDumper = new PhpGeneratorDumper($this->routeCollection);
|
||||
$this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.php';
|
||||
@unlink($this->testTmpFilepath);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@unlink($this->testTmpFilepath);
|
||||
|
||||
$this->routeCollection = null;
|
||||
$this->generatorDumper = null;
|
||||
$this->testTmpFilepath = null;
|
||||
}
|
||||
|
||||
public function testDumpWithRoutes()
|
||||
{
|
||||
$this->routeCollection->add('Test', new Route('/testing/{foo}'));
|
||||
$this->routeCollection->add('Test2', new Route('/testing2'));
|
||||
|
||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
|
||||
include ($this->testTmpFilepath);
|
||||
|
||||
$projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php'));
|
||||
|
||||
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true);
|
||||
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true);
|
||||
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false);
|
||||
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), false);
|
||||
|
||||
$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
|
||||
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
|
||||
$this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar');
|
||||
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testDumpWithoutRoutes()
|
||||
{
|
||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'WithoutRoutesUrlGenerator')));
|
||||
include ($this->testTmpFilepath);
|
||||
|
||||
$projectUrlGenerator = new \WithoutRoutesUrlGenerator(new RequestContext('/app.php'));
|
||||
|
||||
$projectUrlGenerator->generate('Test', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
|
||||
*/
|
||||
public function testGenerateNonExistingRoute()
|
||||
{
|
||||
$this->routeCollection->add('Test', new Route('/test'));
|
||||
|
||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'NonExistingRoutesUrlGenerator')));
|
||||
include ($this->testTmpFilepath);
|
||||
|
||||
$projectUrlGenerator = new \NonExistingRoutesUrlGenerator(new RequestContext());
|
||||
$url = $projectUrlGenerator->generate('NonExisting', array());
|
||||
}
|
||||
|
||||
public function testDumpForRouteWithDefaults()
|
||||
{
|
||||
$this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar')));
|
||||
|
||||
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator')));
|
||||
include ($this->testTmpFilepath);
|
||||
|
||||
$projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext());
|
||||
$url = $projectUrlGenerator->generate('Test', array());
|
||||
|
||||
$this->assertEquals($url, '/testing');
|
||||
}
|
||||
}
|
635
vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
vendored
Normal file
635
vendor/symfony/routing/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
vendored
Normal file
|
@ -0,0 +1,635 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Generator;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAbsoluteUrlWithPort80()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array(), true);
|
||||
|
||||
$this->assertEquals('http://localhost/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteSecureUrlWithPort443()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true);
|
||||
|
||||
$this->assertEquals('https://localhost/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlWithNonStandardPort()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true);
|
||||
|
||||
$this->assertEquals('http://localhost:8080/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteSecureUrlWithNonStandardPort()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true);
|
||||
|
||||
$this->assertEquals('https://localhost:8080/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testRelativeUrlWithoutParameters()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array(), false);
|
||||
|
||||
$this->assertEquals('/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testRelativeUrlWithParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
|
||||
|
||||
$this->assertEquals('/app.php/testing/bar', $url);
|
||||
}
|
||||
|
||||
public function testRelativeUrlWithNullParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null)));
|
||||
$url = $this->getGenerator($routes)->generate('test', array(), false);
|
||||
|
||||
$this->assertEquals('/app.php/testing', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testRelativeUrlWithNullParameterButNotOptional()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
|
||||
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
|
||||
// Generating path "/testing//bar" would be wrong as matching this route would fail.
|
||||
$this->getGenerator($routes)->generate('test', array(), false);
|
||||
}
|
||||
|
||||
public function testRelativeUrlWithOptionalZeroParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), false);
|
||||
|
||||
$this->assertEquals('/app.php/testing/0', $url);
|
||||
}
|
||||
|
||||
public function testNotPassedOptionalParameterInBetween()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0)));
|
||||
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1)));
|
||||
$this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||
}
|
||||
|
||||
public function testRelativeUrlWithExtraParameters()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
|
||||
|
||||
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
||||
}
|
||||
|
||||
public function testAbsoluteUrlWithExtraParameters()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
|
||||
|
||||
$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
|
||||
}
|
||||
|
||||
public function testUrlWithNullExtraParameters()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), true);
|
||||
|
||||
$this->assertEquals('http://localhost/app.php/testing', $url);
|
||||
}
|
||||
|
||||
public function testUrlWithExtraParametersFromGlobals()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$context = new RequestContext('/app.php');
|
||||
$context->setParameter('bar', 'bar');
|
||||
$generator->setContext($context);
|
||||
$url = $generator->generate('test', array('foo' => 'bar'));
|
||||
|
||||
$this->assertEquals('/app.php/testing?foo=bar', $url);
|
||||
}
|
||||
|
||||
public function testUrlWithGlobalParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$context = new RequestContext('/app.php');
|
||||
$context->setParameter('foo', 'bar');
|
||||
$generator->setContext($context);
|
||||
$url = $generator->generate('test', array());
|
||||
|
||||
$this->assertEquals('/app.php/testing/bar', $url);
|
||||
}
|
||||
|
||||
public function testGlobalParameterHasHigherPriorityThanDefault()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en')));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$context = new RequestContext('/app.php');
|
||||
$context->setParameter('_locale', 'de');
|
||||
$generator->setContext($context);
|
||||
$url = $generator->generate('test', array());
|
||||
|
||||
$this->assertSame('/app.php/de', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
|
||||
*/
|
||||
public function testGenerateWithoutRoutes()
|
||||
{
|
||||
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
|
||||
$this->getGenerator($routes)->generate('test', array(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
|
||||
*/
|
||||
public function testGenerateForRouteWithoutMandatoryParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
|
||||
$this->getGenerator($routes)->generate('test', array(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testGenerateForRouteWithInvalidOptionalParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testGenerateForRouteWithInvalidParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2')));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => '0'), true);
|
||||
}
|
||||
|
||||
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$generator->setStrictRequirements(false);
|
||||
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
|
||||
}
|
||||
|
||||
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
|
||||
{
|
||||
if (!interface_exists('Psr\Log\LoggerInterface')) {
|
||||
$this->markTestSkipped('The "psr/log" package is not available');
|
||||
}
|
||||
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
||||
$logger = $this->getMock('Psr\Log\LoggerInterface');
|
||||
$logger->expects($this->once())
|
||||
->method('error');
|
||||
$generator = $this->getGenerator($routes, array(), $logger);
|
||||
$generator->setStrictRequirements(false);
|
||||
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
|
||||
}
|
||||
|
||||
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$generator->setStrictRequirements(null);
|
||||
$this->assertSame('/app.php/testing/bar', $generator->generate('test', array('foo' => 'bar')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testGenerateForRouteWithInvalidMandatoryParameter()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testRequiredParamAndEmptyPassed()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+')));
|
||||
$this->getGenerator($routes)->generate('test', array('slug' => ''));
|
||||
}
|
||||
|
||||
public function testSchemeRequirementDoesNothingIfSameCurrentScheme()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
|
||||
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https')));
|
||||
$this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
|
||||
}
|
||||
|
||||
public function testSchemeRequirementForcesAbsoluteUrl()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https')));
|
||||
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
|
||||
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
|
||||
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
|
||||
}
|
||||
|
||||
public function testPathWithTwoStartingSlashes()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
|
||||
|
||||
// this must not generate '//path-and-not-domain' because that would be a network path
|
||||
$this->assertSame('/path-and-not-domain', $this->getGenerator($routes, array('BaseUrl' => ''))->generate('test'));
|
||||
}
|
||||
|
||||
public function testNoTrailingSlashForMultipleOptionalParameters()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', array('slug2' => null, 'slug3' => null)));
|
||||
|
||||
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo')));
|
||||
}
|
||||
|
||||
public function testWithAnIntegerAsADefaultValue()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0)));
|
||||
|
||||
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
|
||||
}
|
||||
|
||||
public function testNullForOptionalParameterIsIgnored()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/test/{default}', array('default' => 0)));
|
||||
|
||||
$this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => null)));
|
||||
}
|
||||
|
||||
public function testQueryParamSameAsDefault()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/test', array('default' => 'value')));
|
||||
|
||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
|
||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value')));
|
||||
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
|
||||
}
|
||||
|
||||
public function testGenerateWithSpecialRouteName()
|
||||
{
|
||||
$routes = $this->getRoutes('$péß^a|', new Route('/bar'));
|
||||
|
||||
$this->assertSame('/app.php/bar', $this->getGenerator($routes)->generate('$péß^a|'));
|
||||
}
|
||||
|
||||
public function testUrlEncoding()
|
||||
{
|
||||
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)
|
||||
// and other special ASCII chars. These chars are tested as static text path, variable path and query param.
|
||||
$chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id';
|
||||
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+')));
|
||||
$this->assertSame('/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
|
||||
.'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
|
||||
.'?query=%40%3A%5B%5D%2F%28%29%2A%27%22+%2B%2C%3B-._%7E%26%24%3C%3E%7C%7B%7D%25%5C%5E%60%21%3Ffoo%3Dbar%23id',
|
||||
$this->getGenerator($routes)->generate('test', array(
|
||||
'varpath' => $chars,
|
||||
'query' => $chars
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncodingOfRelativePathSegments()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/dir/../dir/..'));
|
||||
$this->assertSame('/app.php/dir/%2E%2E/dir/%2E%2E', $this->getGenerator($routes)->generate('test'));
|
||||
$routes = $this->getRoutes('test', new Route('/dir/./dir/.'));
|
||||
$this->assertSame('/app.php/dir/%2E/dir/%2E', $this->getGenerator($routes)->generate('test'));
|
||||
$routes = $this->getRoutes('test', new Route('/a./.a/a../..a/...'));
|
||||
$this->assertSame('/app.php/a./.a/a../..a/...', $this->getGenerator($routes)->generate('test'));
|
||||
}
|
||||
|
||||
public function testAdjacentVariables()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '\d+')));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$this->assertSame('/app.php/foo123', $generator->generate('test', array('x' => 'foo', 'y' => '123')));
|
||||
$this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', array('x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml')));
|
||||
|
||||
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
|
||||
// and following optional variables like _format could never match.
|
||||
$this->setExpectedException('Symfony\Component\Routing\Exception\InvalidParameterException');
|
||||
$generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml'));
|
||||
}
|
||||
|
||||
public function testOptionalVariableWithNoRealSeparator()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/get{what}', array('what' => 'All')));
|
||||
$generator = $this->getGenerator($routes);
|
||||
|
||||
$this->assertSame('/app.php/get', $generator->generate('test'));
|
||||
$this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites')));
|
||||
}
|
||||
|
||||
public function testRequiredVariableWithNoRealSeparator()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/get{what}Suffix'));
|
||||
$generator = $this->getGenerator($routes);
|
||||
|
||||
$this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', array('what' => 'Sites')));
|
||||
}
|
||||
|
||||
public function testDefaultRequirementOfVariable()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||
$generator = $this->getGenerator($routes);
|
||||
|
||||
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testDefaultRequirementOfVariableDisallowsSlash()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||
$this->getGenerator($routes)->generate('test', array('page' => 'index', '_format' => 'sl/ash'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
|
||||
$this->getGenerator($routes)->generate('test', array('page' => 'do.t', '_format' => 'html'));
|
||||
}
|
||||
|
||||
public function testWithHostDifferentFromContext()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
||||
|
||||
$this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', array('name' =>'Fabien', 'locale' => 'fr')));
|
||||
}
|
||||
|
||||
public function testWithHostSameAsContext()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
||||
|
||||
$this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' =>'Fabien', 'locale' => 'fr')));
|
||||
}
|
||||
|
||||
public function testWithHostSameAsContextAndAbsolute()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
|
||||
|
||||
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' =>'Fabien', 'locale' => 'fr'), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testUrlWithInvalidParameterInHost()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
||||
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
|
||||
}
|
||||
|
||||
public function testUrlWithInvalidParameterInHostInNonStrictMode()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
|
||||
$generator = $this->getGenerator($routes);
|
||||
$generator->setStrictRequirements(false);
|
||||
$this->assertNull($generator->generate('test', array('foo' => 'baz'), false));
|
||||
}
|
||||
|
||||
public function testGenerateNetworkPath()
|
||||
{
|
||||
$routes = $this->getRoutes('test', new Route('/{name}', array(), array('_scheme' => 'http'), array(), '{locale}.example.com'));
|
||||
|
||||
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
||||
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
|
||||
);
|
||||
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test',
|
||||
array('name' =>'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
|
||||
);
|
||||
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test',
|
||||
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
|
||||
);
|
||||
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
|
||||
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateRelativePath()
|
||||
{
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('article', new Route('/{author}/{article}/'));
|
||||
$routes->add('comments', new Route('/{author}/{article}/comments'));
|
||||
$routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com'));
|
||||
$routes->add('scheme', new Route('/{author}', array(), array('_scheme' => 'https')));
|
||||
$routes->add('unrelated', new Route('/about'));
|
||||
|
||||
$generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/'));
|
||||
|
||||
$this->assertSame('comments', $generator->generate('comments',
|
||||
array('author' =>'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('comments?page=2', $generator->generate('comments',
|
||||
array('author' =>'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('../twig-is-great/', $generator->generate('article',
|
||||
array('author' =>'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article',
|
||||
array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',
|
||||
array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('https://example.com/app.php/bernhard', $generator->generate('scheme',
|
||||
array('author' =>'bernhard'), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
$this->assertSame('../../about', $generator->generate('unrelated',
|
||||
array(), UrlGeneratorInterface::RELATIVE_PATH)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRelativePaths
|
||||
*/
|
||||
public function testGetRelativePath($sourcePath, $targetPath, $expectedPath)
|
||||
{
|
||||
$this->assertSame($expectedPath, UrlGenerator::getRelativePath($sourcePath, $targetPath));
|
||||
}
|
||||
|
||||
public function provideRelativePaths()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'/same/dir/',
|
||||
'/same/dir/',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'/same/file',
|
||||
'/same/file',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'/',
|
||||
'/file',
|
||||
'file'
|
||||
),
|
||||
array(
|
||||
'/',
|
||||
'/dir/file',
|
||||
'dir/file'
|
||||
),
|
||||
array(
|
||||
'/dir/file.html',
|
||||
'/dir/different-file.html',
|
||||
'different-file.html'
|
||||
),
|
||||
array(
|
||||
'/same/dir/extra-file',
|
||||
'/same/dir/',
|
||||
'./'
|
||||
),
|
||||
array(
|
||||
'/parent/dir/',
|
||||
'/parent/',
|
||||
'../'
|
||||
),
|
||||
array(
|
||||
'/parent/dir/extra-file',
|
||||
'/parent/',
|
||||
'../'
|
||||
),
|
||||
array(
|
||||
'/a/b/',
|
||||
'/x/y/z/',
|
||||
'../../x/y/z/'
|
||||
),
|
||||
array(
|
||||
'/a/b/c/d/e',
|
||||
'/a/c/d',
|
||||
'../../../c/d'
|
||||
),
|
||||
array(
|
||||
'/a/b/c//',
|
||||
'/a/b/c/',
|
||||
'../'
|
||||
),
|
||||
array(
|
||||
'/a/b/c/',
|
||||
'/a/b/c//',
|
||||
'.//'
|
||||
),
|
||||
array(
|
||||
'/root/a/b/c/',
|
||||
'/root/x/b/c/',
|
||||
'../../../x/b/c/'
|
||||
),
|
||||
array(
|
||||
'/a/b/c/d/',
|
||||
'/a',
|
||||
'../../../../a'
|
||||
),
|
||||
array(
|
||||
'/special-chars/sp%20ce/1€/mäh/e=mc²',
|
||||
'/special-chars/sp%20ce/1€/<µ>/e=mc²',
|
||||
'../<µ>/e=mc²'
|
||||
),
|
||||
array(
|
||||
'not-rooted',
|
||||
'dir/file',
|
||||
'dir/file'
|
||||
),
|
||||
array(
|
||||
'//dir/',
|
||||
'',
|
||||
'../../'
|
||||
),
|
||||
array(
|
||||
'/dir/',
|
||||
'/dir/file:with-colon',
|
||||
'./file:with-colon'
|
||||
),
|
||||
array(
|
||||
'/dir/',
|
||||
'/dir/subdir/file:with-colon',
|
||||
'subdir/file:with-colon'
|
||||
),
|
||||
array(
|
||||
'/dir/',
|
||||
'/dir/:subdir/',
|
||||
'./:subdir/'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
|
||||
{
|
||||
$context = new RequestContext('/app.php');
|
||||
foreach ($parameters as $key => $value) {
|
||||
$method = 'set'.$key;
|
||||
$context->$method($value);
|
||||
}
|
||||
$generator = new UrlGenerator($routes, $context, $logger);
|
||||
|
||||
return $generator;
|
||||
}
|
||||
|
||||
protected function getRoutes($name, Route $route)
|
||||
{
|
||||
$routes = new RouteCollection();
|
||||
$routes->add($name, $route);
|
||||
|
||||
return $routes;
|
||||
}
|
||||
}
|
38
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
38
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Doctrine\\Common\\Version')) {
|
||||
$this->markTestSkipped('Doctrine is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getReader()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
public function getClassLoader($reader)
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
|
||||
->setConstructorArgs(array($reader))
|
||||
->getMockForAbstractClass()
|
||||
;
|
||||
}
|
||||
}
|
119
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
119
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = $this->getClassLoader($this->reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadMissingClass()
|
||||
{
|
||||
$this->loader->load('MissingClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadAbstractClass()
|
||||
{
|
||||
$this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestSupportsChecksResource
|
||||
*/
|
||||
public function testSupportsChecksResource($resource, $expectedSupports)
|
||||
{
|
||||
$this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
|
||||
}
|
||||
|
||||
public function provideTestSupportsChecksResource()
|
||||
{
|
||||
return array(
|
||||
array('class', true),
|
||||
array('\fully\qualified\class\name', true),
|
||||
array('namespaced\class\without\leading\slash', true),
|
||||
array('ÿClassWithLegalSpecialCharacters', true),
|
||||
array('5', false),
|
||||
array('foo.foo', false),
|
||||
array(null, false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSupportsChecksTypeIfSpecified()
|
||||
{
|
||||
$this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function getLoadTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('name'=>'route1'),
|
||||
array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('name'=>'route1', 'defaults' => array('arg2' => 'foo')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadTests
|
||||
*/
|
||||
public function testLoad($className, $routeDatas = array(), $methodArgs = array())
|
||||
{
|
||||
$routeDatas = array_replace(array(
|
||||
'name' => 'route',
|
||||
'path' => '/',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
), $routeDatas);
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($routeDatas))))
|
||||
;
|
||||
$routeCollection = $this->loader->load($className);
|
||||
$route = $routeCollection->get($routeDatas['name']);
|
||||
|
||||
$this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
|
||||
$this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
|
||||
$this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
|
||||
$this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation');
|
||||
}
|
||||
|
||||
private function getAnnotatedRoute($datas)
|
||||
{
|
||||
return new \Symfony\Component\Routing\Annotation\Route($datas);
|
||||
}
|
||||
|
||||
}
|
53
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
53
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->exactly(2))->method('getClassAnnotation');
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixturesDir = __DIR__.'/../Fixtures';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
}
|
47
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
47
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixture = __DIR__.'/../Fixtures/annotated.php';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
}
|
55
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
55
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\ClosureLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Config\FileLocator')) {
|
||||
$this->markTestSkipped('The "Config" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$closure = function () {};
|
||||
|
||||
$this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$route = new Route('/');
|
||||
$routes = $loader->load(function () use ($route) {
|
||||
$routes = new RouteCollection();
|
||||
|
||||
$routes->add('foo', $route);
|
||||
|
||||
return $routes;
|
||||
});
|
||||
|
||||
$this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
|
||||
}
|
||||
}
|
55
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
55
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\PhpFileLoader;
|
||||
|
||||
class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Config\FileLocator')) {
|
||||
$this->markTestSkipped('The "Config" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.php');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
}
|
127
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
127
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader;
|
||||
|
||||
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Config\FileLocator')) {
|
||||
$this->markTestSkipped('The "Config" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadWithNamespacePrefix()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('namespaceprefix.xml');
|
||||
|
||||
$this->assertCount(1, $routeCollection->all(), 'One route is loaded');
|
||||
|
||||
$route = $routeCollection->get('blog_show');
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{_locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('slug'));
|
||||
$this->assertSame('en|fr|de', $route->getRequirement('_locale'));
|
||||
$this->assertSame(null, $route->getDefault('slug'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
}
|
||||
|
||||
public function testLoadWithImport()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
|
||||
{
|
||||
$loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Document types are not allowed.
|
||||
*/
|
||||
public function testDocTypeIsNotAllowed()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load('withdoctype.xml');
|
||||
}
|
||||
}
|
113
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
113
vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
|
||||
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Config\FileLocator')) {
|
||||
$this->markTestSkipped('The "Config" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
|
||||
$this->markTestSkipped('The "Yaml" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$collection = $loader->load('empty.yml');
|
||||
|
||||
$this->assertEquals(array(), $collection->all());
|
||||
$this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml'));
|
||||
}
|
||||
|
||||
public function testLoadSpecialRouteName()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('special_route_name.yml');
|
||||
$route = $routeCollection->get('#$péß^a|');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/true', $route->getPath());
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.yml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadWithResource()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.yml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
}
|
||||
}
|
||||
}
|
137
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php
vendored
Normal file
137
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/ApacheUrlMatcherTest.php
vendored
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Matcher\ApacheUrlMatcher;
|
||||
|
||||
class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $server;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->server = $_SERVER;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$_SERVER = $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getMatchData
|
||||
*/
|
||||
public function testMatch($name, $pathinfo, $server, $expect)
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$context = new RequestContext();
|
||||
$matcher = new ApacheUrlMatcher($collection, $context);
|
||||
|
||||
$_SERVER = $server;
|
||||
|
||||
$result = $matcher->match($pathinfo, $server);
|
||||
$this->assertSame(var_export($expect, true), var_export($result, true));
|
||||
}
|
||||
|
||||
public function getMatchData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Simple route',
|
||||
'/hello/world',
|
||||
array(
|
||||
'_ROUTING_route' => 'hello',
|
||||
'_ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'_ROUTING_param_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'name' => 'world',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Route with params and defaults',
|
||||
'/hello/hugo',
|
||||
array(
|
||||
'_ROUTING_route' => 'hello',
|
||||
'_ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'_ROUTING_param_name' => 'hugo',
|
||||
'_ROUTING_default_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'name' => 'hugo',
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Route with defaults only',
|
||||
'/hello',
|
||||
array(
|
||||
'_ROUTING_route' => 'hello',
|
||||
'_ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'_ROUTING_default_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'name' => 'world',
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'REDIRECT_ envs',
|
||||
'/hello/world',
|
||||
array(
|
||||
'REDIRECT__ROUTING_route' => 'hello',
|
||||
'REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'REDIRECT__ROUTING_param_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'name' => 'world',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'REDIRECT_REDIRECT_ envs',
|
||||
'/hello/world',
|
||||
array(
|
||||
'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
|
||||
'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'name' => 'world',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'REDIRECT_REDIRECT_ envs',
|
||||
'/hello/world',
|
||||
array(
|
||||
'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
|
||||
'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
|
||||
'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
|
||||
),
|
||||
array(
|
||||
'_controller' => 'AcmeBundle:Default:index',
|
||||
'name' => 'world',
|
||||
'_route' => 'hello',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
196
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php
vendored
Normal file
196
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/ApacheMatcherDumperTest.php
vendored
Normal file
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
|
||||
|
||||
class ApacheMatcherDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/');
|
||||
}
|
||||
|
||||
public function testDump()
|
||||
{
|
||||
$dumper = new ApacheMatcherDumper($this->getRouteCollection());
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideEscapeFixtures
|
||||
*/
|
||||
public function testEscapePattern($src, $dest, $char, $with, $message)
|
||||
{
|
||||
$r = new \ReflectionMethod(new ApacheMatcherDumper($this->getRouteCollection()), 'escape');
|
||||
$r->setAccessible(true);
|
||||
$this->assertEquals($dest, $r->invoke(null, $src, $char, $with), $message);
|
||||
}
|
||||
|
||||
public function provideEscapeFixtures()
|
||||
{
|
||||
return array(
|
||||
array('foo', 'foo', ' ', '-', 'Preserve string that should not be escaped'),
|
||||
array('fo-o', 'fo-o', ' ', '-', 'Preserve string that should not be escaped'),
|
||||
array('fo o', 'fo- o', ' ', '-', 'Escape special characters'),
|
||||
array('fo-- o', 'fo--- o', ' ', '-', 'Escape special characters'),
|
||||
array('fo- o', 'fo- o', ' ', '-', 'Do not escape already escaped string'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testEscapeScriptName()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('foo', new Route('/foo'));
|
||||
$dumper = new ApacheMatcherDumper($collection);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher2.apache', $dumper->dump(array('script_name' => 'ap p_d\ ev.php')));
|
||||
}
|
||||
|
||||
private function getRouteCollection()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
|
||||
// defaults and requirements
|
||||
$collection->add('foo', new Route(
|
||||
'/foo/{bar}',
|
||||
array('def' => 'test'),
|
||||
array('bar' => 'baz|symfony')
|
||||
));
|
||||
// defaults parameters in pattern
|
||||
$collection->add('foobar', new Route(
|
||||
'/foo/{bar}',
|
||||
array('bar' => 'toto')
|
||||
));
|
||||
// method requirement
|
||||
$collection->add('bar', new Route(
|
||||
'/bar/{foo}',
|
||||
array(),
|
||||
array('_method' => 'GET|head')
|
||||
));
|
||||
// method requirement (again)
|
||||
$collection->add('baragain', new Route(
|
||||
'/baragain/{foo}',
|
||||
array(),
|
||||
array('_method' => 'get|post')
|
||||
));
|
||||
// simple
|
||||
$collection->add('baz', new Route(
|
||||
'/test/baz'
|
||||
));
|
||||
// simple with extension
|
||||
$collection->add('baz2', new Route(
|
||||
'/test/baz.html'
|
||||
));
|
||||
// trailing slash
|
||||
$collection->add('baz3', new Route(
|
||||
'/test/baz3/'
|
||||
));
|
||||
// trailing slash with variable
|
||||
$collection->add('baz4', new Route(
|
||||
'/test/{foo}/'
|
||||
));
|
||||
// trailing slash and safe method
|
||||
$collection->add('baz5', new Route(
|
||||
'/test/{foo}/',
|
||||
array(),
|
||||
array('_method' => 'get')
|
||||
));
|
||||
// trailing slash and unsafe method
|
||||
$collection->add('baz5unsafe', new Route(
|
||||
'/testunsafe/{foo}/',
|
||||
array(),
|
||||
array('_method' => 'post')
|
||||
));
|
||||
// complex
|
||||
$collection->add('baz6', new Route(
|
||||
'/test/baz',
|
||||
array('foo' => 'bar baz')
|
||||
));
|
||||
// space in path
|
||||
$collection->add('baz7', new Route(
|
||||
'/te st/baz'
|
||||
));
|
||||
// space preceded with \ in path
|
||||
$collection->add('baz8', new Route(
|
||||
'/te\\ st/baz'
|
||||
));
|
||||
// space preceded with \ in requirement
|
||||
$collection->add('baz9', new Route(
|
||||
'/test/{baz}',
|
||||
array(),
|
||||
array(
|
||||
'baz' => 'te\\\\ st',
|
||||
)
|
||||
));
|
||||
|
||||
$collection1 = new RouteCollection();
|
||||
|
||||
$route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
|
||||
$collection1->add('route1', $route1);
|
||||
|
||||
$collection2 = new RouteCollection();
|
||||
|
||||
$route2 = new Route('/route2', array(), array(), array(), 'a.example.com');
|
||||
$collection2->add('route2', $route2);
|
||||
|
||||
$route3 = new Route('/route3', array(), array(), array(), 'b.example.com');
|
||||
$collection2->add('route3', $route3);
|
||||
|
||||
$collection2->addPrefix('/c2');
|
||||
$collection1->addCollection($collection2);
|
||||
|
||||
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
|
||||
$collection1->add('route4', $route4);
|
||||
|
||||
$route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
|
||||
$collection1->add('route5', $route5);
|
||||
|
||||
$route6 = new Route('/route6', array(), array(), array(), null);
|
||||
$collection1->add('route6', $route6);
|
||||
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// host and variables
|
||||
|
||||
$collection1 = new RouteCollection();
|
||||
|
||||
$route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route11', $route11);
|
||||
|
||||
$route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route12', $route12);
|
||||
|
||||
$route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route13', $route13);
|
||||
|
||||
$route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route14', $route14);
|
||||
|
||||
$route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
|
||||
$collection1->add('route15', $route15);
|
||||
|
||||
$route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
|
||||
$collection1->add('route16', $route16);
|
||||
|
||||
$route17 = new Route('/route17', array(), array(), array(), null);
|
||||
$collection1->add('route17', $route17);
|
||||
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
33
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php
vendored
Normal file
33
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Test\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
|
||||
|
||||
class DumperCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetRoot()
|
||||
{
|
||||
$a = new DumperCollection();
|
||||
|
||||
$b = new DumperCollection();
|
||||
$a->add($b);
|
||||
|
||||
$c = new DumperCollection();
|
||||
$b->add($c);
|
||||
|
||||
$d = new DumperCollection();
|
||||
$c->add($d);
|
||||
|
||||
$this->assertSame($a, $c->getRoot());
|
||||
}
|
||||
}
|
123
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php
vendored
Normal file
123
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\DumperPrefixCollection;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\DumperRoute;
|
||||
use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
|
||||
|
||||
class DumperPrefixCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAddPrefixRoute()
|
||||
{
|
||||
$coll = new DumperPrefixCollection;
|
||||
$coll->setPrefix('');
|
||||
|
||||
$route = new DumperRoute('bar', new Route('/foo/bar'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('bar2', new Route('/foo/bar'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('qux', new Route('/foo/qux'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('bar3', new Route('/foo/bar'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('bar4', new Route(''));
|
||||
$result = $coll->addPrefixRoute($route);
|
||||
|
||||
$expect = <<<'EOF'
|
||||
|-coll /
|
||||
| |-coll /f
|
||||
| | |-coll /fo
|
||||
| | | |-coll /foo
|
||||
| | | | |-coll /foo/
|
||||
| | | | | |-coll /foo/b
|
||||
| | | | | | |-coll /foo/ba
|
||||
| | | | | | | |-coll /foo/bar
|
||||
| | | | | | | | |-route bar /foo/bar
|
||||
| | | | | | | | |-route bar2 /foo/bar
|
||||
| | | | | |-coll /foo/q
|
||||
| | | | | | |-coll /foo/qu
|
||||
| | | | | | | |-coll /foo/qux
|
||||
| | | | | | | | |-route qux /foo/qux
|
||||
| | | | | |-coll /foo/b
|
||||
| | | | | | |-coll /foo/ba
|
||||
| | | | | | | |-coll /foo/bar
|
||||
| | | | | | | | |-route bar3 /foo/bar
|
||||
| |-route bar4 /
|
||||
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
|
||||
}
|
||||
|
||||
public function testMergeSlashNodes()
|
||||
{
|
||||
$coll = new DumperPrefixCollection;
|
||||
$coll->setPrefix('');
|
||||
|
||||
$route = new DumperRoute('bar', new Route('/foo/bar'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('bar2', new Route('/foo/bar'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('qux', new Route('/foo/qux'));
|
||||
$coll = $coll->addPrefixRoute($route);
|
||||
|
||||
$route = new DumperRoute('bar3', new Route('/foo/bar'));
|
||||
$result = $coll->addPrefixRoute($route);
|
||||
|
||||
$result->getRoot()->mergeSlashNodes();
|
||||
|
||||
$expect = <<<'EOF'
|
||||
|-coll /f
|
||||
| |-coll /fo
|
||||
| | |-coll /foo
|
||||
| | | |-coll /foo/b
|
||||
| | | | |-coll /foo/ba
|
||||
| | | | | |-coll /foo/bar
|
||||
| | | | | | |-route bar /foo/bar
|
||||
| | | | | | |-route bar2 /foo/bar
|
||||
| | | |-coll /foo/q
|
||||
| | | | |-coll /foo/qu
|
||||
| | | | | |-coll /foo/qux
|
||||
| | | | | | |-route qux /foo/qux
|
||||
| | | |-coll /foo/b
|
||||
| | | | |-coll /foo/ba
|
||||
| | | | | |-coll /foo/bar
|
||||
| | | | | | |-route bar3 /foo/bar
|
||||
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
|
||||
}
|
||||
|
||||
private function collectionToString(DumperCollection $collection, $prefix)
|
||||
{
|
||||
$string = '';
|
||||
foreach ($collection as $route) {
|
||||
if ($route instanceof DumperCollection) {
|
||||
$string .= sprintf("%s|-coll %s\n", $prefix, $route->getPrefix());
|
||||
$string .= $this->collectionToString($route, $prefix.'| ');
|
||||
} else {
|
||||
$string .= sprintf("%s|-route %s %s\n", $prefix, $route->getName(), $route->getRoute()->getPath());
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
261
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php
vendored
Normal file
261
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php
vendored
Normal file
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
|
||||
|
||||
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testDumpWhenSchemeIsUsedWithoutAProperDumper()
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('secure', new Route(
|
||||
'/secure',
|
||||
array(),
|
||||
array('_scheme' => 'https')
|
||||
));
|
||||
$dumper = new PhpMatcherDumper($collection);
|
||||
$dumper->dump();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getRouteCollections
|
||||
*/
|
||||
public function testDump(RouteCollection $collection, $fixture, $options = array())
|
||||
{
|
||||
$basePath = __DIR__.'/../../Fixtures/dumper/';
|
||||
|
||||
$dumper = new PhpMatcherDumper($collection);
|
||||
$this->assertStringEqualsFile($basePath.$fixture, $dumper->dump($options), '->dump() correctly dumps routes as optimized PHP code.');
|
||||
}
|
||||
|
||||
public function getRouteCollections()
|
||||
{
|
||||
/* test case 1 */
|
||||
|
||||
$collection = new RouteCollection();
|
||||
|
||||
$collection->add('overridden', new Route('/overridden'));
|
||||
|
||||
// defaults and requirements
|
||||
$collection->add('foo', new Route(
|
||||
'/foo/{bar}',
|
||||
array('def' => 'test'),
|
||||
array('bar' => 'baz|symfony')
|
||||
));
|
||||
// method requirement
|
||||
$collection->add('bar', new Route(
|
||||
'/bar/{foo}',
|
||||
array(),
|
||||
array('_method' => 'GET|head')
|
||||
));
|
||||
// GET method requirement automatically adds HEAD as valid
|
||||
$collection->add('barhead', new Route(
|
||||
'/barhead/{foo}',
|
||||
array(),
|
||||
array('_method' => 'GET')
|
||||
));
|
||||
// simple
|
||||
$collection->add('baz', new Route(
|
||||
'/test/baz'
|
||||
));
|
||||
// simple with extension
|
||||
$collection->add('baz2', new Route(
|
||||
'/test/baz.html'
|
||||
));
|
||||
// trailing slash
|
||||
$collection->add('baz3', new Route(
|
||||
'/test/baz3/'
|
||||
));
|
||||
// trailing slash with variable
|
||||
$collection->add('baz4', new Route(
|
||||
'/test/{foo}/'
|
||||
));
|
||||
// trailing slash and method
|
||||
$collection->add('baz5', new Route(
|
||||
'/test/{foo}/',
|
||||
array(),
|
||||
array('_method' => 'post')
|
||||
));
|
||||
// complex name
|
||||
$collection->add('baz.baz6', new Route(
|
||||
'/test/{foo}/',
|
||||
array(),
|
||||
array('_method' => 'put')
|
||||
));
|
||||
// defaults without variable
|
||||
$collection->add('foofoo', new Route(
|
||||
'/foofoo',
|
||||
array('def' => 'test')
|
||||
));
|
||||
// pattern with quotes
|
||||
$collection->add('quoter', new Route(
|
||||
'/{quoter}',
|
||||
array(),
|
||||
array('quoter' => '[\']+')
|
||||
));
|
||||
// space in pattern
|
||||
$collection->add('space', new Route(
|
||||
'/spa ce'
|
||||
));
|
||||
|
||||
// prefixes
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('overridden', new Route('/overridden1'));
|
||||
$collection1->add('foo1', new Route('/{foo}'));
|
||||
$collection1->add('bar1', new Route('/{bar}'));
|
||||
$collection1->addPrefix('/b\'b');
|
||||
$collection2 = new RouteCollection();
|
||||
$collection2->addCollection($collection1);
|
||||
$collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*')));
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('foo2', new Route('/{foo1}'));
|
||||
$collection1->add('bar2', new Route('/{bar1}'));
|
||||
$collection1->addPrefix('/b\'b');
|
||||
$collection2->addCollection($collection1);
|
||||
$collection2->addPrefix('/a');
|
||||
$collection->addCollection($collection2);
|
||||
|
||||
// overridden through addCollection() and multiple sub-collections with no own prefix
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('overridden2', new Route('/old'));
|
||||
$collection1->add('helloWorld', new Route('/hello/{who}', array('who' => 'World!')));
|
||||
$collection2 = new RouteCollection();
|
||||
$collection3 = new RouteCollection();
|
||||
$collection3->add('overridden2', new Route('/new'));
|
||||
$collection3->add('hey', new Route('/hey/'));
|
||||
$collection2->addCollection($collection3);
|
||||
$collection1->addCollection($collection2);
|
||||
$collection1->addPrefix('/multi');
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// "dynamic" prefix
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('foo3', new Route('/{foo}'));
|
||||
$collection1->add('bar3', new Route('/{bar}'));
|
||||
$collection1->addPrefix('/b');
|
||||
$collection1->addPrefix('{_locale}');
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// route between collections
|
||||
$collection->add('ababa', new Route('/ababa'));
|
||||
|
||||
// collection with static prefix but only one route
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('foo4', new Route('/{foo}'));
|
||||
$collection1->addPrefix('/aba');
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// prefix and host
|
||||
|
||||
$collection1 = new RouteCollection();
|
||||
|
||||
$route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
|
||||
$collection1->add('route1', $route1);
|
||||
|
||||
$collection2 = new RouteCollection();
|
||||
|
||||
$route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com');
|
||||
$collection1->add('route2', $route2);
|
||||
|
||||
$route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com');
|
||||
$collection1->add('route3', $route3);
|
||||
|
||||
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
|
||||
$collection1->add('route4', $route4);
|
||||
|
||||
$route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
|
||||
$collection1->add('route5', $route5);
|
||||
|
||||
$route6 = new Route('/route6', array(), array(), array(), null);
|
||||
$collection1->add('route6', $route6);
|
||||
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// host and variables
|
||||
|
||||
$collection1 = new RouteCollection();
|
||||
|
||||
$route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route11', $route11);
|
||||
|
||||
$route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route12', $route12);
|
||||
|
||||
$route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route13', $route13);
|
||||
|
||||
$route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
|
||||
$collection1->add('route14', $route14);
|
||||
|
||||
$route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
|
||||
$collection1->add('route15', $route15);
|
||||
|
||||
$route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
|
||||
$collection1->add('route16', $route16);
|
||||
|
||||
$route17 = new Route('/route17', array(), array(), array(), null);
|
||||
$collection1->add('route17', $route17);
|
||||
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
// multiple sub-collections with a single route and a prefix each
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('a', new Route('/a...'));
|
||||
$collection2 = new RouteCollection();
|
||||
$collection2->add('b', new Route('/{var}'));
|
||||
$collection3 = new RouteCollection();
|
||||
$collection3->add('c', new Route('/{var}'));
|
||||
$collection3->addPrefix('/c');
|
||||
$collection2->addCollection($collection3);
|
||||
$collection2->addPrefix('/b');
|
||||
$collection1->addCollection($collection2);
|
||||
$collection1->addPrefix('/a');
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
/* test case 2 */
|
||||
|
||||
$redirectCollection = clone $collection;
|
||||
|
||||
// force HTTPS redirection
|
||||
$redirectCollection->add('secure', new Route(
|
||||
'/secure',
|
||||
array(),
|
||||
array('_scheme' => 'https')
|
||||
));
|
||||
|
||||
// force HTTP redirection
|
||||
$redirectCollection->add('nonsecure', new Route(
|
||||
'/nonsecure',
|
||||
array(),
|
||||
array('_scheme' => 'http')
|
||||
));
|
||||
|
||||
/* test case 3 */
|
||||
|
||||
$rootprefixCollection = new RouteCollection();
|
||||
$rootprefixCollection->add('static', new Route('/test'));
|
||||
$rootprefixCollection->add('dynamic', new Route('/{var}'));
|
||||
$rootprefixCollection->addPrefix('rootprefix');
|
||||
|
||||
return array(
|
||||
array($collection, 'url_matcher1.php', array()),
|
||||
array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
|
||||
array($rootprefixCollection, 'url_matcher3.php', array())
|
||||
);
|
||||
}
|
||||
}
|
58
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php
vendored
Normal file
58
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRedirectWhenNoSlash()
|
||||
{
|
||||
$coll = new RouteCollection();
|
||||
$coll->add('foo', new Route('/foo/'));
|
||||
|
||||
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
|
||||
$matcher->expects($this->once())->method('redirect');
|
||||
$matcher->match('/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
|
||||
*/
|
||||
public function testRedirectWhenNoSlashForNonSafeMethod()
|
||||
{
|
||||
$coll = new RouteCollection();
|
||||
$coll->add('foo', new Route('/foo/'));
|
||||
|
||||
$context = new RequestContext();
|
||||
$context->setMethod('POST');
|
||||
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context));
|
||||
$matcher->match('/foo');
|
||||
}
|
||||
|
||||
public function testSchemeRedirect()
|
||||
{
|
||||
$coll = new RouteCollection();
|
||||
$coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https')));
|
||||
|
||||
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
|
||||
$matcher
|
||||
->expects($this->once())
|
||||
->method('redirect')
|
||||
->with('/foo', 'foo', 'https')
|
||||
->will($this->returnValue(array('_route' => 'foo')))
|
||||
;
|
||||
$matcher->match('/foo');
|
||||
}
|
||||
}
|
66
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php
vendored
Normal file
66
vendor/symfony/routing/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Matcher;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
|
||||
|
||||
class TraceableUrlMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$coll = new RouteCollection();
|
||||
$coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
|
||||
$coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+')));
|
||||
$coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+', '_method' => 'POST')));
|
||||
$coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
|
||||
$coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
|
||||
|
||||
$context = new RequestContext();
|
||||
$context->setHost('baz');
|
||||
|
||||
$matcher = new TraceableUrlMatcher($coll, $context);
|
||||
$traces = $matcher->getTraces('/babar');
|
||||
$this->assertEquals(array(0, 0, 0, 0, 0), $this->getLevels($traces));
|
||||
|
||||
$traces = $matcher->getTraces('/foo');
|
||||
$this->assertEquals(array(1, 0, 0, 2), $this->getLevels($traces));
|
||||
|
||||
$traces = $matcher->getTraces('/bar/12');
|
||||
$this->assertEquals(array(0, 2), $this->getLevels($traces));
|
||||
|
||||
$traces = $matcher->getTraces('/bar/dd');
|
||||
$this->assertEquals(array(0, 1, 1, 0, 0), $this->getLevels($traces));
|
||||
|
||||
$traces = $matcher->getTraces('/foo1');
|
||||
$this->assertEquals(array(0, 0, 0, 0, 2), $this->getLevels($traces));
|
||||
|
||||
$context->setMethod('POST');
|
||||
$traces = $matcher->getTraces('/foo');
|
||||
$this->assertEquals(array(2), $this->getLevels($traces));
|
||||
|
||||
$traces = $matcher->getTraces('/bar/dd');
|
||||
$this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
|
||||
}
|
||||
|
||||
public function getLevels($traces)
|
||||
{
|
||||
$levels = array();
|
||||
foreach ($traces as $trace) {
|
||||
$levels[] = $trace['level'];
|
||||
}
|
||||
|
||||
return $levels;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue