Skip to content

Begin Introduction of new 'sunset' API-Resource annotation in order t… #2252

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

Merged
merged 5 commits into from
Oct 23, 2018

Conversation

blanky0230
Copy link
Contributor

@blanky0230 blanky0230 commented Oct 12, 2018

I messed up with rebasing on the old PR :/

I'm sorry if this was kinda spammy. (git rebase is a bit new to me).

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Related to #2245
License MIT
Doc PR api-platform/docs#658

@blanky0230 blanky0230 force-pushed the support_sunset_header branch from 3da47bd to 8664190 Compare October 12, 2018 08:16
Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Almost done!

@blanky0230 blanky0230 force-pushed the support_sunset_header branch from 8664190 to f841a1a Compare October 12, 2018 09:43
Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

👍 on my side when the listener will be marked final. Great addition, thank you very much!

use ApiPlatform\Core\Util\RequestAttributesExtractor;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

class AddSunsetHeaderListener
Copy link
Member

Choose a reason for hiding this comment

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

Can you make it final please? (sorry I forgot about that before)

Copy link
Member

Choose a reason for hiding this comment

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

Double thinking about this, it will be even better to remove this class and move its code in RespondListener.
Sending HTTP headers like this one is the responsibility of the responder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a very good idea. Feels way cleaner :) I moved it to Eventlistener/RespondListener, could you please take a look at the test, I'm not 100% certain I did it right.


declare(strict_types=1);

namespace ApiPlatform\Core\Sunset\EventListener;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering why not directly in Core\Eventlistener and I faill to see where is the listener declared (src/Bridge/Symfony/Bundle/Resources/config/api.xml) ?

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. Should be in core, and of course registered, thank @antograssiot

Copy link
Contributor Author

@blanky0230 blanky0230 Oct 15, 2018

Choose a reason for hiding this comment

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

So i moved it to EventListener\RespondListner::onKernelView(), was that what you had in mind @antograssiot ? Since I do no longer introduce a new Listener I suppose that's fine :)

@blanky0230 blanky0230 force-pushed the support_sunset_header branch from f841a1a to c55efb3 Compare October 15, 2018 18:10
@@ -55,6 +55,11 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
}
}

if ($request->attributes->has('sunset')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you are not using the value from the ApiResource attribute here.
I've opened a PR on your fork to show you what I had in mind/understood, and also added a Behat test.
You can get inspiration from that or use the code as is, I don't mind

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 pulled your pr in :)

Extract the sunset header from attributes
Copy link
Contributor

@antograssiot antograssiot left a comment

Choose a reason for hiding this comment

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

@dunglas you might want to have another look at this PR as the code changed quite significantly since you approved it

Copy link
Member

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Awesome!

@dunglas dunglas merged commit af81579 into api-platform:master Oct 23, 2018
@dunglas
Copy link
Member

dunglas commented Oct 23, 2018

Thanks! Great improvement.
Don't forget the docs PR please :)

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.

4 participants