Skip to content

removed deprecated Twig features #13409

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 1 commit into from
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 0 additions & 30 deletions src/Symfony/Bridge/Twig/AppVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
* Exposes some Symfony parameters and services as an "app" global variable.
Expand All @@ -25,20 +24,11 @@
*/
class AppVariable
{
private $security;
private $tokenStorage;
private $requestStack;
Copy link
Contributor

Choose a reason for hiding this comment

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

this property is still referenced in getUser

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

private $environment;
private $debug;

/**
* @deprecated since version 2.7, to be removed in 3.0.
*/
public function setSecurity(SecurityContextInterface $security)
{
$this->security = $security;
}

public function setTokenStorage(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
Expand All @@ -59,24 +49,6 @@ public function setDebug($debug)
$this->debug = (bool) $debug;
}

/**
* Returns the security context service.
*
* @deprecated since version 2.6, to be removed in 3.0.
*
* @return SecurityContext|null The security context
*/
public function getSecurity()
{
trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED);

if (null === $this->security) {
throw new \RuntimeException('The "app.security" variable is not available.');
}

return $this->security;
}

/**
* Returns the current user.
*
Expand All @@ -88,8 +60,6 @@ public function getUser()
{
if (null !== $this->tokenStorage) {
$tokenStorage = $this->tokenStorage;
} elseif (null !== $this->security) {
$tokenStorage = $this->security;
} else {
throw new \RuntimeException('The "app.user" variable is not available.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,13 @@ public function getConfigTreeBuilder()
->end()
;

$this->addFormSection($rootNode);
$this->addFormThemesSection($rootNode);
$this->addGlobalsSection($rootNode);
$this->addTwigOptions($rootNode);

return $treeBuilder;
}

private function addFormSection(ArrayNodeDefinition $rootNode)
{
$rootNode
// Check deprecation before the config is processed to ensure
// the setting has been explicitly defined in a configuration file.
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['form']['resources']); })
->then(function ($v) {
trigger_error('The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.', E_USER_DEPRECATED);

return $v;
})
->end()
->validate()
->ifTrue(function ($v) {
return count($v['form']['resources']) > 0;
})
->then(function ($v) {
$v['form_themes'] = array_values(array_unique(array_merge($v['form']['resources'], $v['form_themes'])));

return $v;
})
->end()
->children()
->arrayNode('form')
->info('Deprecated since version 2.6, to be removed in 3.0. Use twig.form_themes instead')
->addDefaultsIfNotSet()
->fixXmlConfig('resource')
->children()
->arrayNode('resources')
->addDefaultChildrenIfNoneSet()
->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end()
->example(array('MyBundle::form.html.twig'))
->validate()
->ifTrue(function ($v) { return !in_array('form_div_layout.html.twig', $v); })
->then(function ($v) {
return array_merge(array('form_div_layout.html.twig'), $v);
})
->end()
->end()
->end()
->end()
->end()
;
}

private function addFormThemesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

<xsd:complexType name="config">
<xsd:sequence>
<!-- @deprecated since version 2.6, to be removed in 3.0 -->
<xsd:element name="form" type="form" minOccurs="0" maxOccurs="1" />
<xsd:element name="form-theme" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="global" type="global" minOccurs="0" maxOccurs="unbounded" />
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you can also remove the complexType name="form"

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, fixed

<xsd:element name="path" type="path" minOccurs="0" maxOccurs="unbounded" />
Expand All @@ -28,12 +26,6 @@
<xsd:attribute name="exception-controller" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="form">
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="resource" type="xsd:string" />
</xsd:choice>
</xsd:complexType>

<xsd:complexType name="path" mixed="true">
<xsd:attribute name="namespace" type="xsd:string" />
</xsd:complexType>
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<service id="twig.app_variable" class="Symfony\Bridge\Twig\AppVariable" public="false">
<call method="setEnvironment"><argument>%kernel.environment%</argument></call>
<call method="setDebug"><argument>%kernel.debug%</argument></call>
<call method="setSecurity"><argument type="service" id="security.context" on-invalid="ignore" /></call>
<call method="setTokenStorage"><argument type="service" id="security.token_storage" on-invalid="ignore" /></call>
<call method="setRequestStack"><argument type="service" id="request_stack" on-invalid="ignore" /></call>
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,6 @@

class TwigExtensionTest extends TestCase
{
/**
* @dataProvider getFormats
*/
public function testLegacyFormResourcesConfigurationKey($format)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$this->loadFromFile($container, 'legacy-form-resources-only', $format);
$this->compileContainer($container);

// Form resources
$this->assertCount(3, $container->getParameter('twig.form.resources'));
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
}

/**
* @dataProvider getFormats
*/
public function testLegacyMergeFormResourcesConfigurationKeyWithFormThemesConfigurationKey($format)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$this->loadFromFile($container, 'legacy-merge-form-resources-with-form-themes', $format);
$this->compileContainer($container);

$this->assertCount(4, $container->getParameter('twig.form.resources'));
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('FooBundle:Form:bar.html.twig', $container->getParameter('twig.form.resources'));
}

public function testLoadEmptyConfiguration()
{
$container = $this->createContainer();
Expand Down
41 changes: 0 additions & 41 deletions src/Symfony/Bundle/TwigBundle/TwigDefaultEscapingStrategy.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Symfony/Bundle/TwigBundle/TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,6 @@ public function __construct(\Twig_Environment $environment, TemplateNameParserIn
$this->locator = $locator;
}

/**
* @deprecated since version 2.7, to be removed in 3.0.
* Inject the escaping strategy on \Twig_Environment instead.
*/
public function setDefaultEscapingStrategy($strategy)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig_Environment object instead.', E_USER_DEPRECATED);

$this->environment->getExtension('escaper')->setDefaultStrategy($strategy);
}

/**
* @deprecated since version 2.7, to be removed in 3.0.
* Use the 'filename' strategy instead.
*/
public function guessDefaultEscapingStrategy($filename)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED);

return \Twig_FileExtensionEscapingStrategy::guess($filename);
}

/**
* {@inheritdoc}
*/
Expand Down