Skip to content

Commit 99101f3

Browse files
authored
Merge pull request #475 from symfony-cmf/return-type
add type declarations to our classes
2 parents 64aefbc + 1764e92 commit 99101f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+487
-871
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Changelog
66

77
* Support Symfony 6
88
* Drop support for Symfony older than 6 and PHP older than 8
9+
* Removed deprecated classes, see UPGRADE-3.0.md
10+
* Removed RouteConditionMetadataListener and added condition mapping to ORM and PHPCR route mapping.
911

1012
2.6.0
1113
-----

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
[![Monthly Downloads](https://poser.pugx.org/symfony-cmf/routing-bundle/d/monthly)](https://packagist.org/packages/symfony-cmf/routing-bundle)
99
[![Daily Downloads](https://poser.pugx.org/symfony-cmf/routing-bundle/d/daily)](https://packagist.org/packages/symfony-cmf/routing-bundle)
1010

11-
This package is part of the [Symfony Content Management Framework (CMF)](http://cmf.symfony.com/) and licensed
12-
under the [MIT License](LICENSE).
11+
This package is part of the Symfony Content Management Framework (CMF) and licensed under the [MIT License](LICENSE).
1312

1413
The RoutingBundle enables the
1514
[CMF Routing component](https://github.com/symfony-cmf/Routing)
16-
as a Symfony bundle. It provides route documents for Doctrine PHPCR-ODM and a
17-
controller for redirection routes.
15+
as a Symfony bundle. It provides route documents for Doctrine ORM and PHPCR-ODM,
16+
as well as a controller for redirection routes.
1817

1918

2019
## Requirements
@@ -25,12 +24,11 @@ controller for redirection routes.
2524

2625
For the install guide and reference, see:
2726

28-
* [symfony-cmf/routing-bundle Documentation](http://symfony.com/doc/master/cmf/bundles/routing/index.html)
27+
* [symfony-cmf/routing-bundle Documentation](https://symfony.com/bundles/CMFRoutingBundle/current/routing-bundle/index.html)
2928

3029
See also:
3130

32-
* [All Symfony CMF documentation](http://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference
33-
* [Symfony CMF Website](http://cmf.symfony.com/) - introduction, live demo, support and community links
31+
* [All Symfony CMF documentation](https://symfony.com/bundles/CMFRoutingBundle/current/index.html) - complete Symfony CMF reference
3432

3533
## Support
3634

@@ -39,12 +37,7 @@ For general support and questions, please use [StackOverflow](http://stackoverfl
3937
## Contributing
4038

4139
Pull requests are welcome. Please see our
42-
[CONTRIBUTING](https://github.com/symfony-cmf/blob/master/CONTRIBUTING.md)
43-
guide.
44-
45-
Unit and/or functional tests exist for this package. See the
46-
[Testing documentation](http://symfony.com/doc/master/cmf/components/testing.html)
47-
for a guide to running the tests.
40+
[CONTRIBUTING guide](https://github.com/symfony-cmf/routing-bundle/blob/master/CONTRIBUTING.md).
4841

4942
Thanks to
5043
[everyone who has contributed](contributors) already.

UPGRADE-3.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Upgrade from 2.x to 3.0
2+
3+
## Parameter and return type declarations
4+
5+
If you extend any of the classes in this repository, you will need to adjust
6+
overwritten methods to specify the parameter and return types.

src/CmfRoutingBundle.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
1616
use Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver as PHPCRXmlDriver;
1717
use Doctrine\ODM\PHPCR\Version as PHPCRVersion;
18+
use Doctrine\ORM\EntityManagerInterface;
1819
use Doctrine\ORM\Mapping\Driver\XmlDriver as ORMXmlDriver;
19-
use Doctrine\ORM\Version as ORMVersion;
2020
use Doctrine\Persistence\Mapping\Driver\DefaultFileLocator;
2121
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\RedirectableMatcherPass;
2222
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\SetRouterPass;
@@ -29,12 +29,9 @@
2929
use Symfony\Component\DependencyInjection\Definition;
3030
use Symfony\Component\HttpKernel\Bundle\Bundle;
3131

32-
/**
33-
* Bundle class.
34-
*/
35-
class CmfRoutingBundle extends Bundle
32+
final class CmfRoutingBundle extends Bundle
3633
{
37-
public function build(ContainerBuilder $container)
34+
public function build(ContainerBuilder $container): void
3835
{
3936
parent::build($container);
4037
$container->addCompilerPass(new RegisterRoutersPass());
@@ -52,7 +49,7 @@ public function build(ContainerBuilder $container)
5249
* Creates and registers compiler passes for PHPCR-ODM mapping if both the
5350
* phpcr-odm and the phpcr-bundle are present.
5451
*/
55-
private function buildPhpcrCompilerPass(ContainerBuilder $container)
52+
private function buildPhpcrCompilerPass(ContainerBuilder $container): void
5653
{
5754
if (!class_exists(PHPCRVersion::class)) {
5855
return;
@@ -75,12 +72,11 @@ private function buildPhpcrCompilerPass(ContainerBuilder $container)
7572
}
7673

7774
/**
78-
* Creates and registers compiler passes for ORM mappings if both doctrine
79-
* ORM and a suitable compiler pass implementation are available.
75+
* Creates and registers compiler passes for ORM mappings if doctrine ORM is available.
8076
*/
81-
private function buildOrmCompilerPass(ContainerBuilder $container)
77+
private function buildOrmCompilerPass(ContainerBuilder $container): void
8278
{
83-
if (!class_exists(ORMVersion::class)) {
79+
if (!interface_exists(EntityManagerInterface::class)) {
8480
return;
8581
}
8682

@@ -115,14 +111,8 @@ private function buildOrmCompilerPass(ContainerBuilder $container)
115111
* Builds the compiler pass for the symfony core routing component. The
116112
* compiler pass factory method uses the SymfonyFileLocator which does
117113
* magic with the namespace and thus does not work here.
118-
*
119-
* @param string $compilerClass the compiler class to instantiate
120-
* @param string $driverClass the xml driver class for this backend
121-
* @param string $type the backend type name
122-
*
123-
* @return CompilerPassInterface
124114
*/
125-
private function buildBaseCompilerPass($compilerClass, $driverClass, $type)
115+
private function buildBaseCompilerPass(string $compilerClass, string $driverClass, string $type): CompilerPassInterface
126116
{
127117
$arguments = [[realpath(__DIR__.'/Resources/config/doctrine-base')], sprintf('.%s.xml', $type)];
128118
$locator = new Definition(DefaultFileLocator::class, $arguments);

src/Controller/RedirectController.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,16 @@
2626
* The plus side is that with the route interface we do not need to pass the
2727
* parameters through magic request attributes.
2828
*/
29-
class RedirectController
29+
final class RedirectController
3030
{
31-
/**
32-
* @var RouterInterface
33-
*/
34-
protected $router;
31+
private RouterInterface $router;
3532

36-
/**
37-
* @param RouterInterface $router the router to use to build urls
38-
*/
3933
public function __construct(RouterInterface $router)
4034
{
4135
$this->router = $router;
4236
}
4337

44-
/**
45-
* Action to redirect based on a RedirectRouteInterface route.
46-
*
47-
* @return \Symfony\Component\HttpFoundation\RedirectResponse the response
48-
*/
49-
public function redirectAction(RedirectRouteInterface $contentDocument)
38+
public function redirectAction(RedirectRouteInterface $contentDocument): RedirectResponse
5039
{
5140
$url = $contentDocument->getUri();
5241

src/DependencyInjection/CmfRoutingExtension.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
* @author David Buchmann
2626
* @author Wouter de Jong <[email protected]>
2727
*/
28-
class CmfRoutingExtension extends Extension
28+
final class CmfRoutingExtension extends Extension
2929
{
3030
/**
3131
* {@inheritdoc}
3232
*/
33-
public function load(array $configs, ContainerBuilder $container)
33+
public function load(array $configs, ContainerBuilder $container): void
3434
{
3535
$config = $this->processConfiguration(new Configuration(), $configs);
3636
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -45,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container)
4545
$loader->load('validators.xml');
4646
}
4747

48-
private function setupChainRouter(array $config, ContainerBuilder $container, LoaderInterface $loader)
48+
private function setupChainRouter(array $config, ContainerBuilder $container, LoaderInterface $loader): void
4949
{
5050
$loader->load('routing-chain.xml');
5151

@@ -58,7 +58,7 @@ private function setupChainRouter(array $config, ContainerBuilder $container, Lo
5858
}
5959
}
6060

61-
private function setupFormTypes(array $config, ContainerBuilder $container, LoaderInterface $loader)
61+
private function setupFormTypes(array $config, ContainerBuilder $container, LoaderInterface $loader): void
6262
{
6363
$loader->load('form-type.xml');
6464

@@ -73,12 +73,8 @@ private function setupFormTypes(array $config, ContainerBuilder $container, Load
7373

7474
/**
7575
* Set up the DynamicRouter - only to be called if enabled is set to true.
76-
*
77-
* @param array $config the compiled configuration for the dynamic router
78-
* @param ContainerBuilder $container the container builder
79-
* @param LoaderInterface $loader the configuration loader
8076
*/
81-
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader)
77+
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader): void
8278
{
8379
$loader->load('routing-dynamic.xml');
8480

@@ -210,7 +206,7 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
210206
$dynamic->replaceArgument(2, new Reference($config['url_generator']));
211207
}
212208

213-
private function loadPhpcrProvider(array $config, LoaderInterface $loader, ContainerBuilder $container, array $locales, $matchImplicitLocale)
209+
private function loadPhpcrProvider(array $config, LoaderInterface $loader, ContainerBuilder $container, array $locales, $matchImplicitLocale): void
214210
{
215211
$loader->load('provider-phpcr.xml');
216212

@@ -232,7 +228,7 @@ private function loadPhpcrProvider(array $config, LoaderInterface $loader, Conta
232228
}
233229
}
234230

235-
private function loadInitializer(LoaderInterface $loader, ContainerBuilder $container)
231+
private function loadInitializer(LoaderInterface $loader, ContainerBuilder $container): void
236232
{
237233
$initializedBasepaths = $container->getParameter($this->getAlias().'.dynamic.persistence.phpcr.route_basepaths');
238234

@@ -244,7 +240,7 @@ private function loadInitializer(LoaderInterface $loader, ContainerBuilder $cont
244240
$loader->load('initializer-phpcr.xml');
245241
}
246242

247-
private function loadOrmProvider(array $config, LoaderInterface $loader, ContainerBuilder $container, $matchImplicitLocale)
243+
private function loadOrmProvider(array $config, LoaderInterface $loader, ContainerBuilder $container, $matchImplicitLocale): void
248244
{
249245
$loader->load('provider-orm.xml');
250246

@@ -264,28 +260,21 @@ private function loadOrmProvider(array $config, LoaderInterface $loader, Contain
264260
}
265261

266262
/**
267-
* @param ContainerBuilder $container The container builder
268-
* @param array $config The config array
269-
* @param array $settingToParameter An array with setting to parameter mappings (key = setting, value = parameter name without alias prefix)
263+
* @param array<string, string> $settingToParameter An array with setting to parameter mappings (key = setting, value = parameter name without alias prefix)
270264
*/
271-
private function configureParameters(ContainerBuilder $container, array $config, array $settingToParameter)
265+
private function configureParameters(ContainerBuilder $container, array $config, array $settingToParameter): void
272266
{
273267
foreach ($settingToParameter as $setting => $parameter) {
274268
$container->setParameter('cmf_routing.'.$parameter, $config[$setting]);
275269
}
276270
}
277271

278-
/**
279-
* Returns the base path for the XSD files.
280-
*
281-
* @return string The XSD base path
282-
*/
283-
public function getXsdValidationBasePath()
272+
public function getXsdValidationBasePath(): string
284273
{
285274
return __DIR__.'/../Resources/config/schema';
286275
}
287276

288-
public function getNamespace()
277+
public function getNamespace(): string
289278
{
290279
return 'http://cmf.symfony.com/schema/dic/routing';
291280
}

src/DependencyInjection/Compiler/RedirectableMatcherPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
/**
2121
* If enabled, change the nested matcher implementation to the redirectable matcher.
2222
*/
23-
class RedirectableMatcherPass implements CompilerPassInterface
23+
final class RedirectableMatcherPass implements CompilerPassInterface
2424
{
25-
public function process(ContainerBuilder $container)
25+
public function process(ContainerBuilder $container): void
2626
{
2727
// only replace the nested matcher if config tells us to
2828
if (!$container->hasParameter('cmf_routing.redirectable_url_matcher') || false === $container->getParameter('cmf_routing.redirectable_url_matcher')) {

src/DependencyInjection/Compiler/SetRouterPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
* Changes the Router implementation.
1919
*/
20-
class SetRouterPass implements CompilerPassInterface
20+
final class SetRouterPass implements CompilerPassInterface
2121
{
22-
public function process(ContainerBuilder $container)
22+
public function process(ContainerBuilder $container): void
2323
{
2424
// only replace the default router by overwriting the 'router' alias if config tells us to
2525
if ($container->hasParameter('cmf_routing.replace_symfony_router') && true === $container->getParameter('cmf_routing.replace_symfony_router')) {

src/DependencyInjection/Compiler/ValidationPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
* Register validation files if their storage is activated.
1919
*/
20-
class ValidationPass implements CompilerPassInterface
20+
final class ValidationPass implements CompilerPassInterface
2121
{
22-
public function process(ContainerBuilder $container)
22+
public function process(ContainerBuilder $container): void
2323
{
2424
if ($container->hasParameter('cmf_routing.backend_type_phpcr') && $container->hasDefinition('validator.builder')) {
2525
$container

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,20 @@
2424
*
2525
* @author David Buchmann
2626
*/
27-
class Configuration implements ConfigurationInterface
27+
final class Configuration implements ConfigurationInterface
2828
{
29-
/**
30-
* Returns the config tree builder.
31-
*
32-
* @return TreeBuilder
33-
*/
34-
public function getConfigTreeBuilder()
29+
public function getConfigTreeBuilder(): TreeBuilder
3530
{
3631
$treeBuilder = new TreeBuilder('cmf_routing');
37-
if (method_exists($treeBuilder, 'getRootNode')) {
38-
$root = $treeBuilder->getRootNode();
39-
} else {
40-
// BC layer for symfony/config 4.1 and older
41-
$root = $treeBuilder->root('cmf_routing');
42-
}
32+
$root = $treeBuilder->getRootNode();
4333

4434
$this->addChainSection($root);
4535
$this->addDynamicSection($root);
4636

4737
return $treeBuilder;
4838
}
4939

50-
private function addChainSection(ArrayNodeDefinition $root)
40+
private function addChainSection(ArrayNodeDefinition $root): void
5141
{
5242
$root
5343
->children()
@@ -67,7 +57,7 @@ private function addChainSection(ArrayNodeDefinition $root)
6757
;
6858
}
6959

70-
private function addDynamicSection(ArrayNodeDefinition $root)
60+
private function addDynamicSection(ArrayNodeDefinition $root): void
7161
{
7262
$root
7363
->children()

0 commit comments

Comments
 (0)