Skip to content
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

Allow Symfony 6 #33

Merged
merged 4 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 15 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ on:

jobs:
tests:
name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.stability }}
name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.deps }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [7.2, 7.4, 8.0]
symfony: [4.4.*, 5.2.*]
stability: [hightest]
php: [ 7.4, 8.0 ]
symfony: [ 4.4.*, 5.3.*, 5.4.* ]
deps: [ hightest ]
include:
- php: 7.2
stability: lowest
deps: lowest
symfony: '*'
- php: 8.0
stability: highest
symfony: '@dev'
deps: highest
symfony: 6.0.*

steps:
- name: Checkout code
Expand All @@ -31,27 +30,24 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install Symfony Flex
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main

- name: Set minimum-stability to dev
run: composer config minimum-stability dev
if: ${{ matrix.symfony == '@dev' }}
tools: flex

- name: Install dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{ matrix.stability }}
dependency-versions: ${{ matrix.deps }}
composer-options: --prefer-dist
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Install phpspec
run: composer bin phpspec install

- name: Run tests
run: bin/phpunit -v
run: vendor/bin/simple-phpunit -v

- name: Run phpspec
run: bin/phpspec run --format=pretty
run: vendor/bin/phpspec run --format=pretty

code-coverage:
name: Code Coverage
Expand All @@ -72,7 +68,7 @@ jobs:
composer-options: --prefer-dist

- name: Run code coverage
run: bin/phpunit -v --coverage-text
run: vendor/bin/simple-phpunit -v --coverage-text

composer-validate:
name: Validate composer.json
Expand Down
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
bin
composer.lock
vendor
tests/fixtures/app/cache
tests/fixtures/app/logs
.php_cs.cache
var
/composer.lock
/vendor
/tests/fixtures/app/cache
/tests/fixtures/app/logs
/.php_cs.cache
/var
/bin/tools/*/vendor/
/bin/tools/*/composer.lock
5 changes: 5 additions & 0 deletions bin/tools/phpspec/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"phpspec/phpspec": "^6.3|^7.0"
}
}
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@
],
"require": {
"php": "^7.2|^8.0",
"symfony/framework-bundle": "^4.4|^5.0"
"symfony/framework-bundle": "^4.4|^5.0|^6.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpspec/phpspec": "^6.3|^7.0",
"symfony/var-dumper": "^4.4|^5.0",
"symfony/phpunit-bridge": "^5.2"
"symfony/var-dumper": "^4.4|^5.0|^6.0",
"symfony/phpunit-bridge": "^5.3",
"bamarni/composer-bin-plugin": "^1.4",
"symfony/yaml": "^4.4|^5.0|^6.0"
},
"autoload": {
"psr-4": { "Umpirsky\\I18nRoutingBundle\\": "src/" }
},
"autoload-dev": {
"files": ["tests/fixtures/app/AppKernel.php"]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"branch-alias": {
"dev-master": "0.0.1-dev"
},
"bamarni-bin": {
"target-directory": "bin/tools"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
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
2 changes: 1 addition & 1 deletion tests/fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AppKernel extends Kernel
{
public function registerBundles()
public function registerBundles(): iterable
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
Expand Down