removed deprecated Twig features

This commit is contained in:
Fabien Potencier 2015-01-14 12:12:46 +01:00
parent ceefea86cc
commit 2afd6142aa
7 changed files with 0 additions and 187 deletions

View File

@ -16,7 +16,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
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.
@ -25,20 +24,11 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
*/
class AppVariable
{
private $security;
private $tokenStorage;
private $requestStack;
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;
@ -59,24 +49,6 @@ class AppVariable
$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.
*
@ -88,8 +60,6 @@ class AppVariable
{
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.');
}

View File

@ -38,7 +38,6 @@ class Configuration implements ConfigurationInterface
->end()
;
$this->addFormSection($rootNode);
$this->addFormThemesSection($rootNode);
$this->addGlobalsSection($rootNode);
$this->addTwigOptions($rootNode);
@ -46,52 +45,6 @@ class Configuration implements ConfigurationInterface
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

View File

@ -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" />
<xsd:element name="path" type="path" minOccurs="0" maxOccurs="unbounded" />
@ -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>

View File

@ -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>

View File

@ -23,44 +23,6 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
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();

View File

@ -1,41 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\TwigBundle;
trigger_error('The '.__NAMESPACE__.'\TwigDefaultEscapingStrategy class is deprecated in version 2.7 and will be removed in version 3.0. Use the "filename" auto-escaping strategy instead.', E_USER_DEPRECATED);
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since version 2.7, will be removed in 3.0. Use the "filename" auto-escaping strategy instead.
*/
class TwigDefaultEscapingStrategy
{
public static function guess($filename)
{
// remove .twig
$filename = substr($filename, 0, -5);
// get the format
$format = substr($filename, strrpos($filename, '.') + 1);
if ('js' === $format) {
return 'js';
}
if ('txt' === $format) {
return false;
}
return 'html';
}
}

View File

@ -41,28 +41,6 @@ class TwigEngine extends BaseEngine implements EngineInterface
$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}
*/