Bug #46008
Reflection should resolve relative namespaces
Status: | Resolved | Start date: | 2013-03-04 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Sebastian Kurfuerst | % Done: | 100% |
|
Category: | Reflection | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No | Affected Flow version: | Git master |
Description
Annotations (e.g. @var
) with relative class names are not resolved correctly under the namespace of the given class.
To have a correct handling of namespaces in PHP we should support the usage of relative class names in these places.
1namespace MyVendor\MyPackage\Domain\Model;
2
3class Foo {
4
5 /**
6 * @var Bar
7 */
8 protected $bar;
9
10}
1namespace MyVendor\MyPackage\Domain\Model;
2
3class Bar {
4
5}
Since this is a problem for some people (e.g. also PhpStorm uses relative class names when auto-completing) I consider this a bug we should solve in the framework.
Related issues
Associated revisions
[FEATURE] Resolve relative namespaces and use statements in @var & @param annotations
Reflection should expand shortened or namespaced @var & @param annotations
to their fully qualified class name.
This has a direct benefit in the following areas (all covered by tests):
- Reflection returns the fully qualified class name for @var and @param annotations
- Reflection returns the fully qualified property types for Domain Models
inside the class schema - Dependency Injection using @Flow\Inject works with shortened class names
- Property mapping works for shortened class names in type hint & @param annotation
Resolves: #46008
Releases: master
Change-Id: I28fd7c7993ea79714cc62032fcc332ac8cf9d4bc
[BUGFIX] Fix resolving of relative namespaces in parent classes
With I28fd7c7993ea79714cc62032fcc332ac8cf9d4bc the ReflectionService
resolves relative and aliased namespaces automatically.
This doesn't work for inherited classes though because the code only
considered the current class, not it's parents.
With this change code like this will work::
use TYPO3\Flow\Security\Context;
class SomeParentClass {
/**
- @var Context
- @Flow\Inject
*/
protected $securityContext;
// ...
}
class SomeChildClass extends SomeParentClass {
}
Change-Id: Ie4b931a03a94d506890e996b9d8bae7d0d1a2e14
Fixes: #50909
Related: #46008
Releases: master
[BUGFIX] Fix resolving of imported collection types
This change extends the ReflectionService so that it is able to
expand our custom notation for collection types::
CollectionType<ElementType>
Background:
In the Coding Guidelines we encourage developers to import namespaces
in order to increase readability.
With #46008 the ReflectionService is able to resolve relative and
imported namespace (with #50909 this also works for abstract classes).
But this does not work for our custom notation of Collection types yet.
With this fix relative and imported class names are supported also for
our custom notation of collection types and the above would be
expanded to::
\CollectionTypeNamespace\CollectionType<\ElementTypeNamespace\ElementType>
Change-Id: I4e228d6846776d2500d7e8aec2bc88df170bc9de
Fixes: #57034
Related: #46008
Related: #50909
Releases: master, 2.2, 2.1
[BUGFIX] Fix resolving of imported collection types
This change extends the ReflectionService so that it is able to
expand our custom notation for collection types::
CollectionType<ElementType>
Background:
In the Coding Guidelines we encourage developers to import namespaces
in order to increase readability.
With #46008 the ReflectionService is able to resolve relative and
imported namespace (with #50909 this also works for abstract classes).
But this does not work for our custom notation of Collection types yet.
With this fix relative and imported class names are supported also for
our custom notation of collection types and the above would be
expanded to::
\CollectionTypeNamespace\CollectionType<\ElementTypeNamespace\ElementType>
Change-Id: I4e228d6846776d2500d7e8aec2bc88df170bc9de
Fixes: #57034
Related: #46008
Related: #50909
Releases: master, 2.2, 2.1
[BUGFIX] Fix resolving of imported collection types
This change extends the ReflectionService so that it is able to
expand our custom notation for collection types::
CollectionType<ElementType>
Background:
In the Coding Guidelines we encourage developers to import namespaces
in order to increase readability.
With #46008 the ReflectionService is able to resolve relative and
imported namespace (with #50909 this also works for abstract classes).
But this does not work for our custom notation of Collection types yet.
With this fix relative and imported class names are supported also for
our custom notation of collection types and the above would be
expanded to::
\CollectionTypeNamespace\CollectionType<\ElementTypeNamespace\ElementType>
Change-Id: I4e228d6846776d2500d7e8aec2bc88df170bc9de
Fixes: #57034
Related: #46008
Related: #50909
Releases: master, 2.2, 2.1
History
#1 Updated by Bastian Waidelich over 2 years ago
Probably we should also consider use statements:
1namespace MyVendor\MyPackage\Domain\Model; 2 3use MyVendor\MyPackage\Bar as Baz; 4 5class Foo { 6 7 /** 8 * @var Baz 9 */ 10 protected $baz; 11}
but it seems PHP itself is buggy there https://bugs.php.net/bug.php?id=63665
#2 Updated by Bastian Waidelich over 2 years ago
Bastian Waidelich wrote:
but it seems PHP itself is buggy there https://bugs.php.net/bug.php?id=63665
This bug report seems is about something different it seems. This works as expected:
1namespace Foo\Bar;
2
3class Baz {
4
5}
6
7namespace MyPackage;
8use Foo\Bar\Baz as Quux;
9
10class Test {
11
12 /**
13 * @param Quux $param
14 * @return void
15 */
16 public function test(Quux $param) {
17 }
18}
19
20$reflectionMethod = new \ReflectionMethod('MyPackage\Test', 'test');
21echo current($reflectionMethod->getParameters())->getClass();
Result:
Class [ class Foo\Bar\Baz ] { @@ test.php 4-6 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } }
#3 Updated by Sebastian Kurfuerst over 2 years ago
- Status changed from New to Accepted
- Assigned To set to Sebastian Kurfuerst
I have a patch for this in the works; almost ready.
#4 Updated by Bastian Waidelich over 2 years ago
Sebastian Kurfuerst wrote:
I have a patch for this in the works; almost ready.
Great! Looking forward to this one
#5 Updated by Gerrit Code Review over 2 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158
#6 Updated by Gerrit Code Review about 2 years ago
Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158
#7 Updated by Gerrit Code Review about 2 years ago
Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158
#8 Updated by Gerrit Code Review about 2 years ago
Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20158
#9 Updated by Sebastian Kurfuerst about 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset bc8f7164dea7331823b6170aa76833ffdc6c9658.