Skip to content

Commit

Permalink
adjust type-hints to be forward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Nov 2, 2021
1 parent 3fa756d commit 28e864a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
11 changes: 2 additions & 9 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@

final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('umpirsky_i18n_routing');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('umpirsky_i18n_routing');
}

$rootNode
$treeBuilder->getRootNode()
->children()
->scalarNode('route_name_suffix')->defaultValue('_i18n')->end()
->scalarNode('default_locale')->isRequired()->end()
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/UmpirskyI18nRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class UmpirskyI18nRoutingExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), $configs);
Expand Down
4 changes: 2 additions & 2 deletions src/Routing/Loader/I18nRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function supports($resource, $type = null): bool
return $this->loader->supports($resource, $type);
}

public function getResolver()
public function getResolver(): LoaderResolverInterface
{
return $this->loader->getResolver();
}

public function setResolver(LoaderResolverInterface $resolver)
public function setResolver(LoaderResolverInterface $resolver): void
{
$this->loader->setResolver($resolver);
}
Expand Down
23 changes: 13 additions & 10 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;

/**
Expand All @@ -29,22 +30,22 @@ public function __construct(RouterInterface $router, string $routeNameSuffix, st
$this->defaultLocale = $defaultLocale;
}

public function setContext(RequestContext $context)
public function setContext(RequestContext $context): void
{
$this->router->setContext($context);
}

public function getContext()
public function getContext(): RequestContext
{
return $this->router->getContext();
}

public function getRouteCollection()
public function getRouteCollection(): RouteCollection
{
return $this->router->getRouteCollection();
}

public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH): string
{
if (array_key_exists('_locale', $parameters) && $parameters['_locale'] === $this->defaultLocale) {
unset($parameters['_locale']);
Expand All @@ -59,27 +60,29 @@ public function generate($name, $parameters = array(), $referenceType = self::AB
return $this->router->generate($name, $parameters, $referenceType);
}

public function match($pathinfo)
public function match($pathinfo): array
{
return $this->normalizeI18nMatch($this->router->match($pathinfo));
}

public function matchRequest(Request $request)
public function matchRequest(Request $request): array
{
return $this->normalizeI18nMatch($this->router->matchRequest($request));
}

public function warmUp($cacheDir)
public function warmUp($cacheDir): array
{
if ($this->router instanceof WarmableInterface) {
$this->router->warmUp($cacheDir);
return $this->router->warmUp($cacheDir);
}

return [];
}

/**
* @todo Inject route name suffix
*/
private function generateI18n($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
private function generateI18n($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string
{
if (!array_key_exists('_locale', $parameters) && (!$this->getContext()->hasParameter('_locale') || $this->defaultLocale === $this->getContext()->getParameter('_locale'))) {
return $this->router->generate($name, $parameters, $referenceType);
Expand All @@ -90,7 +93,7 @@ private function generateI18n($name, $parameters = [], $referenceType = self::AB
return $this->router->generate($name.$this->routeNameSuffix, $parameters, $referenceType);
}

private function normalizeI18nMatch(array $parameters)
private function normalizeI18nMatch(array $parameters): array
{
$i18nPosition = strlen($parameters['_route']) - strlen($this->routeNameSuffix);

Expand Down
1 change: 0 additions & 1 deletion src/Routing/Strategy/PrefixStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Umpirsky\I18nRoutingBundle\Routing\Generator\LocaleRequirementGeneratorInterface;

class PrefixStrategy extends AbstractStrategy
{
Expand Down

0 comments on commit 28e864a

Please sign in to comment.