Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 325 php8 attributes #326

Merged
merged 15 commits into from
Oct 14, 2024
Merged

Conversation

ixarlie
Copy link
Contributor

@ixarlie ixarlie commented Jan 10, 2023

resolves #325

To be precise the php version must be 8.1 or greater to support nested attributes.

@W0rma
Copy link
Contributor

W0rma commented Jan 31, 2023

@ixarlie FYI CI has been fixed in master.

@ixarlie
Copy link
Contributor Author

ixarlie commented Jan 31, 2023

@W0rma branch was updated with master. Thanks

@ixarlie ixarlie force-pushed the issue-325-php8-attributes branch from 1dd390b to ac5771e Compare January 31, 2023 22:36
@goetas goetas closed this Jun 9, 2023
@goetas goetas reopened this Jun 9, 2023
@fabianoroberto
Copy link

Is anyone handling this PR?

* @param string|array $content
* @param Exclusion|null $exclusion
*/
public function __construct(array $values = [], $content = null, ?string $type = null, ?string $xmlElementName = null, $exclusion = 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
public function __construct(array $values = [], $content = null, ?string $type = null, ?string $xmlElementName = null, $exclusion = null)
public function __construct(array $values = [], $content = null, ?string $type = null, ?string $xmlElementName = null, ?Exclusion $exclusion = null)

/**
* @Annotation
* @Target("ANNOTATION")
*/
#[\Attribute(0)]
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of passing "0"?

(the same question applies to all usages of #[\Attribute(0)] in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to resolve an issue that may not be an issue. I intended not to allow the attribute to be used on any of the existing targets. It seems the 0 produces this behaviour.

Attribute::TARGET_CLASS
Attribute::TARGET_FUNCTION
Attribute::TARGET_METHOD
Attribute::TARGET_PROPERTY
Attribute::TARGET_CLASS_CONSTANT
Attribute::TARGET_PARAMETER
Attribute::TARGET_ALL

For example, Embedded can be used only as a nested attribute.

I can remove the 0 for Embedded, Exclusion and Route as I am not sure if it could be a problem for certain configurations.

/**
* @Required
* @var mixed
*/
#[Required]
Copy link
Contributor

Choose a reason for hiding this comment

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

The @Required annotation does not reference a symfony class but Doctrine\Common\Annotations\Annotation\Required.

I suggest to remove #[Required] everywhere in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was wrong to use the Symfony Required class which is about the service auto-wiring. So, it has nothing to do with the Doctrine annotation purpose.

I will remove #[Required]

*/
private $reader;

public function __construct(Reader $reader)
Copy link
Contributor

Choose a reason for hiding this comment

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

From the class name I would expect that this class is only about reading attributes.

An approach similar to schmittjoh/serializer#1469 would be nice.
This way the annotation reader would become optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I didn't want to do something very different from how JMS was doing it back then. That PR was created after I created mine.

But I totally agree with that decoupling approach.

I believe it answers my concern in this comment #326 (comment)

@W0rma
Copy link
Contributor

W0rma commented Jan 9, 2024

@ixarlie Are you still working on this PR or should someone else take it over?

@ixarlie
Copy link
Contributor Author

ixarlie commented Jan 11, 2024

@ixarlie Are you still working on this PR or should someone else take it over?

@W0rma Hi, sorry for the late response. Yes, I can still work on it.

I worked on this some time ago, my concern is whether the approach I've copied from JMS is still valid for this or whether there are better ways to accomplish it.

In any case, let me go over your comments.

Thanks

@ixarlie ixarlie force-pushed the issue-325-php8-attributes branch from 9d3d3d6 to 312caef Compare January 12, 2024 00:03
@W0rma
Copy link
Contributor

W0rma commented Jan 13, 2024

@ixarlie Thank you for updating this PR!

The code LGTM. However, I don't have the possibility to test the changes since I don't use the annotations in my project.

@goetas Any thoughts about the implementation in this PR?

@goetas
Copy link
Collaborator

goetas commented Jan 13, 2024

I will look at it mid February, sorry busy times 😞😢

@jeandonaldroselin
Copy link

Hello,
Is anyone handling this PR?

@jbcr
Copy link

jbcr commented Jun 12, 2024

This PR can also move the doctrine/annotation in suggested requirement to enable some project using it to remove the doctrine/annotation dependencies?

@goetas goetas closed this Oct 14, 2024
@goetas goetas reopened this Oct 14, 2024
@goetas goetas merged commit 95427a4 into willdurand:master Oct 14, 2024
43 checks passed
@ixarlie ixarlie deleted the issue-325-php8-attributes branch October 16, 2024 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

php8 attributes
6 participants