-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
Better HTTP headers #2039
Better HTTP headers #2039
Conversation
jewome62
commented
Jun 25, 2018
•
edited
Loading
edited
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | yes, i add one |
Tests pass? | no, but i work on this |
Fixed tickets | #1912 |
License | MIT |
Doc PR | none |
src/EventListener/WriteListener.php
Outdated
|
||
public function __construct(DataPersisterInterface $dataPersister) | ||
public function __construct(DataPersisterInterface $dataPersister, IriConverterInterface $iriConverter) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second argument must be made optional. 😄
But we can trigger a deprecation error if it's not provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha sorry yeah I should've say what you said in addition 😆
'X-Frame-Options' => 'deny', | ||
]; | ||
|
||
if($request->isMethod('POST') || $request->isMethod('PUT')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be the same for PATCH
, I think...
src/EventListener/WriteListener.php
Outdated
|
||
public function __construct(DataPersisterInterface $dataPersister) | ||
public function __construct(DataPersisterInterface $dataPersister, IriConverterInterface $iriConverter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second argument must be made optional. 😄
But we can trigger a deprecation error if it's not provided.
src/EventListener/WriteListener.php
Outdated
@@ -57,6 +60,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event) | |||
} | |||
|
|||
$event->setControllerResult($persistResult ?? $controllerResult); | |||
$request->attributes->set('_iri_item', $this->iriConverter->getIriFromItem($controllerResult)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe _api_write_item_iri
?
@@ -25,10 +26,12 @@ | |||
class WriteListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we could mark this class as final
? It was never designed to be extended in the first place...
(Strictly speaking, it'd be a BC break... But I highly doubt it'd bother anyone. I don't remember if we've done something like this before. Do we just add the @final
in PHPDoc?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or @internal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add @final
in the PHPDoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2046
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this to #2046 then. 😄
28621b0
to
5c8abe3
Compare
@teohhanhui See: #2043 |
'X-Frame-Options' => 'deny', | ||
]; | ||
|
||
if ($request->isMethod('POST') || $request->isMethod('PUT') || $request->isMethod('PATCH')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use \in_array
here.
@@ -25,10 +26,12 @@ | |||
class WriteListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add @final
in the PHPDoc.
The error messages need to be rephrased. I'll give some suggestions, if somebody doesn't get it done before I do. |
$headers['Location'] = $request->attributes->get('_api_write_item_iri'); | ||
} | ||
} else { | ||
@trigger_error(sprintf('No request attribute from `_api_write_item_iri` key is deprecated since API Platform 2.3 and will not be supported in API Platform 3, an string should always be returned. see deprecated into %s constructor for more details.', WriteListener::class), E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should have this deprecation error here, but:
Not setting the
_api_write_item_iri
request attribute is deprecated since API Platform 2.3 and will not be supported in API Platform 3. See %s for the default implementation.
@teohhanhui I make the fix. Anyway, @dunglas said me that we are trying to reduce the dependencies in the Platform API classes, so normally I will remove the deprecated ones to make sure that it remains optional definitively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash the commits? 😄
@@ -25,10 +26,12 @@ | |||
class WriteListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this to #2046 then. 😄
bd333a9
to
d8a707d
Compare
I have rebase from master |
d8a707d
to
592891e
Compare
592891e
to
d361494
Compare
src/EventListener/WriteListener.php
Outdated
use ApiPlatform\Core\DataPersister\DataPersisterInterface; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; | ||
|
||
/** | ||
* Bridges persistense and the API system. | ||
* | ||
* @final |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed.
d361494
to
7507d90
Compare
66898c9
to
7f046fd
Compare
@dunglas may you merge this please? I rebased it. |
7f046fd
to
cb26a49
Compare
Thanks @jewome62! 🎉 |