-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add a new Link component #22273
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
Add a new Link component #22273
Conversation
A better name would probably be "Link Component": https://html.spec.whatwg.org/multipage/semantics.html#links |
Added to the 3.3 milestone because this is only about new features already planned for 3.3 |
Not changing the service definition for |
I've renamed the component Link, added support for generic "Link" headers (preloading and resource hints) and introduced new Twig helpers for This new component now support all types of prefetching and is smart enough to manage generic Link headers (for instance, when it will be available https://github.com/api-platform/core/blob/master/src/Hydra/EventListener/AddLinkHeaderListener.php in API Platform may be removed). @stof comment also addressed. |
c0d3a31
to
e47b413
Compare
@@ -39,6 +39,7 @@ | ||
"symfony/console": "~3.3", | ||
"symfony/css-selector": "~2.8|~3.0", | ||
"symfony/dom-crawler": "~2.8|~3.0", | ||
"symfony/links": "~3.3", |
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.
symfony/link
"symfony/http-kernel": "^2.8 || ^3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { "Symfony\\Component\\Preload\\": "" }, |
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.
Symfony\Component\Link\
d0f40a0
to
ff6b790
Compare
Tests should be green after the merge. |
{ | ||
protected function setUp() | ||
{ | ||
if (!class_exists(LinkManager::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.
I would add symfony/link
to the require-dev
section of the composer.json
file instead.
@@ -208,6 +208,10 @@ public function load(array $configs, ContainerBuilder $container) | ||
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader); | ||
} | ||
|
||
if ($this->isConfigEnabled($container, $config['links'])) { |
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.
I think we should test for the Link component to be present first and throw a meaningful exception if not present.
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.
Link should not be a mandatory component. You mean throwing if enabled is set to true
but the component not installed?
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.
yes, we did that recently for other optional dependencies too
|
||
<service id="links.link_manager" class="Symfony\Component\Link\LinkManager" public="false" /> | ||
|
||
<service id="links.link_listener" class="Symfony\Component\Link\EventListener\LinkListener"> |
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 be private?
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.
IIRC, event listeners can't
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.
since #20953 they can
@@ -62,6 +63,10 @@ | ||
<xsd:attribute name="path" type="xsd:string" /> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="links"> | ||
<xsd:attribute name="enabled" type="xsd:boolean" /> |
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 make sense to set this to xsd:string
to allow using a DI parameter in the config?
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.
All others similar parameters use xsd:boolean
. If we want to change this behavior, we should do it in another PR for all enabled
parameters.
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 something to "fix" by adding a new "boolean" type, borrowed from the XSD of the DI XmlFileLoader? (in another PR)
@@ -238,6 +238,9 @@ protected static function getBundleDefaultConfig() | ||
'log' => true, | ||
'throw' => true, | ||
), | ||
'links' => array( | ||
'enabled' => !class_exists(FullStack::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.
What about adding the component as a dev dependency to the composer.json
file instead?
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.
It is, it's not related.
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.
sorry, I misread the code
* | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
*/ | ||
class LinkManager implements LinkManagerInterface |
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.
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.
👍 on my side but I think it's against our CS (maybe @final
). ping @nicolas-grekas
src/Symfony/Component/Link/README.md
Outdated
Link Component | ||
============== | ||
|
||
The Link component manages link between resources. It is particularly useful advise clients |
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.
[...] manages links between [...]
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.
[...] useful to advise [...]
"symfony/http-kernel": "" | ||
}, | ||
"require-dev": { | ||
"symfony/http-kernel": "^2.8 || ^3.0" |
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 EventDispatcher and HttpFoundation components are used by the LinkListenerTest
class too.
Please, call this "HttpLink". |
@teohhanhui it's not really related to HTTP (only the listener is). It can also handle HTML links and in general links in any other protocol. |
@xabbuh's comments fixed |
I believe it's defined in RFC 5988 - Web Linking. Perhaps it can be named WebLink or ResourceLink. |
I like |
|
24e7b13
to
fd2dd50
Compare
use Symfony\Component\Serializer\Serializer; | ||
use Symfony\Component\Translation\Translator; | ||
use Symfony\Component\Validator\Validation; | ||
use Symfony\Component\WebLink\WebLinkManagerInterface; |
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 interface does not exist anymore
d8fe813
to
73797d4
Compare
73797d4
to
209901b
Compare
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.
👍
Some tests are broken on Travis. |
@fabpot IIUC, only because the component is not available on Packagist yet (DEPS=low)? |
Thank you @dunglas. |
Great job! I almost missed it... is there a post somewhere? I couldn't find any. Or is it reverted? |
There is New in Symfony 3.3: WebLink component. |
@jdreesen Ah, thank you. I probably looked for "Link*". |
This PR was merged into the 3.4 branch. Discussion ---------- Add docs for the WebLink component The WebLink component is available since Symfony 3.3, but I never took the time to add the docs (however, a blog post explaining how to use it was available). This documentation is based on https://dunglas.fr/2017/10/symfony-4-http2-push-and-preloading/. If necessary, I can grant any copyright regarding this post to the Symfony project. symfony/symfony#21478 symfony/symfony#22273 Closes #7515. Commits ------- 91ee3bc Fix RST ea7b3da @nicolas-grekas' review 38fda88 fix build e12e776 RST 088690f Fix link e3d4036 RST 178821e refactor 9f4ae9b fix typo 6beb4eb Add docs for the WebLink component
This a proposal to extract HTTP preloading features introduced in #21478 in their own component.
There are some good reasons to do it:
Asset
Twig extension)This component would also better fit in HttpFoundation than in Asset. But there is no dependency between it and HttpFoundation and it can easily be used with PSR-7 too, so IMO it better belongs in a standalone component.
Btw, ~~~I plan to add support for prefetching to this component. Except a PR soon.~~~ Prefetching and prerendering support added in this PR.
ping @symfony/deciders