Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[PropertyInfo] AddPropertyAttributesExtractor
#57601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedJun 29, 2024
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
9562951
toe0199a8
Comparesrc/Symfony/Component/PropertyInfo/PropertyAttributesExtractorInterface.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyAttribute.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e55b199
to20631f8
Compare20631f8
toceafe5d
ComparePropertyAttributesExtractor
@OskarStark Hi, thanks for the review! Since this is my first PR, can you point out any potential issues that might be preventing feedback, or is it just the high number of PRs for the maintainers? The tests are failing, but it seems unrelated to my changes. |
* - name: The fully-qualified class name of the attribute | ||
* - arguments: An associative array of attribute arguments if present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would use@param
annotation to describe these parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Since the@param
annotation is used for describing method's arguments, are you suggesting using it for thestring $class, string $property, array $context = []
arguments?
* - name: The fully-qualified class name of the attribute | ||
* - arguments: An associative array of attribute arguments if present | ||
* | ||
* @return array<int, array{name: string, arguments: array<array-key, mixed>}>|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
* @returnarray<int,array{name: string, arguments: array<array-key, mixed>}>|null | |
* @returnlist<array{name: string, arguments: array<array-key, mixed>}>|null |
public function getAttributes($class, $property, array $context = []): ?array | ||
{ | ||
$this->assertIsString($class); | ||
$this->assertIsString($property); | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
publicfunction getAttributes($class,$property,array$context = []): ?array | |
{ | |
$this->assertIsString($class); | |
$this->assertIsString($property); | |
returnnull; | |
} | |
publicfunction getAttributes(string$class,string$property,array$context = []): ?array | |
{ | |
returnnull; | |
} |
I think that is enough, thanks to modern PHP typing system.
@@ -45,6 +47,7 @@ | |||
->tag('property_info.type_extractor', ['priority' => -1002]) | |||
->tag('property_info.access_extractor', ['priority' => -1000]) | |||
->tag('property_info.initializable_extractor', ['priority' => -1000]) | |||
->tag('property_info.attributes_extractor', ['priority' => -1000]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
->tag('property_info.attributes_extractor', ['priority' => -1000]) | |
->tag('property_info.attribute_extractor', ['priority' => -1000]) |
To be consistent? (same inFrameworkExtension
andPropertyInfoPass
)
/** | ||
* @author Andrew Alyamovsky <andrew.alyamovsky@gmail.com> | ||
*/ | ||
interface PropertyAttributesExtractorInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
interfacePropertyAttributesExtractorInterface | |
interfacePropertyAttributeExtractorInterface |
To be consistent with other extractors. For example, even ifgetTypes
is plural,PropertyTypeExtractorInterface
is singular.
foreach ($reflProperty->getAttributes() as $attribute) { | ||
$attributes[] = [ | ||
'name' => $attribute->getName(), | ||
'arguments' => $attribute->getArguments(), | ||
]; | ||
} | ||
return $attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
foreach ($reflProperty->getAttributes()as$attribute) { | |
$attributes[] = [ | |
'name' =>$attribute->getName(), | |
'arguments' =>$attribute->getArguments(), | |
]; | |
} | |
return$attributes; | |
return$reflProperty->getAttributes(); |
Why not returning attributes themselves? So that we can have all the attribute data (repeated, etc) and use thenewInstance
method.
If it was because you want to decouplegetAttributes
from\ReflectionXXX
, I think that we shouldn't try to decouple as it's part of the PHP language itself.
While the PropertyInfo component works great for extracting property annotations, in its current state it does not support extracting attributes. This means there's a necessity to use
ReflectionClass
on the target class to extract attributes, and that it's not possible to leveragePropertyInfoCacheExtractor
to cache the results.This PR adds a separate
PropertyAttributesExtractorInterface
interface that does just that, which is implemented by the existingReflectionExtractor
class.