Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[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

Open
alyamovsky wants to merge8 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromalyamovsky:property-info-attributes

Conversation

alyamovsky
Copy link

QA
Branch?7.2
Bug fix?no
New feature?yes
Deprecations?no
Issuesno
LicenseMIT

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 useReflectionClass on the target class to extract attributes, and that it's not possible to leveragePropertyInfoCacheExtractor to cache the results.

This PR adds a separatePropertyAttributesExtractorInterface interface that does just that, which is implemented by the existingReflectionExtractor class.

OskarStark reacted with eyes emoji
@carsonbot
Copy link

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:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@alyamovskyalyamovskyforce-pushed theproperty-info-attributes branch from9562951 toe0199a8CompareJune 29, 2024 17:06
@alyamovskyalyamovskyforce-pushed theproperty-info-attributes branch frome55b199 to20631f8CompareJuly 1, 2024 20:50
@alyamovskyalyamovskyforce-pushed theproperty-info-attributes branch from20631f8 toceafe5dCompareJuly 12, 2024 23:32
@OskarStarkOskarStark changed the title[PropertyInfo] Add property attributes extractor[PropertyInfo] AddPropertyAttributesExtractorJul 13, 2024
@alyamovsky
Copy link
Author

@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.

Comment on lines +23 to +24
* - name: The fully-qualified class name of the attribute
* - arguments: An associative array of attribute arguments if present
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
* @returnarray<int,array{name: string, arguments: array<array-key, mixed>}>|null
* @returnlist<array{name: string, arguments: array<array-key, mixed>}>|null

Comment on lines +61 to +67
public function getAttributes($class, $property, array $context = []): ?array
{
$this->assertIsString($class);
$this->assertIsString($property);

return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
->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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
interfacePropertyAttributesExtractorInterface
interfacePropertyAttributeExtractorInterface

To be consistent with other extractors. For example, even ifgetTypes is plural,PropertyTypeExtractorInterface is singular.

Comment on lines +525 to +532
foreach ($reflProperty->getAttributes() as $attribute) {
$attributes[] = [
'name' => $attribute->getName(),
'arguments' => $attribute->getArguments(),
];
}

return $attributes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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.

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mtarldmtarldmtarld left review comments

@OskarStarkOskarStarkOskarStark approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

5 participants
@alyamovsky@carsonbot@OskarStark@mtarld@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp