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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ixarlie
Copy link

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

ixarlie commented Jan 31, 2023

@W0rma branch was updated with master. Thanks

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

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

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
5 participants