Skip to content

Commit

Permalink
Merge pull request #475 from symfony-cmf/return-type
Browse files Browse the repository at this point in the history
add type declarations to our classes
  • Loading branch information
dbu authored Feb 11, 2022
2 parents 64aefbc + 1764e92 commit 99101f3
Show file tree
Hide file tree
Showing 41 changed files with 487 additions and 871 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

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

2.6.0
-----
Expand Down
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
[![Monthly Downloads](https://poser.pugx.org/symfony-cmf/routing-bundle/d/monthly)](https://packagist.org/packages/symfony-cmf/routing-bundle)
[![Daily Downloads](https://poser.pugx.org/symfony-cmf/routing-bundle/d/daily)](https://packagist.org/packages/symfony-cmf/routing-bundle)

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

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


## Requirements
Expand All @@ -25,12 +24,11 @@ controller for redirection routes.

For the install guide and reference, see:

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

See also:

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

## Support

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

Pull requests are welcome. Please see our
[CONTRIBUTING](https://github.com/symfony-cmf/blob/master/CONTRIBUTING.md)
guide.

Unit and/or functional tests exist for this package. See the
[Testing documentation](http://symfony.com/doc/master/cmf/components/testing.html)
for a guide to running the tests.
[CONTRIBUTING guide](https://github.com/symfony-cmf/routing-bundle/blob/master/CONTRIBUTING.md).

Thanks to
[everyone who has contributed](contributors) already.
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Upgrade from 2.x to 3.0

## Parameter and return type declarations

If you extend any of the classes in this repository, you will need to adjust
overwritten methods to specify the parameter and return types.
26 changes: 8 additions & 18 deletions src/CmfRoutingBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
use Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver as PHPCRXmlDriver;
use Doctrine\ODM\PHPCR\Version as PHPCRVersion;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\XmlDriver as ORMXmlDriver;
use Doctrine\ORM\Version as ORMVersion;
use Doctrine\Persistence\Mapping\Driver\DefaultFileLocator;
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\RedirectableMatcherPass;
use Symfony\Cmf\Bundle\RoutingBundle\DependencyInjection\Compiler\SetRouterPass;
Expand All @@ -29,12 +29,9 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Bundle class.
*/
class CmfRoutingBundle extends Bundle
final class CmfRoutingBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new RegisterRoutersPass());
Expand All @@ -52,7 +49,7 @@ public function build(ContainerBuilder $container)
* Creates and registers compiler passes for PHPCR-ODM mapping if both the
* phpcr-odm and the phpcr-bundle are present.
*/
private function buildPhpcrCompilerPass(ContainerBuilder $container)
private function buildPhpcrCompilerPass(ContainerBuilder $container): void
{
if (!class_exists(PHPCRVersion::class)) {
return;
Expand All @@ -75,12 +72,11 @@ private function buildPhpcrCompilerPass(ContainerBuilder $container)
}

/**
* Creates and registers compiler passes for ORM mappings if both doctrine
* ORM and a suitable compiler pass implementation are available.
* Creates and registers compiler passes for ORM mappings if doctrine ORM is available.
*/
private function buildOrmCompilerPass(ContainerBuilder $container)
private function buildOrmCompilerPass(ContainerBuilder $container): void
{
if (!class_exists(ORMVersion::class)) {
if (!interface_exists(EntityManagerInterface::class)) {
return;
}

Expand Down Expand Up @@ -115,14 +111,8 @@ private function buildOrmCompilerPass(ContainerBuilder $container)
* Builds the compiler pass for the symfony core routing component. The
* compiler pass factory method uses the SymfonyFileLocator which does
* magic with the namespace and thus does not work here.
*
* @param string $compilerClass the compiler class to instantiate
* @param string $driverClass the xml driver class for this backend
* @param string $type the backend type name
*
* @return CompilerPassInterface
*/
private function buildBaseCompilerPass($compilerClass, $driverClass, $type)
private function buildBaseCompilerPass(string $compilerClass, string $driverClass, string $type): CompilerPassInterface
{
$arguments = [[realpath(__DIR__.'/Resources/config/doctrine-base')], sprintf('.%s.xml', $type)];
$locator = new Definition(DefaultFileLocator::class, $arguments);
Expand Down
17 changes: 3 additions & 14 deletions src/Controller/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,16 @@
* The plus side is that with the route interface we do not need to pass the
* parameters through magic request attributes.
*/
class RedirectController
final class RedirectController
{
/**
* @var RouterInterface
*/
protected $router;
private RouterInterface $router;

/**
* @param RouterInterface $router the router to use to build urls
*/
public function __construct(RouterInterface $router)
{
$this->router = $router;
}

/**
* Action to redirect based on a RedirectRouteInterface route.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse the response
*/
public function redirectAction(RedirectRouteInterface $contentDocument)
public function redirectAction(RedirectRouteInterface $contentDocument): RedirectResponse
{
$url = $contentDocument->getUri();

Expand Down
35 changes: 12 additions & 23 deletions src/DependencyInjection/CmfRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
* @author David Buchmann
* @author Wouter de Jong <[email protected]>
*/
class CmfRoutingExtension extends Extension
final class CmfRoutingExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration(new Configuration(), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand All @@ -45,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('validators.xml');
}

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

Expand All @@ -58,7 +58,7 @@ private function setupChainRouter(array $config, ContainerBuilder $container, Lo
}
}

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

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

/**
* Set up the DynamicRouter - only to be called if enabled is set to true.
*
* @param array $config the compiled configuration for the dynamic router
* @param ContainerBuilder $container the container builder
* @param LoaderInterface $loader the configuration loader
*/
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader)
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader): void
{
$loader->load('routing-dynamic.xml');

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

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

Expand All @@ -232,7 +228,7 @@ private function loadPhpcrProvider(array $config, LoaderInterface $loader, Conta
}
}

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

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

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

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

/**
* @param ContainerBuilder $container The container builder
* @param array $config The config array
* @param array $settingToParameter An array with setting to parameter mappings (key = setting, value = parameter name without alias prefix)
* @param array<string, string> $settingToParameter An array with setting to parameter mappings (key = setting, value = parameter name without alias prefix)
*/
private function configureParameters(ContainerBuilder $container, array $config, array $settingToParameter)
private function configureParameters(ContainerBuilder $container, array $config, array $settingToParameter): void
{
foreach ($settingToParameter as $setting => $parameter) {
$container->setParameter('cmf_routing.'.$parameter, $config[$setting]);
}
}

/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string
{
return __DIR__.'/../Resources/config/schema';
}

public function getNamespace()
public function getNamespace(): string
{
return 'http://cmf.symfony.com/schema/dic/routing';
}
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/RedirectableMatcherPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
/**
* If enabled, change the nested matcher implementation to the redirectable matcher.
*/
class RedirectableMatcherPass implements CompilerPassInterface
final class RedirectableMatcherPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
// only replace the nested matcher if config tells us to
if (!$container->hasParameter('cmf_routing.redirectable_url_matcher') || false === $container->getParameter('cmf_routing.redirectable_url_matcher')) {
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/SetRouterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
/**
* Changes the Router implementation.
*/
class SetRouterPass implements CompilerPassInterface
final class SetRouterPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
// only replace the default router by overwriting the 'router' alias if config tells us to
if ($container->hasParameter('cmf_routing.replace_symfony_router') && true === $container->getParameter('cmf_routing.replace_symfony_router')) {
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/ValidationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
/**
* Register validation files if their storage is activated.
*/
class ValidationPass implements CompilerPassInterface
final class ValidationPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if ($container->hasParameter('cmf_routing.backend_type_phpcr') && $container->hasDefinition('validator.builder')) {
$container
Expand Down
20 changes: 5 additions & 15 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,20 @@
*
* @author David Buchmann
*/
class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
/**
* Returns the config tree builder.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('cmf_routing');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$root = $treeBuilder->root('cmf_routing');
}
$root = $treeBuilder->getRootNode();

$this->addChainSection($root);
$this->addDynamicSection($root);

return $treeBuilder;
}

private function addChainSection(ArrayNodeDefinition $root)
private function addChainSection(ArrayNodeDefinition $root): void
{
$root
->children()
Expand All @@ -67,7 +57,7 @@ private function addChainSection(ArrayNodeDefinition $root)
;
}

private function addDynamicSection(ArrayNodeDefinition $root)
private function addDynamicSection(ArrayNodeDefinition $root): void
{
$root
->children()
Expand Down
Loading

0 comments on commit 99101f3

Please sign in to comment.