upgrade to laravel 7 and set branch to v2
This commit is contained in:
@@ -31,7 +31,7 @@ class CompiledUrlGenerator extends UrlGenerator
|
||||
$this->defaultLocale = $defaultLocale;
|
||||
}
|
||||
|
||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
||||
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
$locale = $parameters['_locale']
|
||||
?? $this->context->getParameter('_locale')
|
||||
|
||||
@@ -40,10 +40,8 @@ interface ConfigurableRequirementsInterface
|
||||
/**
|
||||
* Enables or disables the exception on incorrect parameters.
|
||||
* Passing null will deactivate the requirements check completely.
|
||||
*
|
||||
* @param bool|null $enabled
|
||||
*/
|
||||
public function setStrictRequirements($enabled);
|
||||
public function setStrictRequirements(?bool $enabled);
|
||||
|
||||
/**
|
||||
* Returns whether to throw an exception on incorrect parameters.
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
<?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;
|
||||
|
||||
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.3, use "CompiledUrlGeneratorDumper" instead.', PhpGeneratorDumper::class), \E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*
|
||||
* @deprecated since Symfony 4.3, use CompiledUrlGeneratorDumper instead.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
$options = array_merge([
|
||||
'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;
|
||||
|
||||
/**
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Routing Component.
|
||||
*/
|
||||
class {$options['class']} extends {$options['base_class']}
|
||||
{
|
||||
private static \$declaredRoutes;
|
||||
private \$defaultLocale;
|
||||
|
||||
public function __construct(RequestContext \$context, LoggerInterface \$logger = null, string \$defaultLocale = null)
|
||||
{
|
||||
\$this->context = \$context;
|
||||
\$this->logger = \$logger;
|
||||
\$this->defaultLocale = \$defaultLocale;
|
||||
if (null === self::\$declaredRoutes) {
|
||||
self::\$declaredRoutes = {$this->generateDeclaredRoutes()};
|
||||
}
|
||||
}
|
||||
|
||||
{$this->generateGenerateMethod()}
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code representing an array of defined routes
|
||||
* together with the routes properties (e.g. requirements).
|
||||
*/
|
||||
private function generateDeclaredRoutes(): string
|
||||
{
|
||||
$routes = "[\n";
|
||||
foreach ($this->getRoutes()->all() as $name => $route) {
|
||||
$compiledRoute = $route->compile();
|
||||
|
||||
$properties = [];
|
||||
$properties[] = $compiledRoute->getVariables();
|
||||
$properties[] = $route->getDefaults();
|
||||
$properties[] = $route->getRequirements();
|
||||
$properties[] = $compiledRoute->getTokens();
|
||||
$properties[] = $compiledRoute->getHostTokens();
|
||||
$properties[] = $route->getSchemes();
|
||||
|
||||
$routes .= sprintf(" '%s' => %s,\n", $name, CompiledUrlMatcherDumper::export($properties));
|
||||
}
|
||||
$routes .= ' ]';
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates PHP code representing the `generate` method that implements the UrlGeneratorInterface.
|
||||
*/
|
||||
private function generateGenerateMethod(): string
|
||||
{
|
||||
return <<<'EOF'
|
||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
$locale = $parameters['_locale']
|
||||
?? $this->context->getParameter('_locale')
|
||||
?: $this->defaultLocale;
|
||||
|
||||
if (null !== $locale && null !== $name) {
|
||||
do {
|
||||
if ((self::$declaredRoutes[$name.'.'.$locale][1]['_canonical_route'] ?? null) === $name) {
|
||||
$name .= '.'.$locale;
|
||||
break;
|
||||
}
|
||||
} while (false !== $locale = strstr($locale, '_', true));
|
||||
}
|
||||
|
||||
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, $requiredSchemes) = self::$declaredRoutes[$name];
|
||||
|
||||
if (isset($defaults['_canonical_route']) && isset($defaults['_locale'])) {
|
||||
if (!\in_array('_locale', $variables, true)) {
|
||||
unset($parameters['_locale']);
|
||||
} elseif (!isset($parameters['_locale'])) {
|
||||
$parameters['_locale'] = $defaults['_locale'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
@@ -108,9 +108,9 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStrictRequirements($enabled)
|
||||
public function setStrictRequirements(?bool $enabled)
|
||||
{
|
||||
$this->strictRequirements = null === $enabled ? null : (bool) $enabled;
|
||||
$this->strictRequirements = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +124,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
||||
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
|
||||
{
|
||||
$route = null;
|
||||
$locale = $parameters['_locale']
|
||||
@@ -167,7 +167,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
|
||||
protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = [])
|
||||
{
|
||||
$variables = array_flip($variables);
|
||||
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
||||
@@ -333,7 +333,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
||||
*
|
||||
* @return string The relative target path
|
||||
*/
|
||||
public static function getRelativePath($basePath, $targetPath)
|
||||
public static function getRelativePath(string $basePath, string $targetPath)
|
||||
{
|
||||
if ($basePath === $targetPath) {
|
||||
return '';
|
||||
|
||||
@@ -71,10 +71,6 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
|
||||
*
|
||||
* The special parameter _fragment will be used as the document fragment suffixed to the final URL.
|
||||
*
|
||||
* @param string $name The name of the route
|
||||
* @param mixed[] $parameters An array of parameters
|
||||
* @param int $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
|
||||
@@ -82,5 +78,5 @@ interface UrlGeneratorInterface extends RequestContextAwareInterface
|
||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||
* it does not match the requirement
|
||||
*/
|
||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH);
|
||||
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user