Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6cee255

Browse filesBrowse files
committed
Automatically enable the routing annotation loader
1 parent c82fe60 commit 6cee255
Copy full SHA for 6cee255

File tree

8 files changed

+90
-9
lines changed
Filter options

8 files changed

+90
-9
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@
9898
"symfony/phpunit-bridge": "~3.2",
9999
"symfony/polyfill-apcu": "~1.1",
100100
"symfony/security-acl": "~2.8|~3.0",
101-
"phpdocumentor/reflection-docblock": "^3.0",
102-
"sensio/framework-extra-bundle": "^3.0.2"
101+
"phpdocumentor/reflection-docblock": "^3.0"
103102
},
104103
"conflict": {
105104
"phpdocumentor/reflection-docblock": "<3.0",

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CHANGELOG
4848
`Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass` instead
4949
* Deprecated `ValidateWorkflowsPass`, use
5050
`Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass` instead
51-
* Deprecated `ConstraintValidatorFactory`, use
51+
* Deprecated `ConstraintValidatorFactory`, use
5252
`Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
5353

5454
3.2.0

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1616
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1717
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
18+
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
1819
use Symfony\Component\Cache\Adapter\AdapterInterface;
1920
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2021
use Symfony\Component\Config\FileLocator;
@@ -48,6 +49,8 @@
4849
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
4950
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
5051
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
52+
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
53+
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
5154
use Symfony\Component\Serializer\Encoder\CsvEncoder;
5255
use Symfony\Component\Serializer\Encoder\DecoderInterface;
5356
use Symfony\Component\Serializer\Encoder\EncoderInterface;
@@ -692,6 +695,26 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
692695
$container->findDefinition('router.default')->getClass(),
693696
));
694697
}
698+
699+
if ($this->annotationsConfigEnabled) {
700+
$container->register('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
701+
->addTag('routing.loader', array('priority' => -10))
702+
->addArgument(new Reference('annotation_reader'));
703+
704+
$container->register('routing.loader.directory', AnnotationDirectoryLoader::class)
705+
->addTag('routing.loader', array('priority' => -10))
706+
->setArguments(array(
707+
new Reference('file_locator'),
708+
new Reference('routing.loader.annotation'),
709+
));
710+
711+
$container->register('routing.loader.file', AnnotationFileLoader::class)
712+
->addTag('routing.loader', array('priority' => -10))
713+
->setArguments(array(
714+
new Reference('file_locator'),
715+
new Reference('routing.loader.annotation'),
716+
));
717+
}
695718
}
696719

697720
/**
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Routing;
13+
14+
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
15+
use Symfony\Component\Routing\Route;
16+
17+
/**
18+
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
19+
* that sets the '_controller' default based on the class and method names.
20+
*
21+
* @author Fabien Potencier <fabien@symfony.com>
22+
*/
23+
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
24+
{
25+
/**
26+
* Configures the _controller default parameter of a given Route instance.
27+
*
28+
* @param mixed $annot The annotation class instance
29+
*/
30+
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
31+
{
32+
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
33+
}
34+
35+
/**
36+
* Makes the default route name more sane by removing common keywords.
37+
*
38+
* @return string
39+
*/
40+
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
41+
{
42+
$routeName = parent::getDefaultRouteName($class, $method);
43+
44+
return preg_replace(array(
45+
'/(bundle|controller)_/',
46+
'/action(_\d+)?$/',
47+
'/__/',
48+
), array(
49+
'_',
50+
'\\1',
51+
'_',
52+
), $routeName);
53+
}
54+
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
1313
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
14-
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
1514

1615
return array(
1716
new FrameworkBundle(),
1817
new TestBundle(),
19-
new SensioFrameworkExtraBundle(),
2018
);

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
"symfony/web-link": "~3.3|~4.0",
5858
"doctrine/annotations": "~1.0",
5959
"phpdocumentor/reflection-docblock": "^3.0",
60-
"twig/twig": "~1.26|~2.0",
61-
"sensio/framework-extra-bundle": "^3.0.2"
60+
"twig/twig": "~1.26|~2.0"
6261
},
6362
"conflict": {
6463
"phpdocumentor/reflection-docblock": "<3.0",

‎src/Symfony/Component/Routing/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.4.0
5+
-----
6+
7+
* Added support for prioritized routing loaders.
8+
49
3.3.0
510
-----
611

@@ -19,7 +24,7 @@ CHANGELOG
1924

2025
* Added support for `bool`, `int`, `float`, `string`, `list` and `map` defaults in XML configurations.
2126
* Added support for UTF-8 requirements
22-
27+
2328
2.8.0
2429
-----
2530

‎src/Symfony/Component/Routing/DependencyInjection/RoutingResolverPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/DependencyInjection/RoutingResolverPass.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Reference;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
1718

1819
/**
1920
* Adds tagged routing.loader services to routing.resolver service.
@@ -22,6 +23,8 @@
2223
*/
2324
class RoutingResolverPass implements CompilerPassInterface
2425
{
26+
use PriorityTaggedServiceTrait;
27+
2528
private $resolverServiceId;
2629
private $loaderTag;
2730

@@ -39,7 +42,7 @@ public function process(ContainerBuilder $container)
3942

4043
$definition = $container->getDefinition($this->resolverServiceId);
4144

42-
foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) {
45+
foreach ($this->findAndSortTaggedServices($this->loaderTag, $container) as $id) {
4346
$definition->addMethodCall('addLoader', array(new Reference($id)));
4447
}
4548
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.