bug #41014 [Routing] allow extending Route attribute (robmro27)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Routing] allow extending Route attribute

| Q             | A
| ------------- | ---
| Branch?       | 5.x <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       |  <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | <!-- required for new features -->

There is probably missed `\ReflectionAttribute::IS_INSTANCEOF` parameter and because of that Route attribute class could not be extended. This could be used by some popular bundles like `FOSRestBundle` for example. Right
now it's not possible to add attributes support there like it was before (extending Route Annotation).

Commits
-------

d733b78f88 [Routing] allow extending Route attribute
This commit is contained in:
Fabien Potencier 2021-05-01 16:20:47 +02:00
commit 4cc0ab3e99

View File

@ -280,7 +280,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
$globals = $this->resetGlobals();
$annot = null;
if (\PHP_VERSION_ID >= 80000 && ($attribute = $class->getAttributes($this->routeAnnotationClass)[0] ?? null)) {
if (\PHP_VERSION_ID >= 80000 && ($attribute = $class->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null)) {
$annot = $attribute->newInstance();
}
if (!$annot && $this->reader) {
@ -372,7 +372,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
private function getAnnotations(object $reflection): iterable
{
if (\PHP_VERSION_ID >= 80000) {
foreach ($reflection->getAttributes($this->routeAnnotationClass) as $attribute) {
foreach ($reflection->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
yield $attribute->newInstance();
}
}