Skip to content

Conversation

@albe
Copy link
Member

@albe albe commented Apr 18, 2021

This allows to use all existing Annotations as PHP8 Attributes and makes the ReflectionService pick up attributes like annotations.
Hence all is*AnnotatedWith() and *Annotation() methods will return attribute classes as if they were annotations.

#[Flow\Scope("singleton")]
class MyClass {

    /**
     * @var LoggerInterface
     */
    #[Flow\Inject]
    protected $logger;

Note though, that this means a class that has both annotation and the equal attribute will behave as if all annotations were duplicated.

Also, in case you manually instanciated an Annotation class, you need to adjust to the changed constructor, which no longer takes a named array, but the list of actual properties.
In most cases instead of new Flow\Inject($args) you can probably do new Flow\Inject(...$args) with PHP8 and named parameters.

For Doctrine Annotations - see doctrine/orm#8266 which will be available with 2.9

@albe albe force-pushed the php8-attributes branch from 2cb5eba to abb589b Compare April 18, 2021 12:31
@albe
Copy link
Member Author

albe commented Apr 18, 2021

This is a reduced subset of #2404 that only contains the attributes support without changing any functionality

Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

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

Looks good by reading, I like how the annotation implementations get simpler!

@daniellienert
Copy link
Member

@albe - I also really like it ( as far as I understand it :) - would you take care of the failing psalm tests?

Copy link
Member

@skurfuerst skurfuerst left a comment

Choose a reason for hiding this comment

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

looks good by reading :) Great job! Instanciating annotations manually is a case I have never seen in the wild, so for me that's safe.

@kdambekalns kdambekalns merged commit 10a060b into master Aug 11, 2021
@kdambekalns kdambekalns deleted the php8-attributes branch August 11, 2021 10:53
@albe
Copy link
Member Author

albe commented Aug 11, 2021

Regarding psalm, I guess we need to do a baseline update in master anyway before the release. I can take care on friday if it's not too late

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants