Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #23044 Automatically enable the routing annotation loader (Gu…
…ilhemN) This PR was merged into the 3.4 branch. Discussion ---------- Automatically enable the routing annotation loader | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | there's probably one but I didn't find it | License | MIT | Doc PR | Thanks to fqcn services, most of the time, we don't need the SensioFrameworkExtraBundle to use `@Route`. So I suggest to automatically enable it when annotations are enabled. This way we could simplify https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/etc/routing.yaml#L5. Note: I added priority support for routing loaders to make sure sensio loaders are executed before ours. Commits ------- c2f796f Automatically enable the routing annotation loader
- Loading branch information
Showing
8 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Routing; | ||
|
||
use Symfony\Component\Routing\Loader\AnnotationClassLoader; | ||
use Symfony\Component\Routing\Route; | ||
|
||
/** | ||
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader | ||
* that sets the '_controller' default based on the class and method names. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class AnnotatedRouteControllerLoader extends AnnotationClassLoader | ||
{ | ||
/** | ||
* Configures the _controller default parameter of a given Route instance. | ||
* | ||
* @param mixed $annot The annotation class instance | ||
*/ | ||
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) | ||
{ | ||
$route->setDefault('_controller', $class->getName().'::'.$method->getName()); | ||
} | ||
|
||
/** | ||
* Makes the default route name more sane by removing common keywords. | ||
* | ||
* @return string | ||
*/ | ||
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method) | ||
{ | ||
return preg_replace(array( | ||
'/(bundle|controller)_/', | ||
'/action(_\d+)?$/', | ||
'/__/', | ||
), array( | ||
'_', | ||
'\\1', | ||
'_', | ||
), parent::getDefaultRouteName($class, $method)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters