Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] adding typehint to some functions and parameters #51005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
*
* @return void
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void
{
if ('__invoke' === $method->getName()) {
$route->setDefault('_controller', $class->getName());
Expand Down
95 changes: 19 additions & 76 deletions src/Symfony/Component/Routing/Annotation/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,17 @@ public function __construct(
}
}

/**
* @return void
*/
public function setPath(string $path)
public function setPath(string $path): void
{
$this->path = $path;
}

/**
* @return string|null
*/
public function getPath()
public function getPath(): ?string
{
return $this->path;
}

/**
* @return void
*/
public function setLocalizedPaths(array $localizedPaths)
public function setLocalizedPaths(array $localizedPaths): void
{
$this->localizedPaths = $localizedPaths;
}
Expand All @@ -105,130 +96,82 @@ public function getLocalizedPaths(): array
return $this->localizedPaths;
}

/**
* @return void
*/
public function setHost(string $pattern)
public function setHost(string $pattern): void
{
$this->host = $pattern;
}

/**
* @return string|null
*/
public function getHost()
public function getHost(): ?string
{
return $this->host;
}

/**
* @return void
*/
public function setName(string $name)
public function setName(string $name): void
{
$this->name = $name;
}

/**
* @return string|null
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}

/**
* @return void
*/
public function setRequirements(array $requirements)
public function setRequirements(array $requirements): void
{
$this->requirements = $requirements;
}

/**
* @return array
*/
public function getRequirements()
public function getRequirements(): array
{
return $this->requirements;
}

/**
* @return void
*/
public function setOptions(array $options)
public function setOptions(array $options): void
{
$this->options = $options;
}

/**
* @return array
*/
public function getOptions()
public function getOptions(): array
{
return $this->options;
}

/**
* @return void
*/
public function setDefaults(array $defaults)
public function setDefaults(array $defaults): void
{
$this->defaults = $defaults;
}

/**
* @return array
*/
public function getDefaults()
public function getDefaults(): array
{
return $this->defaults;
}

/**
* @return void
*/
public function setSchemes(array|string $schemes)
public function setSchemes(array|string $schemes): void
{
$this->schemes = (array) $schemes;
}

/**
* @return array
*/
public function getSchemes()
public function getSchemes(): array
{
return $this->schemes;
}

/**
* @return void
*/
public function setMethods(array|string $methods)
public function setMethods(array|string $methods): void
{
$this->methods = (array) $methods;
}

/**
* @return array
*/
public function getMethods()
public function getMethods(): array
{
return $this->methods;
}

/**
* @return void
*/
public function setCondition(?string $condition)
public function setCondition(?string $condition): void
{
$this->condition = $condition;
}

/**
* @return string|null
*/
public function getCondition()
public function getCondition(): ?string
{
return $this->condition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class RoutingResolverPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

/**
* @return void
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (false === $container->hasDefinition('routing.resolver')) {
return;
Expand Down
30 changes: 9 additions & 21 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,8 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
'%2A' => '*',
];

protected $routes;
protected $context;
protected ?bool $strictRequirements = true;

/**
* @var bool|null
*/
protected $strictRequirements = true;

protected $logger;

private ?string $defaultLocale;

/**
* This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
Expand All @@ -62,7 +53,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
* "?" and "#" (would be interpreted wrongly as query and fragment identifier),
* "'" and """ (are used as delimiters in HTML).
*/
protected $decodedChars = [
protected array $decodedChars = [
// 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
Expand All @@ -83,12 +74,12 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
'%7C' => '|',
];

public function __construct(RouteCollection $routes, RequestContext $context, LoggerInterface $logger = null, string $defaultLocale = null)
{
$this->routes = $routes;
$this->context = $context;
$this->logger = $logger;
$this->defaultLocale = $defaultLocale;
public function __construct(
protected RouteCollection $routes,
protected RequestContext $context,
protected ?LoggerInterface $logger = null,
private ?string $defaultLocale = null
) {
}

/**
Expand All @@ -104,10 +95,7 @@ public function getContext(): RequestContext
return $this->context;
}

/**
* @return void
*/
public function setStrictRequirements(?bool $enabled)
public function setStrictRequirements(?bool $enabled): void
{
$this->strictRequirements = $enabled;
}
Expand Down
48 changes: 12 additions & 36 deletions src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,20 @@
*/
abstract class AnnotationClassLoader implements LoaderInterface
{
protected $reader;
protected $env;
protected string $routeAnnotationClass = RouteAnnotation::class;

/**
* @var string
*/
protected $routeAnnotationClass = RouteAnnotation::class;

/**
* @var int
*/
protected $defaultRouteIndex = 0;
protected int $defaultRouteIndex = 0;

public function __construct(Reader $reader = null, string $env = null)
{
$this->reader = $reader;
$this->env = $env;
public function __construct(
protected ?Reader $reader = null,
protected ?string $env = null
) {
}

/**
* Sets the annotation class to read route properties from.
*
* @return void
*/
public function setRouteAnnotationClass(string $class)
public function setRouteAnnotationClass(string $class): void
{
$this->routeAnnotationClass = $class;
}
Expand Down Expand Up @@ -160,10 +149,8 @@ public function load(mixed $class, string $type = null): RouteCollection

/**
* @param RouteAnnotation $annot or an object that exposes a similar interface
*
* @return void
*/
protected function addRoute(RouteCollection $collection, object $annot, array $globals, \ReflectionClass $class, \ReflectionMethod $method)
protected function addRoute(RouteCollection $collection, object $annot, array $globals, \ReflectionClass $class, \ReflectionMethod $method): void
{
if ($annot->getEnv() && $annot->getEnv() !== $this->env) {
return;
Expand Down Expand Up @@ -263,10 +250,8 @@ public function getResolver(): LoaderResolverInterface

/**
* Gets the default route name for a class method.
*
* @return string
*/
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
{
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
$name = \function_exists('mb_strtolower') && preg_match('//u', $name) ? mb_strtolower($name, 'UTF-8') : strtolower($name);
Expand All @@ -278,10 +263,7 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
return $name;
}

/**
* @return array
*/
protected function getGlobals(\ReflectionClass $class)
protected function getGlobals(\ReflectionClass $class): array
{
$globals = $this->resetGlobals();

Expand Down Expand Up @@ -363,18 +345,12 @@ private function resetGlobals(): array
];
}

/**
* @return Route
*/
protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition)
protected function createRoute(string $path, array $defaults, array $requirements, array $options, ?string $host, array $schemes, array $methods, ?string $condition): Route
{
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
}

/**
* @return void
*/
abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot);
abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void;

/**
* @param \ReflectionClass|\ReflectionMethod $reflection
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
*/
class AnnotationFileLoader extends FileLoader
{
protected $loader;

public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
{
public function __construct(
FileLocatorInterface $locator,
protected AnnotationClassLoader $loader
) {
if (!\function_exists('token_get_all')) {
throw new \LogicException('The Tokenizer extension is required for the routing annotation loaders.');
}

parent::__construct($locator);

$this->loader = $loader;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Routing/Loader/ContainerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
*/
class ContainerLoader extends ObjectLoader
{
private ContainerInterface $container;

public function __construct(ContainerInterface $container, string $env = null)
public function __construct(private ContainerInterface $container, string $env = null)
{
$this->container = $container;
parent::__construct($env);
Expand Down
Loading