updated-packages
This commit is contained in:
@@ -36,6 +36,19 @@ class CollectionConfigurator
|
||||
$this->parentPrefixes = $parentPrefixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (null === $this->prefixes) {
|
||||
@@ -47,10 +60,8 @@ class CollectionConfigurator
|
||||
|
||||
/**
|
||||
* Creates a sub-collection.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
final public function collection($name = '')
|
||||
final public function collection(string $name = ''): self
|
||||
{
|
||||
return new self($this->collection, $this->name.$name, $this, $this->prefixes);
|
||||
}
|
||||
@@ -62,7 +73,7 @@ class CollectionConfigurator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function prefix($prefix)
|
||||
final public function prefix($prefix): self
|
||||
{
|
||||
if (\is_array($prefix)) {
|
||||
if (null === $this->parentPrefixes) {
|
||||
@@ -88,7 +99,7 @@ class CollectionConfigurator
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function createRoute($path): Route
|
||||
private function createRoute(string $path): Route
|
||||
{
|
||||
return (clone $this->route)->setPath($path);
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ namespace Symfony\Component\Routing\Loader\Configurator;
|
||||
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RouteCompiler;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
@@ -29,6 +30,19 @@ class ImportConfigurator
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->parent->addCollection($this->route);
|
||||
@@ -41,7 +55,7 @@ class ImportConfigurator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function prefix($prefix, bool $trailingSlashOnRoot = true)
|
||||
final public function prefix($prefix, bool $trailingSlashOnRoot = true): self
|
||||
{
|
||||
if (!\is_array($prefix)) {
|
||||
$this->route->addPrefix($prefix);
|
||||
@@ -63,6 +77,7 @@ class ImportConfigurator
|
||||
foreach ($prefix as $locale => $localePrefix) {
|
||||
$localizedRoute = clone $route;
|
||||
$localizedRoute->setDefault('_locale', $locale);
|
||||
$localizedRoute->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER));
|
||||
$localizedRoute->setDefault('_canonical_route', $name);
|
||||
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
|
||||
$this->route->add($name.'.'.$locale, $localizedRoute);
|
||||
@@ -84,7 +99,7 @@ class ImportConfigurator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function namePrefix(string $namePrefix)
|
||||
final public function namePrefix(string $namePrefix): self
|
||||
{
|
||||
$this->route->addNamePrefix($namePrefix);
|
||||
|
||||
|
@@ -34,12 +34,13 @@ class RoutingConfigurator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ImportConfigurator
|
||||
* @param string|string[]|null $exclude Glob patterns to exclude from the import
|
||||
*/
|
||||
final public function import($resource, $type = null, $ignoreErrors = false)
|
||||
final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
|
||||
{
|
||||
$this->loader->setCurrentDir(\dirname($this->path));
|
||||
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
|
||||
|
||||
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file, $exclude) ?: [];
|
||||
if (!\is_array($imported)) {
|
||||
return new ImportConfigurator($this->collection, $imported);
|
||||
}
|
||||
@@ -52,10 +53,7 @@ class RoutingConfigurator
|
||||
return new ImportConfigurator($this->collection, $mergedCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CollectionConfigurator
|
||||
*/
|
||||
final public function collection($name = '')
|
||||
final public function collection(string $name = ''): CollectionConfigurator
|
||||
{
|
||||
return new CollectionConfigurator($this->collection, $name);
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ use Symfony\Component\Routing\Loader\Configurator\CollectionConfigurator;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\RouteCompiler;
|
||||
|
||||
trait AddTrait
|
||||
{
|
||||
@@ -34,7 +35,7 @@ trait AddTrait
|
||||
*/
|
||||
final public function add(string $name, $path): RouteConfigurator
|
||||
{
|
||||
$paths = array();
|
||||
$paths = [];
|
||||
$parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
|
||||
|
||||
if (\is_array($path)) {
|
||||
@@ -67,6 +68,7 @@ trait AddTrait
|
||||
$routes->add($name.'.'.$locale, $route = $this->createRoute($path));
|
||||
$this->collection->add($this->name.$name.'.'.$locale, $route);
|
||||
$route->setDefault('_locale', $locale);
|
||||
$route->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER));
|
||||
$route->setDefault('_canonical_route', $this->name.$name);
|
||||
}
|
||||
|
||||
@@ -83,7 +85,7 @@ trait AddTrait
|
||||
return $this->add($name, $path);
|
||||
}
|
||||
|
||||
private function createRoute($path): Route
|
||||
private function createRoute(string $path): Route
|
||||
{
|
||||
return new Route($path);
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function defaults(array $defaults)
|
||||
final public function defaults(array $defaults): self
|
||||
{
|
||||
$this->route->addDefaults($defaults);
|
||||
|
||||
@@ -38,7 +38,7 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function requirements(array $requirements)
|
||||
final public function requirements(array $requirements): self
|
||||
{
|
||||
$this->route->addRequirements($requirements);
|
||||
|
||||
@@ -50,19 +50,31 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function options(array $options)
|
||||
final public function options(array $options): self
|
||||
{
|
||||
$this->route->addOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether paths should accept utf8 encoding.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function utf8(bool $utf8 = true): self
|
||||
{
|
||||
$this->route->addOptions(['utf8' => $utf8]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the condition.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function condition(string $condition)
|
||||
final public function condition(string $condition): self
|
||||
{
|
||||
$this->route->setCondition($condition);
|
||||
|
||||
@@ -74,7 +86,7 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function host(string $pattern)
|
||||
final public function host(string $pattern): self
|
||||
{
|
||||
$this->route->setHost($pattern);
|
||||
|
||||
@@ -89,7 +101,7 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function schemes(array $schemes)
|
||||
final public function schemes(array $schemes): self
|
||||
{
|
||||
$this->route->setSchemes($schemes);
|
||||
|
||||
@@ -104,7 +116,7 @@ trait RouteTrait
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function methods(array $methods)
|
||||
final public function methods(array $methods): self
|
||||
{
|
||||
$this->route->setMethods($methods);
|
||||
|
||||
@@ -114,13 +126,37 @@ trait RouteTrait
|
||||
/**
|
||||
* Adds the "_controller" entry to defaults.
|
||||
*
|
||||
* @param callable|string $controller a callable or parseable pseudo-callable
|
||||
* @param callable|string|array $controller a callable or parseable pseudo-callable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function controller($controller)
|
||||
final public function controller($controller): self
|
||||
{
|
||||
$this->route->addDefaults(array('_controller' => $controller));
|
||||
$this->route->addDefaults(['_controller' => $controller]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the "_locale" entry to defaults.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function locale(string $locale): self
|
||||
{
|
||||
$this->route->addDefaults(['_locale' => $locale]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the "_format" entry to defaults.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
final public function format(string $format): self
|
||||
{
|
||||
$this->route->addDefaults(['_format' => $format]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user