[Routing] Add type-hints to all public interfaces.
This commit is contained in:
parent
06899a13b4
commit
457b3227f7
@ -31,7 +31,7 @@ class CompiledUrlGenerator extends UrlGenerator
|
|||||||
$this->defaultLocale = $defaultLocale;
|
$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']
|
$locale = $parameters['_locale']
|
||||||
?? $this->context->getParameter('_locale')
|
?? $this->context->getParameter('_locale')
|
||||||
|
@ -40,10 +40,8 @@ interface ConfigurableRequirementsInterface
|
|||||||
/**
|
/**
|
||||||
* Enables or disables the exception on incorrect parameters.
|
* Enables or disables the exception on incorrect parameters.
|
||||||
* Passing null will deactivate the requirements check completely.
|
* 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.
|
* Returns whether to throw an exception on incorrect parameters.
|
||||||
|
@ -108,9 +108,9 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
|
||||||
{
|
{
|
||||||
$route = null;
|
$route = null;
|
||||||
$locale = $parameters['_locale']
|
$locale = $parameters['_locale']
|
||||||
@ -155,7 +155,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||||
* it does not match the requirement
|
* it does not match the requirement
|
||||||
*/
|
*/
|
||||||
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);
|
$variables = array_flip($variables);
|
||||||
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
|
||||||
@ -321,7 +321,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
|
|||||||
*
|
*
|
||||||
* @return string The relative target path
|
* @return string The relative target path
|
||||||
*/
|
*/
|
||||||
public static function getRelativePath($basePath, $targetPath)
|
public static function getRelativePath(string $basePath, string $targetPath)
|
||||||
{
|
{
|
||||||
if ($basePath === $targetPath) {
|
if ($basePath === $targetPath) {
|
||||||
return '';
|
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.
|
* 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
|
* @return string The generated URL
|
||||||
*
|
*
|
||||||
* @throws RouteNotFoundException If the named route doesn't exist
|
* @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
|
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
|
||||||
* it does not match the requirement
|
* 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);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ abstract class RedirectableUrlMatcher extends UrlMatcher implements Redirectable
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function match($pathinfo)
|
public function match(string $pathinfo)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return parent::match($pathinfo);
|
return parent::match($pathinfo);
|
||||||
|
@ -27,5 +27,5 @@ interface RedirectableUrlMatcherInterface
|
|||||||
*
|
*
|
||||||
* @return array An array of parameters
|
* @return array An array of parameters
|
||||||
*/
|
*/
|
||||||
public function redirect($path, $route, $scheme = null);
|
public function redirect(string $path, string $route, string $scheme = null);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function match($pathinfo)
|
public function match(string $pathinfo)
|
||||||
{
|
{
|
||||||
$this->allow = $this->allowSchemes = [];
|
$this->allow = $this->allowSchemes = [];
|
||||||
|
|
||||||
|
@ -37,5 +37,5 @@ interface UrlMatcherInterface extends RequestContextAwareInterface
|
|||||||
* @throws ResourceNotFoundException If the resource could not be found
|
* @throws ResourceNotFoundException If the resource could not be found
|
||||||
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
|
||||||
*/
|
*/
|
||||||
public function match($pathinfo);
|
public function match(string $pathinfo);
|
||||||
}
|
}
|
||||||
|
@ -159,12 +159,11 @@ class Router implements RouterInterface, RequestMatcherInterface
|
|||||||
/**
|
/**
|
||||||
* Sets an option.
|
* Sets an option.
|
||||||
*
|
*
|
||||||
* @param string $key The key
|
* @param mixed $value The value
|
||||||
* @param mixed $value The value
|
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function setOption($key, $value)
|
public function setOption(string $key, $value)
|
||||||
{
|
{
|
||||||
if (!\array_key_exists($key, $this->options)) {
|
if (!\array_key_exists($key, $this->options)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
||||||
@ -176,13 +175,11 @@ class Router implements RouterInterface, RequestMatcherInterface
|
|||||||
/**
|
/**
|
||||||
* Gets an option value.
|
* Gets an option value.
|
||||||
*
|
*
|
||||||
* @param string $key The key
|
|
||||||
*
|
|
||||||
* @return mixed The value
|
* @return mixed The value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function getOption($key)
|
public function getOption(string $key)
|
||||||
{
|
{
|
||||||
if (!\array_key_exists($key, $this->options)) {
|
if (!\array_key_exists($key, $this->options)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
|
||||||
@ -237,7 +234,7 @@ class Router implements RouterInterface, RequestMatcherInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
|
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH)
|
||||||
{
|
{
|
||||||
return $this->getGenerator()->generate($name, $parameters, $referenceType);
|
return $this->getGenerator()->generate($name, $parameters, $referenceType);
|
||||||
}
|
}
|
||||||
@ -245,7 +242,7 @@ class Router implements RouterInterface, RequestMatcherInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function match($pathinfo)
|
public function match(string $pathinfo)
|
||||||
{
|
{
|
||||||
return $this->getMatcher()->match($pathinfo);
|
return $this->getMatcher()->match($pathinfo);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ use Symfony\Component\Routing\Matcher\UrlMatcher;
|
|||||||
*/
|
*/
|
||||||
class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
|
class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
|
||||||
{
|
{
|
||||||
public function redirect($path, $route, $scheme = null)
|
public function redirect(string $path, string $route, string $scheme = null)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'_controller' => 'Some controller reference...',
|
'_controller' => 'Some controller reference...',
|
||||||
|
@ -33,7 +33,7 @@ class CompiledRedirectableUrlMatcherTest extends RedirectableUrlMatcherTest
|
|||||||
|
|
||||||
class TestCompiledRedirectableUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
|
class TestCompiledRedirectableUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
|
||||||
{
|
{
|
||||||
public function redirect($path, $route, $scheme = null)
|
public function redirect(string $path, string $route, string $scheme = null)
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ class CompiledUrlMatcherDumperTest extends TestCase
|
|||||||
|
|
||||||
class TestCompiledUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
|
class TestCompiledUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
|
||||||
{
|
{
|
||||||
public function redirect($path, $route, $scheme = null)
|
public function redirect(string $path, string $route, string $scheme = null)
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user