Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename to WebLink
  • Loading branch information
dunglas committed Apr 10, 2017
commit 7be2a6c6e5887900ebe415a683ab81ded03e5909
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\Link\LinkManagerInterface;
use Symfony\Component\WebLink\WebLinkManagerInterface;

/**
* Twig extension for the Symfony Preload component.
* Twig extension for the Symfony WebLink component.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class LinkExtension extends \Twig_Extension
class WebLinkExtension extends \Twig_Extension
{
private $linkManager;

public function __construct(LinkManagerInterface $linkManager)
public function __construct(WebLinkManagerInterface $linkManager)
{
$this->linkManager = $linkManager;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public function link($uri, $rel, array $attributes = array())
*/
public function preload($uri, array $attributes = array())
{
return $this->link($uri, 'preload', $attributes);
return $this->link($uri, WebLinkManagerInterface::REL_PRELOAD, $attributes);
}

/**
Expand All @@ -81,7 +81,7 @@ public function preload($uri, array $attributes = array())
*/
public function dnsPrefetch($uri, array $attributes = array())
{
return $this->link($uri, 'dns-prefetch', $attributes);
return $this->link($uri, WebLinkManagerInterface::REL_DNS_PREFETCH, $attributes);
}

/**
Expand All @@ -94,11 +94,11 @@ public function dnsPrefetch($uri, array $attributes = array())
*/
public function preconnect($uri, array $attributes = array())
{
return $this->link($uri, 'preconnect', $attributes);
return $this->link($uri, WebLinkManagerInterface::REL_PRECONNECT, $attributes);
}

/**
* Indicates to the client that it should prefetch this resource .
* Indicates to the client that it should prefetch this resource.
*
* @param string $uri A public path
* @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)")
Expand All @@ -107,7 +107,7 @@ public function preconnect($uri, array $attributes = array())
*/
public function prefetch($uri, array $attributes = array())
{
return $this->link($uri, 'prefetch', $attributes);
return $this->link($uri, WebLinkManagerInterface::REL_PREFETCH, $attributes);
}

/**
Expand All @@ -120,7 +120,7 @@ public function prefetch($uri, array $attributes = array())
*/
public function prerender($uri, array $attributes = array())
{
return $this->link($uri, 'prerender', $attributes);
return $this->link($uri, WebLinkManagerInterface::REL_PRERENDER, $attributes);
}

/**
Expand All @@ -130,6 +130,6 @@ public function prerender($uri, array $attributes = array())
*/
public function getName()
{
return 'link';
return 'web_link';
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this method.

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,70 @@
namespace Symfony\Bridge\Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\LinkExtension;
use Symfony\Component\Link\LinkManager;
use Symfony\Bridge\Twig\Extension\WebLinkExtension;
use Symfony\Component\WebLink\WebLinkManager;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class LinkExtensionTest extends TestCase
class WebLinkExtensionTest extends TestCase
{
public function testLink()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->link('/foo.css', 'preload', array('as' => 'style', 'nopush' => true)));
$this->assertEquals('</foo.css>; rel=preload; as=style; nopush', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=preload; as=style; nopush', $linkManager->buildHeaderValue());
}

public function testPreload()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->preload('/foo.css', array('as' => 'style', 'crossorigin' => true)));
$this->assertEquals('</foo.css>; rel=preload; as=style; crossorigin', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=preload; as=style; crossorigin', $linkManager->buildHeaderValue());
}

public function testDnsPrefetch()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->dnsPrefetch('/foo.css', array('as' => 'style', 'crossorigin' => true)));
$this->assertEquals('</foo.css>; rel=dns-prefetch; as=style; crossorigin', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=dns-prefetch; as=style; crossorigin', $linkManager->buildHeaderValue());
}

public function testPreconnect()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->preconnect('/foo.css', array('as' => 'style', 'crossorigin' => true)));
$this->assertEquals('</foo.css>; rel=preconnect; as=style; crossorigin', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=preconnect; as=style; crossorigin', $linkManager->buildHeaderValue());
}

public function testPrefetch()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->prefetch('/foo.css', array('as' => 'style', 'crossorigin' => true)));
$this->assertEquals('</foo.css>; rel=prefetch; as=style; crossorigin', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=prefetch; as=style; crossorigin', $linkManager->buildHeaderValue());
}

public function testPrerender()
{
$linkManager = new LinkManager();
$extension = new LinkExtension($linkManager);
$linkManager = new WebLinkManager();
$extension = new WebLinkExtension($linkManager);

$this->assertEquals('/foo.css', $extension->prerender('/foo.css', array('as' => 'style', 'crossorigin' => true)));
$this->assertEquals('</foo.css>; rel=prerender; as=style; crossorigin', $linkManager->buildValues());
$this->assertEquals('</foo.css>; rel=prerender; as=style; crossorigin', $linkManager->buildHeaderValue());
}

public function testGetName()
{
$this->assertEquals('web_link', (new WebLinkExtension(new WebLinkManager()))->getName());
}
}
3 changes: 2 additions & 1 deletion 3 src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"symfony/stopwatch": "~2.8|~3.0",
"symfony/console": "~2.8|~3.0",
"symfony/var-dumper": "~2.8.10|~3.1.4|~3.2",
"symfony/expression-language": "~2.8|~3.0"
"symfony/expression-language": "~2.8|~3.0",
"symfony/weblink": "~3.3"
},
"suggest": {
"symfony/finder": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Link\LinkManagerInterface;
use Symfony\Component\WebLink\WebLinkManagerInterface;
Copy link
Member

Choose a reason for hiding this comment

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

alpha order

use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\Validation;
Expand Down Expand Up @@ -101,7 +101,7 @@ public function getConfigTreeBuilder()
$this->addPropertyInfoSection($rootNode);
$this->addCacheSection($rootNode);
$this->addPhpErrorsSection($rootNode);
$this->addLinksSection($rootNode);
$this->addWebLinkSection($rootNode);

return $treeBuilder;
}
Expand Down Expand Up @@ -808,13 +808,13 @@ private function addPhpErrorsSection(ArrayNodeDefinition $rootNode)
;
}

private function addLinksSection(ArrayNodeDefinition $rootNode)
private function addWebLinkSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('links')
->info('links configuration')
->{!class_exists(FullStack::class) && interface_exists(LinkManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->arrayNode('web_link')
->info('web links configuration')
->{!class_exists(FullStack::class) && interface_exists(WebLinkManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Link\LinkManagerInterface;
use Symfony\Component\WebLink\WebLinkManagerInterface;
Copy link
Member

Choose a reason for hiding this comment

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

alpha order

use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
Expand Down Expand Up @@ -209,12 +209,12 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
}

if ($this->isConfigEnabled($container, $config['links'])) {
if (!interface_exists(LinkManagerInterface::class)) {
throw new LogicException('Link support cannot be enabled as the Link component is not installed.');
if ($this->isConfigEnabled($container, $config['web_link'])) {
if (!interface_exists(WebLinkManagerInterface::class)) {
throw new LogicException('WebLink support cannot be enabled as the WebLink component is not installed.');
}

$loader->load('links.xml');
$loader->load('web_link.xml');
}

$this->addAnnotatedClassesToCompile(array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,5 @@
<argument /> <!-- manifest path -->
</service>

<service id="assets.preload_manager" class="Symfony\Component\Asset\Preload\PreloadManager" public="false" />

<service id="asset.preload_listener" class="Symfony\Component\Asset\EventListener\PreloadListener">
<argument type="service" id="assets.preload_manager" />

<tag name="kernel.event_subscriber" />
</service>

</services>
</container>
18 changes: 0 additions & 18 deletions 18 src/Symfony/Bundle/FrameworkBundle/Resources/config/links.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
<xsd:element name="fragments" type="fragments" minOccurs="0" maxOccurs="1" />
<xsd:element name="links" type="links" minOccurs="0" maxOccurs="1" />
<xsd:element name="web-link" type="web_link" minOccurs="0" maxOccurs="1" />
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
<xsd:element name="session" type="session" minOccurs="0" maxOccurs="1" />
Expand Down Expand Up @@ -63,7 +63,7 @@
<xsd:attribute name="path" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="links">
<xsd:complexType name="web_link">
<xsd:attribute name="enabled" type="xsd:boolean" />
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@nicolas-grekas nicolas-grekas Apr 5, 2017

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)

</xsd:complexType>

Expand Down
19 changes: 19 additions & 0 deletions 19 src/Symfony/Bundle/FrameworkBundle/Resources/config/web_link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>

<service id="web_link.manager" class="Symfony\Component\WebLink\WebLinkManager" public="false" />
<service id="Symfony\Component\WebLink\WebLinkManagerInterface" alias="web_link.manager" public="false" />

<service id="web_link.add_link_header_listener" class="Symfony\Component\Link\WebLink\HeaderListener" public="false">
<argument type="service" id="web_link.manager" />

<tag name="kernel.event_subscriber" />
</service>

</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected static function getBundleDefaultConfig()
'log' => true,
'throw' => true,
),
'links' => array(
'web_link' => array(
'enabled' => !class_exists(FullStack::class),
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

$container->loadFromExtension('framework', array(
'links' => array('enabled' => true),
'web_link' => array('enabled' => true),
));
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:links enabled="true" />
<framework:web-link enabled="true" />
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
framework:
links:
web_link:
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ public function testAssetsDefaultVersionStrategyAsService()
$this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1));
}

public function testLinks()
public function testWebLink()
{
$container = $this->createContainerFromFile('links');
$this->assertTrue($container->hasDefinition('links.link_listener'));
$container = $this->createContainerFromFile('web_link');
$this->assertTrue($container->hasDefinition('web_link.manager'));
}

public function testTranslator()
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"symfony/console": "~3.3",
"symfony/css-selector": "~2.8|~3.0",
"symfony/dom-crawler": "~2.8|~3.0",
"symfony/link": "~3.3",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~2.8|~3.0",
"symfony/form": "~3.3",
Expand All @@ -54,6 +53,7 @@
"symfony/workflow": "~3.3",
"symfony/yaml": "~3.2",
"symfony/property-info": "~3.3",
"symfony/weblink": "~3.3",
"doctrine/annotations": "~1.0",
"phpdocumentor/reflection-docblock": "^3.0",
"twig/twig": "~1.26|~2.0",
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.