Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Add PHP 8.0 attributes support #707

Merged
merged 1 commit into from
Feb 16, 2021
Merged

Conversation

Yoann-TYT
Copy link
Contributor

@Yoann-TYT Yoann-TYT commented Dec 8, 2020

Add PHP 8.0 attributes support

Using PHP attributes if we start a new project on PHP 8.0

Instead of using classic doctrine annotations

    /**
     * @Cache(public=true, maxage="0", smaxage="1 month")
     * @IsGranted("ROLE_ADMIN")
     */
    public function foo() { }

We should use attributes PHP 8.0

    #[Cache(public: true, maxage: '0', smaxage: '1 month')]
    #[IsGranted('ROLE_ADMIN')]
    public function foo() { }

Note for Etag attribute

In the documentation, we use Etag ( not etag or ETag used in the unit tests ). So, to simplify the code, I suggest to fix the unit test. What do you think about that ?

Thank you for your reading :)

@Yoann-TYT Yoann-TYT marked this pull request as ready for review December 8, 2020 07:11
composer.json Outdated Show resolved Hide resolved
src/Configuration/Cache.php Outdated Show resolved Hide resolved
src/EventListener/ControllerListener.php Outdated Show resolved Hide resolved
@pkly
Copy link

pkly commented Dec 8, 2020

Seems good to me

@fabpot
Copy link
Member

fabpot commented Jan 13, 2021

@derrabus Do you have time to review this PR?

Copy link
Contributor

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Thank you for working on this topic! I have added a few comments.

If you can, please add more tests for the named argument constructor usage of the annotation classes. Those changes don't seem to be covered well by the current tests.

src/EventListener/ControllerListener.php Outdated Show resolved Hide resolved
src/EventListener/ControllerListener.php Outdated Show resolved Hide resolved
src/EventListener/ControllerListener.php Outdated Show resolved Hide resolved
src/Configuration/Cache.php Outdated Show resolved Hide resolved
src/Configuration/Cache.php Outdated Show resolved Hide resolved
$mustRevalidate = false,
$vary = [],
$lastModified = null,
$Etag = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

The capital E looks odd.

Copy link
Contributor Author

@Yoann-TYT Yoann-TYT Jan 15, 2021

Choose a reason for hiding this comment

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

I'm agree with you but i'm annoyed because on the documentation, we suggest to use "Etag" and not "etag" for the annotation Cache.
So, I can transform Etag to etag, but I have to add a information on the documentation to inform that for attributes, we use etag and not Etag. What do you think about that ?

@Yoann-TYT
Copy link
Contributor Author

Thanks for your review @derrabus, I'll see that

phpunit.xml.dist Outdated Show resolved Hide resolved
@Yoann-TYT
Copy link
Contributor Author

Thank you for working on this topic! I have added a few comments.

If you can, please add more tests for the named argument constructor usage of the annotation classes. Those changes don't seem to be covered well by the current tests.

Yes, I'll add more tests this week-end ;)

src/Configuration/ParamConverter.php Outdated Show resolved Hide resolved
src/Configuration/Security.php Outdated Show resolved Hide resolved
src/Configuration/Template.php Outdated Show resolved Hide resolved
src/Configuration/Cache.php Outdated Show resolved Hide resolved
src/Configuration/Cache.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented Jan 20, 2021

Can you rebase on current master (that should help for the tests)

Copy link
Contributor

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

I think, we're on a good path here, thank you so much for your work.

Please remember adding tests that cover using each of the annotation classes as an attribute. So far, only Chache is really covered and there's only a basic test for ParamConverter.

src/Configuration/Cache.php Outdated Show resolved Hide resolved
tests/EventListener/ControllerListenerTest.php Outdated Show resolved Hide resolved
@nlhommet
Copy link

Hi,
What is blocking? need help finishing this PR?

@Yoann-TYT
Copy link
Contributor Author

Hi @nlhommet !
Thanks, I just need to add more tests. I'll do that this week-end ! :)

@fabpot
Copy link
Member

fabpot commented Feb 16, 2021

Thanks @Yoann-TYT for working on this feature, this is much appreciated.

@fabpot fabpot merged commit 8b23c28 into sensiolabs:master Feb 16, 2021
fabpot added a commit that referenced this pull request Feb 23, 2021
This PR was merged into the 6.1.x-dev branch.

Discussion
----------

Restore undetermined state in Cache configuration

This PR fix a BC break introduced by #707.

Given the following code:
```
    /**
     * @Cache(smaxage="+1min")
     */
    public function fooAction(){}
```

The headers generated by `HttpCacheListener` changed as following:
```diff
- public, s-maxage=60
+ private, s-maxage=60
```

Why? Because previously the Cache's properties were null until the user provide a value. In such state, `isPublic` returns false (although `isPrivate`). And sometimes, null is expected (like the `vary` array => https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/b3596907c3d35bee5a9a1096baaeb7d465a04f30/src/EventListener/HttpCacheListener.php#L135)

The #707 PR introduce 2 changes:
- a value for each property is now forced by the constructor's default value.
- the constructor calls the setter for each property (even if the user did not provide a value for it), some setter (ie. `setPublic`) does not expect a null value and convert null into something.

It looks like, only the Cache configuration is affected. Other Configuration has already a default value defined for each property.

This PR restore the default `null` value for all properties and prevent the constructor to call the setter when the value is null.

Commits
-------

99e749b Restore undetermined state in Cache configuration
*/
public function __construct(
$data = [],
string $message = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a BC break, I opened #733 for more info

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants