Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FWBundle] Add a new method AbstractController::addLink()#28875
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ro0NL commentedOct 15, 2018
what about |
dunglas commentedOct 15, 2018
@ro0NL very good idea. Updated accordingly. |
43394b6 to4924de1Compare| */ | ||
| publicfunctionaddLink(Link$link) | ||
| { | ||
| if (!class_exists(HttpHeaderSerializer::class)) { |
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.
actually just havingfig/link-util is enough for this method to work, so we can test forGenericLinkProvider.. but i like the suggestion forsymfony/web-link in the message :))
Uh oh!
There was an error while loading.Please reload this page.
ro0NL left a comment
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.
does it need aRequest::getLinks() as well, for completeness (at least keeps the_links attribute an implementation detail) and enables a return type :)
fabpot commentedOct 16, 2018
Having the method on |
dunglas commentedOct 16, 2018
@fabpot I thought the same thing, but the current, temporary, list of values must be stored in request attributes. Then the header is added to the response by the listener. |
ro0NL commentedOct 16, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
maybe it should be dealt by a new service, provided by WebLink component. Something like |
javiereguiluz commentedOct 16, 2018
My preference would be the original proposal from Kévin: |
dunglas commentedOct 16, 2018
And they can always use (Actually I prefer having it in |
ro0NL commentedOct 16, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
i see why we might favor Speaking about DX, right now standalone it's over 👍 for AbstractController, that means working with attribtues remains the "true" API. We can live with that i guess. |
dunglas commentedOct 21, 2018
Last commit reverted and typo fixed. |
src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| * | ||
| * @final | ||
| */ | ||
| protectedfunctionaddLink(Request$request,Link$link) |
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.
would it make sense to change the signature toRequest $request, string $rel, string $href?
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.
To support all features ofLink it should beaddLink(Request $request, array|string $rels, string $link, array $attributes = []) then.
I'm not sure it is worth it. WDYT?
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.
OK, I missed EvolvableLinkTrait, let's keep as is.
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.
Shouldn't it bePsr\Link\LinkInterface?
| 4.2.0 | ||
| ----- | ||
| * Added a`Symfony\Bundle\FrameworkBundle\Controller\AbstractController::addLink()` method to add Link headers to the current response |
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.
AbstractController, same-package code excludes the NS usually
fabpot commentedOct 24, 2018
Thank you@dunglas. |
…k() (dunglas)This PR was squashed before being merged into the 4.2-dev branch (closes#28875).Discussion----------[FWBundle] Add a new method AbstractController::addLink()| Q | A| ------------- | ---| Branch? | master| Bug fix? |no| New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | yes <!-- please add some, will be required by reviewers -->| Fixed tickets | n/a <!-- #-prefixed issue number(s), if any -->| License | MIT| Doc PR | todoThis provides a convenient method to add `Link` headers to the current `Response` directly from the `Request` object.It improves the developer experience and the discoverability of [the WebLink component](symfony/symfony-docs#10309).Usage:```phpnamespace App\Controller;use Fig\Link\Link;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;class MyAction extends AbstractController{ public function __invoke(Request $request): Response { $this->addLink($request, new Link('mercure', 'https://demo.mercure.rocks')); return $this->json(['foo' => 'bar']); }}```Commits-------4d20c39 [FWBundle] Add a new method AbstractController::addLink()
Uh oh!
There was an error while loading.Please reload this page.
This provides a convenient method to add
Linkheaders to the currentResponsedirectly from theRequestobject.It improves the developer experience and the discoverability ofthe WebLink component.
Usage: