*/
-class CodeExtension extends \Twig_Extension
+class CodeExtension extends AbstractExtension
{
private $fileLinkFormat;
private $rootDir;
@@ -42,14 +45,14 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
public function getFilters()
{
return array(
- new \Twig_SimpleFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('format_args_as_text', array($this, 'formatArgsAsText')),
- new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')),
+ new TwigFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
+ new TwigFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
+ new TwigFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
+ new TwigFilter('format_args_as_text', array($this, 'formatArgsAsText')),
+ new TwigFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
+ new TwigFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
+ new TwigFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
+ new TwigFilter('file_link', array($this, 'getFileLink')),
);
}
@@ -174,7 +177,7 @@ public function formatFile($file, $line, $text = null)
$text = "$text at line $line";
if (false !== $link = $this->getFileLink($file, $line)) {
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
diff --git a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php
index 5e43547ff1f40..eddd4d7f2afa0 100644
--- a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php
@@ -14,13 +14,17 @@
use Symfony\Bridge\Twig\TokenParser\DumpTokenParser;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
+use Twig\Environment;
+use Twig\Extension\AbstractExtension;
+use Twig\Template;
+use Twig\TwigFunction;
/**
* Provides integration of the dump() function with Twig.
*
* @author Nicolas Grekas
*/
-class DumpExtension extends \Twig_Extension
+class DumpExtension extends AbstractExtension
{
private $cloner;
@@ -32,7 +36,7 @@ public function __construct(ClonerInterface $cloner)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
+ new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
);
}
@@ -46,7 +50,7 @@ public function getName()
return 'dump';
}
- public function dump(\Twig_Environment $env, $context)
+ public function dump(Environment $env, $context)
{
if (!$env->isDebug()) {
return;
@@ -55,7 +59,7 @@ public function dump(\Twig_Environment $env, $context)
if (2 === func_num_args()) {
$vars = array();
foreach ($context as $key => $value) {
- if (!$value instanceof \Twig_Template) {
+ if (!$value instanceof Template) {
$vars[$key] = $value;
}
}
diff --git a/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php b/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
index 6b30a279419b7..fc64fa3e3775d 100644
--- a/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
@@ -12,13 +12,15 @@
namespace Symfony\Bridge\Twig\Extension;
use Symfony\Component\ExpressionLanguage\Expression;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* ExpressionExtension gives a way to create Expressions from a template.
*
* @author Fabien Potencier
*/
-class ExpressionExtension extends \Twig_Extension
+class ExpressionExtension extends AbstractExtension
{
/**
* {@inheritdoc}
@@ -26,7 +28,7 @@ class ExpressionExtension extends \Twig_Extension
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('expression', array($this, 'createExpression')),
+ new TwigFunction('expression', array($this, 'createExpression')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php
index e833e3de2d228..053b1d4a6b336 100644
--- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php
@@ -14,6 +14,12 @@
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
+use Twig\Environment;
+use Twig\Extension\AbstractExtension;
+use Twig\Extension\InitRuntimeInterface;
+use Twig\TwigFilter;
+use Twig\TwigFunction;
+use Twig\TwigTest;
/**
* FormExtension extends Twig with form capabilities.
@@ -21,7 +27,7 @@
* @author Fabien Potencier
* @author Bernhard Schussek
*/
-class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
+class FormExtension extends AbstractExtension implements InitRuntimeInterface
{
/**
* This property is public so that it can be accessed directly from compiled
@@ -39,7 +45,7 @@ public function __construct(TwigRendererInterface $renderer)
/**
* {@inheritdoc}
*/
- public function initRuntime(\Twig_Environment $environment)
+ public function initRuntime(Environment $environment)
{
$this->renderer->setEnvironment($environment);
}
@@ -61,16 +67,16 @@ public function getTokenParsers()
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
- new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
- new \Twig_SimpleFunction('csrf_token', array($this, 'renderCsrfToken')),
+ new TwigFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
+ new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
+ new TwigFunction('csrf_token', array($this, 'renderCsrfToken')),
);
}
@@ -80,7 +86,7 @@ public function getFunctions()
public function getFilters()
{
return array(
- new \Twig_SimpleFilter('humanize', array($this, 'humanize')),
+ new TwigFilter('humanize', array($this, 'humanize')),
);
}
@@ -90,7 +96,7 @@ public function getFilters()
public function getTests()
{
return array(
- new \Twig_SimpleTest('selectedchoice', array($this, 'isSelectedChoice')),
+ new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
index 69d6d326f4d08..90b515ee320ba 100644
--- a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
@@ -14,13 +14,15 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* Twig extension for the Symfony HttpFoundation component.
*
* @author Fabien Potencier
*/
-class HttpFoundationExtension extends \Twig_Extension
+class HttpFoundationExtension extends AbstractExtension
{
private $requestStack;
private $requestContext;
@@ -37,8 +39,8 @@ public function __construct(RequestStack $requestStack, RequestContext $requestC
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('absolute_url', array($this, 'generateAbsoluteUrl')),
- new \Twig_SimpleFunction('relative_path', array($this, 'generateRelativePath')),
+ new TwigFunction('absolute_url', array($this, 'generateAbsoluteUrl')),
+ new TwigFunction('relative_path', array($this, 'generateRelativePath')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
index 1da12aaf5eb10..07e913059754c 100644
--- a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
@@ -13,13 +13,15 @@
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* Provides integration with the HttpKernel component.
*
* @author Fabien Potencier
*/
-class HttpKernelExtension extends \Twig_Extension
+class HttpKernelExtension extends AbstractExtension
{
private $handler;
@@ -36,9 +38,9 @@ public function __construct(FragmentHandler $handler)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))),
- new \Twig_SimpleFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
- new \Twig_SimpleFunction('controller', array($this, 'controller')),
+ new TwigFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))),
+ new TwigFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
+ new TwigFunction('controller', array($this, 'controller')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php b/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php
index ea105e8d955e4..17abb779899ac 100644
--- a/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php
@@ -12,13 +12,15 @@
namespace Symfony\Bridge\Twig\Extension;
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* LogoutUrlHelper provides generator functions for the logout URL to Twig.
*
* @author Jeremy Mikola
*/
-class LogoutUrlExtension extends \Twig_Extension
+class LogoutUrlExtension extends AbstractExtension
{
private $generator;
@@ -33,8 +35,8 @@ public function __construct(LogoutUrlGenerator $generator)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('logout_url', array($this, 'getLogoutUrl')),
- new \Twig_SimpleFunction('logout_path', array($this, 'getLogoutPath')),
+ new TwigFunction('logout_url', array($this, 'getLogoutUrl')),
+ new TwigFunction('logout_path', array($this, 'getLogoutPath')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
index 648a6c8036d75..21214f81196ad 100644
--- a/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/ProfilerExtension.php
@@ -12,16 +12,18 @@
namespace Symfony\Bridge\Twig\Extension;
use Symfony\Component\Stopwatch\Stopwatch;
+use Twig\Extension\ProfilerExtension as BaseProfilerExtension;
+use Twig\Profiler\Profile;
/**
* @author Fabien Potencier
*/
-class ProfilerExtension extends \Twig_Extension_Profiler
+class ProfilerExtension extends BaseProfilerExtension
{
private $stopwatch;
private $events;
- public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch = null)
+ public function __construct(Profile $profile, Stopwatch $stopwatch = null)
{
parent::__construct($profile);
@@ -29,7 +31,7 @@ public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatc
$this->events = new \SplObjectStorage();
}
- public function enter(\Twig_Profiler_Profile $profile)
+ public function enter(Profile $profile)
{
if ($this->stopwatch && $profile->isTemplate()) {
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
@@ -38,7 +40,7 @@ public function enter(\Twig_Profiler_Profile $profile)
parent::enter($profile);
}
- public function leave(\Twig_Profiler_Profile $profile)
+ public function leave(Profile $profile)
{
parent::leave($profile);
diff --git a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
index 81cef949c7408..97b1ea31360ce 100644
--- a/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
@@ -12,13 +12,18 @@
namespace Symfony\Bridge\Twig\Extension;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
+use Twig\Extension\AbstractExtension;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Node;
+use Twig\TwigFunction;
/**
* Provides integration of the Routing component with Twig.
*
* @author Fabien Potencier
*/
-class RoutingExtension extends \Twig_Extension
+class RoutingExtension extends AbstractExtension
{
private $generator;
@@ -35,8 +40,8 @@ public function __construct(UrlGeneratorInterface $generator)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
- new \Twig_SimpleFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
+ new TwigFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
+ new TwigFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
);
}
@@ -82,9 +87,11 @@ public function getUrl($name, $parameters = array(), $schemeRelative = false)
* - path('route', {'param1': 'value1', 'param2': 'value2'})
* If param1 and param2 reference placeholder in the route, it would still be safe. But we don't know.
*
- * @param \Twig_Node $argsNode The arguments of the path/url function
+ * @param Node $argsNode The arguments of the path/url function
*
* @return array An array with the contexts the URL is safe
+ *
+ * To be made @final in 3.4, and the type-hint be changed to "\Twig\Node\Node" in 4.0.
*/
public function isUrlGenerationSafe(\Twig_Node $argsNode)
{
@@ -93,8 +100,8 @@ public function isUrlGenerationSafe(\Twig_Node $argsNode)
$argsNode->hasNode(1) ? $argsNode->getNode(1) : null
);
- if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 &&
- (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant)
+ if (null === $paramsNode || $paramsNode instanceof ArrayExpression && count($paramsNode) <= 2 &&
+ (!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof ConstantExpression)
) {
return array('html');
}
diff --git a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
index fa5fae2e77a01..193726a684371 100644
--- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
@@ -14,13 +14,15 @@
use Symfony\Component\Security\Acl\Voter\FieldVote;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* SecurityExtension exposes security context features.
*
* @author Fabien Potencier
*/
-class SecurityExtension extends \Twig_Extension
+class SecurityExtension extends AbstractExtension
{
private $securityChecker;
@@ -52,7 +54,7 @@ public function isGranted($role, $object = null, $field = null)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('is_granted', array($this, 'isGranted')),
+ new TwigFunction('is_granted', array($this, 'isGranted')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php
index 52af92324c228..635188b7389e4 100644
--- a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php
@@ -13,13 +13,14 @@
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser;
+use Twig\Extension\AbstractExtension;
/**
* Twig extension for the stopwatch helper.
*
* @author Wouter J
*/
-class StopwatchExtension extends \Twig_Extension
+class StopwatchExtension extends AbstractExtension
{
private $stopwatch;
diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
index f1f2fbd20b82e..5155169a8173d 100644
--- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
@@ -17,18 +17,22 @@
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
+use Twig\Extension\AbstractExtension;
+use Twig\NodeVisitor\NodeVisitorInterface;
+use Twig\TokenParser\AbstractTokenParser;
+use Twig\TwigFilter;
/**
* Provides integration of the Translation component with Twig.
*
* @author Fabien Potencier
*/
-class TranslationExtension extends \Twig_Extension
+class TranslationExtension extends AbstractExtension
{
private $translator;
private $translationNodeVisitor;
- public function __construct(TranslatorInterface $translator, \Twig_NodeVisitorInterface $translationNodeVisitor = null)
+ public function __construct(TranslatorInterface $translator, NodeVisitorInterface $translationNodeVisitor = null)
{
if (!$translationNodeVisitor) {
$translationNodeVisitor = new TranslationNodeVisitor();
@@ -49,15 +53,15 @@ public function getTranslator()
public function getFilters()
{
return array(
- new \Twig_SimpleFilter('trans', array($this, 'trans')),
- new \Twig_SimpleFilter('transchoice', array($this, 'transchoice')),
+ new TwigFilter('trans', array($this, 'trans')),
+ new TwigFilter('transchoice', array($this, 'transchoice')),
);
}
/**
* Returns the token parser instance to add to the existing list.
*
- * @return array An array of Twig_TokenParser instances
+ * @return AbstractTokenParser[]
*/
public function getTokenParsers()
{
diff --git a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php
index 2d46795b4a81e..894a2fd189014 100644
--- a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php
@@ -13,13 +13,15 @@
use Symfony\Component\Yaml\Dumper as YamlDumper;
use Symfony\Component\Yaml\Yaml;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFilter;
/**
* Provides integration of the Yaml component with Twig.
*
* @author Fabien Potencier
*/
-class YamlExtension extends \Twig_Extension
+class YamlExtension extends AbstractExtension
{
/**
* {@inheritdoc}
@@ -27,8 +29,8 @@ class YamlExtension extends \Twig_Extension
public function getFilters()
{
return array(
- new \Twig_SimpleFilter('yaml_encode', array($this, 'encode')),
- new \Twig_SimpleFilter('yaml_dump', array($this, 'dump')),
+ new TwigFilter('yaml_encode', array($this, 'encode')),
+ new TwigFilter('yaml_dump', array($this, 'dump')),
);
}
diff --git a/src/Symfony/Bridge/Twig/Form/TwigRenderer.php b/src/Symfony/Bridge/Twig/Form/TwigRenderer.php
index ac139e44a1331..2485c0a88c530 100644
--- a/src/Symfony/Bridge/Twig/Form/TwigRenderer.php
+++ b/src/Symfony/Bridge/Twig/Form/TwigRenderer.php
@@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\FormRenderer;
+use Twig\Environment;
/**
* @author Bernhard Schussek
@@ -33,7 +34,7 @@ public function __construct(TwigRendererEngineInterface $engine, $csrfTokenManag
/**
* {@inheritdoc}
*/
- public function setEnvironment(\Twig_Environment $environment)
+ public function setEnvironment(Environment $environment)
{
$this->engine->setEnvironment($environment);
}
diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
index 5248d5fd370ea..d83124e721366 100644
--- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
+++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
@@ -13,6 +13,8 @@
use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\Form\FormView;
+use Twig\Environment;
+use Twig\Template;
/**
* @author Bernhard Schussek
@@ -20,19 +22,19 @@
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
{
/**
- * @var \Twig_Environment
+ * @var Environment
*/
private $environment;
/**
- * @var \Twig_Template
+ * @var Template
*/
private $template;
/**
* {@inheritdoc}
*/
- public function setEnvironment(\Twig_Environment $environment)
+ public function setEnvironment(Environment $environment)
{
$this->environment = $environment;
}
@@ -150,13 +152,13 @@ protected function loadResourceForBlockName($cacheKey, FormView $view, $blockNam
*/
protected function loadResourcesFromTheme($cacheKey, &$theme)
{
- if (!$theme instanceof \Twig_Template) {
- /* @var \Twig_Template $theme */
+ if (!$theme instanceof Template) {
+ /* @var Template $theme */
$theme = $this->environment->loadTemplate($theme);
}
if (null === $this->template) {
- // Store the first \Twig_Template instance that we find so that
+ // Store the first Template instance that we find so that
// we can call displayBlock() later on. It doesn't matter *which*
// template we use for that, since we pass the used blocks manually
// anyway.
diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php
index ef764a248f339..3e8a8e1f4678d 100644
--- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php
+++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php
@@ -12,16 +12,15 @@
namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\FormRendererEngineInterface;
+use Twig\Environment;
+
+// BC/FC with namespaced Twig
+class_exists('Twig\Environment');
/**
* @author Bernhard Schussek
*/
interface TwigRendererEngineInterface extends FormRendererEngineInterface
{
- /**
- * Sets Twig's environment.
- *
- * @param \Twig_Environment $environment
- */
- public function setEnvironment(\Twig_Environment $environment);
+ public function setEnvironment(Environment $environment);
}
diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php
index 4682f520008ac..cb45c17e1afc2 100644
--- a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php
+++ b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php
@@ -12,16 +12,15 @@
namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\FormRendererInterface;
+use Twig\Environment;
+
+// BC/FC with namespaced Twig
+class_exists('Twig\Environment');
/**
* @author Bernhard Schussek
*/
interface TwigRendererInterface extends FormRendererInterface
{
- /**
- * Sets Twig's environment.
- *
- * @param \Twig_Environment $environment
- */
- public function setEnvironment(\Twig_Environment $environment);
+ public function setEnvironment(Environment $environment);
}
diff --git a/src/Symfony/Bridge/Twig/Node/DumpNode.php b/src/Symfony/Bridge/Twig/Node/DumpNode.php
index a66781e36550a..d820d75cc7db9 100644
--- a/src/Symfony/Bridge/Twig/Node/DumpNode.php
+++ b/src/Symfony/Bridge/Twig/Node/DumpNode.php
@@ -11,14 +11,17 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Node;
+
/**
* @author Julien Galenski
*/
-class DumpNode extends \Twig_Node
+class DumpNode extends Node
{
private $varPrefix;
- public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null)
+ public function __construct($varPrefix, Node $values = null, $lineno, $tag = null)
{
$nodes = array();
if (null !== $values) {
@@ -32,7 +35,7 @@ public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag
/**
* {@inheritdoc}
*/
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler
->write("if (\$this->env->isDebug()) {\n")
@@ -44,7 +47,7 @@ public function compile(\Twig_Compiler $compiler)
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
->indent()
- ->write(sprintf('if (!$%sval instanceof \Twig_Template) {'."\n", $this->varPrefix))
+ ->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
->indent()
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
->outdent()
diff --git a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php
index 91793771393d8..b2eb100d5bfdc 100644
--- a/src/Symfony/Bridge/Twig/Node/FormThemeNode.php
+++ b/src/Symfony/Bridge/Twig/Node/FormThemeNode.php
@@ -11,22 +11,20 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Node;
+
/**
* @author Fabien Potencier
*/
-class FormThemeNode extends \Twig_Node
+class FormThemeNode extends Node
{
- public function __construct(\Twig_Node $form, \Twig_Node $resources, $lineno, $tag = null)
+ public function __construct(Node $form, Node $resources, $lineno, $tag = null)
{
parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param \Twig_Compiler $compiler A Twig_Compiler instance
- */
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler
->addDebugInfo($this)
diff --git a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php
index 33865e2f1cb78..4a06907b0b43a 100644
--- a/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php
+++ b/src/Symfony/Bridge/Twig/Node/RenderBlockNode.php
@@ -11,6 +11,9 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\FunctionExpression;
+
/**
* Compiles a call to {@link \Symfony\Component\Form\FormRendererInterface::renderBlock()}.
*
@@ -19,9 +22,9 @@
*
* @author Bernhard Schussek
*/
-class RenderBlockNode extends \Twig_Node_Expression_Function
+class RenderBlockNode extends FunctionExpression
{
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
$arguments = iterator_to_array($this->getNode('arguments'));
diff --git a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
index 9cb964865ea19..7c95199953b2f 100644
--- a/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
+++ b/src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
@@ -11,12 +11,17 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\FunctionExpression;
+
/**
* @author Bernhard Schussek
*/
-class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
+class SearchAndRenderBlockNode extends FunctionExpression
{
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(');
@@ -39,7 +44,7 @@ public function compile(\Twig_Compiler $compiler)
$variables = isset($arguments[2]) ? $arguments[2] : null;
$lineno = $label->getTemplateLine();
- if ($label instanceof \Twig_Node_Expression_Constant) {
+ if ($label instanceof ConstantExpression) {
// If the label argument is given as a constant, we can either
// strip it away if it is empty, or integrate it into the array
// of variables at compile time.
@@ -48,8 +53,8 @@ public function compile(\Twig_Compiler $compiler)
// Only insert the label into the array if it is not empty
if (!twig_test_empty($label->getAttribute('value'))) {
$originalVariables = $variables;
- $variables = new \Twig_Node_Expression_Array(array(), $lineno);
- $labelKey = new \Twig_Node_Expression_Constant('label', $lineno);
+ $variables = new ArrayExpression(array(), $lineno);
+ $labelKey = new ConstantExpression('label', $lineno);
if (null !== $originalVariables) {
foreach ($originalVariables->getKeyValuePairs() as $pair) {
diff --git a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php
index 95d755a78cdb0..fac770c2499ba 100644
--- a/src/Symfony/Bridge/Twig/Node/StopwatchNode.php
+++ b/src/Symfony/Bridge/Twig/Node/StopwatchNode.php
@@ -11,19 +11,23 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\AssignNameExpression;
+use Twig\Node\Node;
+
/**
* Represents a stopwatch node.
*
* @author Wouter J
*/
-class StopwatchNode extends \Twig_Node
+class StopwatchNode extends Node
{
- public function __construct(\Twig_Node $name, \Twig_Node $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
+ public function __construct(Node $name, Node $body, AssignNameExpression $var, $lineno = 0, $tag = null)
{
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
}
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler
->addDebugInfo($this)
diff --git a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
index adee71ffc5dc4..c9c82b33e541c 100644
--- a/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
+++ b/src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
@@ -11,22 +11,21 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\AbstractExpression;
+use Twig\Node\Node;
+
/**
* @author Fabien Potencier
*/
-class TransDefaultDomainNode extends \Twig_Node
+class TransDefaultDomainNode extends Node
{
- public function __construct(\Twig_Node_Expression $expr, $lineno = 0, $tag = null)
+ public function __construct(AbstractExpression $expr, $lineno = 0, $tag = null)
{
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param \Twig_Compiler $compiler A Twig_Compiler instance
- */
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
// noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
}
diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php
index 7b2f9c090405f..020810f7b7c55 100644
--- a/src/Symfony/Bridge/Twig/Node/TransNode.php
+++ b/src/Symfony/Bridge/Twig/Node/TransNode.php
@@ -11,12 +11,23 @@
namespace Symfony\Bridge\Twig\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\AbstractExpression;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\Node;
+use Twig\Node\TextNode;
+
+// BC/FC with namespaced Twig
+class_exists('Twig\Node\Expression\ArrayExpression');
+
/**
* @author Fabien Potencier
*/
-class TransNode extends \Twig_Node
+class TransNode extends Node
{
- public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
+ public function __construct(Node $body, Node $domain = null, AbstractExpression $count = null, AbstractExpression $vars = null, AbstractExpression $locale = null, $lineno = 0, $tag = null)
{
$nodes = array('body' => $body);
if (null !== $domain) {
@@ -35,17 +46,12 @@ public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_N
parent::__construct($nodes, array(), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param \Twig_Compiler $compiler A Twig_Compiler instance
- */
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler->addDebugInfo($this);
- $defaults = new \Twig_Node_Expression_Array(array(), -1);
- if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof \Twig_Node_Expression_Array) {
+ $defaults = new ArrayExpression(array(), -1);
+ if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof ArrayExpression) {
$defaults = $this->getNode('vars');
$vars = null;
}
@@ -96,11 +102,11 @@ public function compile(\Twig_Compiler $compiler)
$compiler->raw(");\n");
}
- protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
+ protected function compileString(Node $body, ArrayExpression $vars, $ignoreStrictCheck = false)
{
- if ($body instanceof \Twig_Node_Expression_Constant) {
+ if ($body instanceof ConstantExpression) {
$msg = $body->getAttribute('value');
- } elseif ($body instanceof \Twig_Node_Text) {
+ } elseif ($body instanceof TextNode) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
@@ -109,18 +115,18 @@ protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $
preg_match_all('/(?getTemplateLine());
+ $key = new ConstantExpression('%'.$var.'%', $body->getTemplateLine());
if (!$vars->hasElement($key)) {
if ('count' === $var && $this->hasNode('count')) {
$vars->addElement($this->getNode('count'), $key);
} else {
- $varExpr = new \Twig_Node_Expression_Name($var, $body->getTemplateLine());
+ $varExpr = new NameExpression($var, $body->getTemplateLine());
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
$vars->addElement($varExpr, $key);
}
}
}
- return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars);
+ return array(new ConstantExpression(str_replace('%%', '%', trim($msg)), $body->getTemplateLine()), $vars);
}
}
diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
index e64d6eae2347d..b3c89d18eb2bd 100644
--- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
+++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
@@ -13,13 +13,24 @@
use Symfony\Bridge\Twig\Node\TransNode;
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
+use Twig\Environment;
+use Twig\Node\BlockNode;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\AssignNameExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\FilterExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\ModuleNode;
+use Twig\Node\Node;
+use Twig\Node\SetNode;
+use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* TranslationDefaultDomainNodeVisitor.
*
* @author Fabien Potencier
*/
-class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
+class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
{
/**
* @var Scope
@@ -37,23 +48,23 @@ public function __construct()
/**
* {@inheritdoc}
*/
- protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
+ protected function doEnterNode(Node $node, Environment $env)
{
- if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
+ if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->enter();
}
if ($node instanceof TransDefaultDomainNode) {
- if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
+ if ($node->getNode('expr') instanceof ConstantExpression) {
$this->scope->set('domain', $node->getNode('expr'));
return $node;
} else {
$var = $this->getVarName();
- $name = new \Twig_Node_Expression_AssignName($var, $node->getTemplateLine());
- $this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getTemplateLine()));
+ $name = new AssignNameExpression($var, $node->getTemplateLine());
+ $this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
- return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getTemplateLine());
+ return new SetNode(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine());
}
}
@@ -61,7 +72,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
return $node;
}
- if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
+ if ($node instanceof FilterExpression && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
$arguments = $node->getNode('arguments');
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
if ($this->isNamedArguments($arguments)) {
@@ -71,7 +82,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
} else {
if (!$arguments->hasNode($ind)) {
if (!$arguments->hasNode($ind - 1)) {
- $arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getTemplateLine()));
+ $arguments->setNode($ind - 1, new ArrayExpression(array(), $node->getTemplateLine()));
}
$arguments->setNode($ind, $this->scope->get('domain'));
@@ -89,13 +100,13 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
/**
* {@inheritdoc}
*/
- protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
+ protected function doLeaveNode(Node $node, Environment $env)
{
if ($node instanceof TransDefaultDomainNode) {
return false;
}
- if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
+ if ($node instanceof BlockNode || $node instanceof ModuleNode) {
$this->scope = $this->scope->leave();
}
diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php
index 6e3880d09ed98..01f230b9efdff 100644
--- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php
+++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php
@@ -12,13 +12,18 @@
namespace Symfony\Bridge\Twig\NodeVisitor;
use Symfony\Bridge\Twig\Node\TransNode;
+use Twig\Environment;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\FilterExpression;
+use Twig\Node\Node;
+use Twig\NodeVisitor\AbstractNodeVisitor;
/**
* TranslationNodeVisitor extracts translation messages.
*
* @author Fabien Potencier
*/
-class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
+class TranslationNodeVisitor extends AbstractNodeVisitor
{
const UNDEFINED_DOMAIN = '_undefined';
@@ -45,16 +50,16 @@ public function getMessages()
/**
* {@inheritdoc}
*/
- protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
+ protected function doEnterNode(Node $node, Environment $env)
{
if (!$this->enabled) {
return $node;
}
if (
- $node instanceof \Twig_Node_Expression_Filter &&
+ $node instanceof FilterExpression &&
'trans' === $node->getNode('filter')->getAttribute('value') &&
- $node->getNode('node') instanceof \Twig_Node_Expression_Constant
+ $node->getNode('node') instanceof ConstantExpression
) {
// extract constant nodes with a trans filter
$this->messages[] = array(
@@ -62,9 +67,9 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
);
} elseif (
- $node instanceof \Twig_Node_Expression_Filter &&
+ $node instanceof FilterExpression &&
'transchoice' === $node->getNode('filter')->getAttribute('value') &&
- $node->getNode('node') instanceof \Twig_Node_Expression_Constant
+ $node->getNode('node') instanceof ConstantExpression
) {
// extract constant nodes with a trans filter
$this->messages[] = array(
@@ -85,7 +90,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
/**
* {@inheritdoc}
*/
- protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
+ protected function doLeaveNode(Node $node, Environment $env)
{
return $node;
}
@@ -99,12 +104,12 @@ public function getPriority()
}
/**
- * @param \Twig_Node $arguments
- * @param int $index
+ * @param Node $arguments
+ * @param int $index
*
* @return string|null
*/
- private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
+ private function getReadDomainFromArguments(Node $arguments, $index)
{
if ($arguments->hasNode('domain')) {
$argument = $arguments->getNode('domain');
@@ -118,13 +123,13 @@ private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
}
/**
- * @param \Twig_Node $node
+ * @param Node $node
*
* @return string|null
*/
- private function getReadDomainFromNode(\Twig_Node $node)
+ private function getReadDomainFromNode(Node $node)
{
- if ($node instanceof \Twig_Node_Expression_Constant) {
+ if ($node instanceof ConstantExpression) {
return $node->getAttribute('value');
}
diff --git a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
index 16dd75120c1da..19b8cbec8188e 100644
--- a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
@@ -16,6 +16,8 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
+use Twig\Loader\FilesystemLoader;
+use Twig\Environment;
class LintCommandTest extends TestCase
{
@@ -71,7 +73,7 @@ public function testLintFileCompileTimeException()
*/
private function createCommandTester()
{
- $twig = new \Twig_Environment(new \Twig_Loader_Filesystem());
+ $twig = new Environment(new FilesystemLoader());
$command = new LintCommand();
$command->setTwigEnvironment($twig);
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
index 312fda1d7106a..36e0e6a08d99e 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
@@ -15,6 +15,8 @@
use Symfony\Bridge\Twig\Extension\DumpExtension;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
+use Twig\Environment;
+use Twig\Loader\ArrayLoader;
class DumpExtensionTest extends TestCase
{
@@ -24,7 +26,7 @@ class DumpExtensionTest extends TestCase
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
{
$extension = new DumpExtension(new VarCloner());
- $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array(
+ $twig = new Environment(new ArrayLoader(array('template' => $template)), array(
'debug' => $debug,
'cache' => false,
'optimizations' => 0,
@@ -64,7 +66,7 @@ public function getDumpTags()
public function testDump($context, $args, $expectedOutput, $debug = true)
{
$extension = new DumpExtension(new VarCloner());
- $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array(
+ $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array(
'debug' => $debug,
'cache' => false,
'optimizations' => 0,
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php
index 597dfc75f4165..ab3b44ccce0c1 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php
@@ -13,6 +13,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\ExpressionExtension;
+use Twig\Environment;
+use Twig\Loader\ArrayLoader;
class ExpressionExtensionTest extends TestCase
{
@@ -21,7 +23,7 @@ class ExpressionExtensionTest extends TestCase
public function testExpressionCreation()
{
$template = "{{ expression('1 == 1') }}";
- $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
+ $twig = new Environment(new ArrayLoader(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new ExpressionExtension());
$output = $twig->render('template');
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
index 1c8e5dcd490f7..4cbc55b46a66c 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
@@ -11,7 +11,9 @@
namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
-class StubFilesystemLoader extends \Twig_Loader_Filesystem
+use Twig\Loader\FilesystemLoader;
+
+class StubFilesystemLoader extends FilesystemLoader
{
protected function findTemplate($name, $throw = true)
{
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php
index 09ea0a1782ffc..562eec94595c3 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3HorizontalLayoutTest.php
@@ -19,6 +19,7 @@
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractBootstrap3HorizontalLayoutTest;
+use Twig\Environment;
class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest
{
@@ -48,7 +49,7 @@ protected function setUp()
__DIR__.'/Fixtures/templates/form',
));
- $environment = new \Twig_Environment($loader, array('strict_variables' => true));
+ $environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php
index b68386286593d..d8fa05812053c 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php
@@ -19,6 +19,7 @@
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest;
+use Twig\Environment;
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
{
@@ -48,7 +49,7 @@ protected function setUp()
__DIR__.'/Fixtures/templates/form',
));
- $environment = new \Twig_Environment($loader, array('strict_variables' => true));
+ $environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
index ab20cb286cb33..8734208607c6d 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
@@ -20,6 +20,7 @@
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
+use Twig\Environment;
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
{
@@ -49,7 +50,7 @@ protected function setUp()
__DIR__.'/Fixtures/templates/form',
));
- $environment = new \Twig_Environment($loader, array('strict_variables' => true));
+ $environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addGlobal('global', '');
// the value can be any template that exists
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
index 83c9fc72711d0..fc35b8f6e20de 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
@@ -19,6 +19,7 @@
use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
+use Twig\Environment;
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
{
@@ -48,7 +49,7 @@ protected function setUp()
__DIR__.'/Fixtures/templates/form',
));
- $environment = new \Twig_Environment($loader, array('strict_variables' => true));
+ $environment = new Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addGlobal('global', '');
$environment->addExtension($this->extension);
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
index 9f62ee02ad358..a0221393ce91b 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
@@ -16,11 +16,13 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
+use Twig\Environment;
+use Twig\Loader\ArrayLoader;
class HttpKernelExtensionTest extends TestCase
{
/**
- * @expectedException \Twig_Error_Runtime
+ * @expectedException \Twig\Error\RuntimeError
*/
public function testFragmentWithError()
{
@@ -74,8 +76,8 @@ protected function getFragmentHandler($return)
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
{
- $loader = new \Twig_Loader_Array(array('index' => $template));
- $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
+ $loader = new ArrayLoader(array('index' => $template));
+ $twig = new Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new HttpKernelExtension($renderer));
return $twig->render('index');
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
index 5fa4e9cd36b1c..fdff039851228 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
@@ -13,6 +13,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
+use Twig\Environment;
+use Twig\Node\Expression\FilterExpression;
+use Twig\Source;
class RoutingExtensionTest extends TestCase
{
@@ -21,12 +24,12 @@ class RoutingExtensionTest extends TestCase
*/
public function testEscaping($template, $mustBeEscaped)
{
- $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
+ $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new RoutingExtension($this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock()));
- $nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, '')));
+ $nodes = $twig->parse($twig->tokenize(new Source($template, '')));
- $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
+ $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof FilterExpression);
}
public function getEscapingTemplates()
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php
index 86a4fcbe32269..7bc4eed6ab3e1 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php
@@ -13,11 +13,14 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
+use Twig\Environment;
+use Twig\Error\RuntimeError;
+use Twig\Loader\ArrayLoader;
class StopwatchExtensionTest extends TestCase
{
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testFailIfStoppingWrongEvent()
{
@@ -29,12 +32,12 @@ public function testFailIfStoppingWrongEvent()
*/
public function testTiming($template, $events)
{
- $twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
+ $twig = new Environment(new ArrayLoader(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
$twig->addExtension(new StopwatchExtension($this->getStopwatch($events)));
try {
$nodes = $twig->render('template');
- } catch (\Twig_Error_Runtime $e) {
+ } catch (RuntimeError $e) {
throw $e->getPrevious();
}
}
diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
index 446697d3dd8b2..36016d7f49bca 100644
--- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
@@ -16,6 +16,8 @@
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Loader\ArrayLoader;
+use Twig\Environment;
+use Twig\Loader\ArrayLoader as TwigArrayLoader;
class TranslationExtensionTest extends TestCase
{
@@ -33,8 +35,8 @@ public function testTrans($template, $expected, array $variables = array())
{
if ($expected != $this->getTemplate($template)->render($variables)) {
echo $template."\n";
- $loader = new \Twig_Loader_Array(array('index' => $template));
- $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
+ $loader = new TwigArrayLoader(array('index' => $template));
+ $twig = new Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n";
@@ -45,7 +47,7 @@ public function testTrans($template, $expected, array $variables = array())
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
*/
public function testTransUnknownKeyword()
@@ -54,7 +56,7 @@ public function testTransUnknownKeyword()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
*/
public function testTransComplexBody()
@@ -63,7 +65,7 @@ public function testTransComplexBody()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
*/
public function testTransChoiceComplexBody()
@@ -189,11 +191,11 @@ protected function getTemplate($template, $translator = null)
}
if (is_array($template)) {
- $loader = new \Twig_Loader_Array($template);
+ $loader = new TwigArrayLoader($template);
} else {
- $loader = new \Twig_Loader_Array(array('index' => $template));
+ $loader = new TwigArrayLoader(array('index' => $template));
}
- $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
+ $twig = new Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new TranslationExtension($translator));
return $twig->loadTemplate('index');
diff --git a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
index 93c8433c2894e..087596e242281 100644
--- a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
@@ -13,6 +13,10 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\DumpNode;
+use Twig\Compiler;
+use Twig\Environment;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\Node;
class DumpNodeTest extends TestCase
{
@@ -20,14 +24,14 @@ public function testNoVar()
{
$node = new DumpNode('bar', null, 7);
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $compiler = new \Twig_Compiler($env);
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
+ $compiler = new Compiler($env);
$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
$barvars = array();
foreach ($context as $barkey => $barval) {
- if (!$barval instanceof \Twig_Template) {
+ if (!$barval instanceof \Twig\Template) {
$barvars[$barkey] = $barval;
}
}
@@ -44,14 +48,14 @@ public function testIndented()
{
$node = new DumpNode('bar', null, 7);
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $compiler = new \Twig_Compiler($env);
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
+ $compiler = new Compiler($env);
$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
$barvars = array();
foreach ($context as $barkey => $barval) {
- if (!$barval instanceof \Twig_Template) {
+ if (!$barval instanceof \Twig\Template) {
$barvars[$barkey] = $barval;
}
}
@@ -66,13 +70,13 @@ public function testIndented()
public function testOneVar()
{
- $vars = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('foo', 7),
+ $vars = new Node(array(
+ new NameExpression('foo', 7),
));
$node = new DumpNode('bar', $vars, 7);
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $compiler = new \Twig_Compiler($env);
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
+ $compiler = new Compiler($env);
$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
@@ -81,9 +85,9 @@ public function testOneVar()
}
EOTXT;
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
- } elseif (PHP_VERSION_ID >= 50400) {
+ } elseif (\PHP_VERSION_ID >= 50400) {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
@@ -94,14 +98,14 @@ public function testOneVar()
public function testMultiVars()
{
- $vars = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('foo', 7),
- new \Twig_Node_Expression_Name('bar', 7),
+ $vars = new Node(array(
+ new NameExpression('foo', 7),
+ new NameExpression('bar', 7),
));
$node = new DumpNode('bar', $vars, 7);
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
- $compiler = new \Twig_Compiler($env);
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
+ $compiler = new Compiler($env);
$expected = <<<'EOTXT'
if ($this->env->isDebug()) {
@@ -114,9 +118,9 @@ public function testMultiVars()
EOTXT;
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
- } elseif (PHP_VERSION_ID >= 50400) {
+ } elseif (\PHP_VERSION_ID >= 50400) {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
diff --git a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
index 4202355594745..48bbdab98cf1b 100644
--- a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
@@ -13,15 +13,21 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\FormThemeNode;
+use Twig\Compiler;
+use Twig\Environment;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\Node;
class FormThemeTest extends TestCase
{
public function testConstructor()
{
- $form = new \Twig_Node_Expression_Name('form', 0);
- $resources = new \Twig_Node(array(
- new \Twig_Node_Expression_Constant('tpl1', 0),
- new \Twig_Node_Expression_Constant('tpl2', 0),
+ $form = new NameExpression('form', 0);
+ $resources = new Node(array(
+ new ConstantExpression('tpl1', 0),
+ new ConstantExpression('tpl2', 0),
));
$node = new FormThemeNode($form, $resources, 0);
@@ -32,17 +38,17 @@ public function testConstructor()
public function testCompile()
{
- $form = new \Twig_Node_Expression_Name('form', 0);
- $resources = new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant(0, 0),
- new \Twig_Node_Expression_Constant('tpl1', 0),
- new \Twig_Node_Expression_Constant(1, 0),
- new \Twig_Node_Expression_Constant('tpl2', 0),
+ $form = new NameExpression('form', 0);
+ $resources = new ArrayExpression(array(
+ new ConstantExpression(0, 0),
+ new ConstantExpression('tpl1', 0),
+ new ConstantExpression(1, 0),
+ new ConstantExpression('tpl2', 0),
), 0);
$node = new FormThemeNode($form, $resources, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -52,7 +58,7 @@ public function testCompile()
trim($compiler->compile($node)->getSource())
);
- $resources = new \Twig_Node_Expression_Constant('tpl1', 0);
+ $resources = new ConstantExpression('tpl1', 0);
$node = new FormThemeNode($form, $resources, 0);
@@ -67,11 +73,11 @@ public function testCompile()
protected function getVariableGetter($name)
{
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}
diff --git a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
index 69b987e83297f..a603576f30274 100644
--- a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
@@ -13,18 +13,25 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
+use Twig\Compiler;
+use Twig\Environment;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConditionalExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\Node;
class SearchAndRenderBlockNodeTest extends TestCase
{
public function testCompileWidget()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
));
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -37,17 +44,17 @@ public function testCompileWidget()
public function testCompileWidgetWithVariables()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant('foo', 0),
- new \Twig_Node_Expression_Constant('bar', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ArrayExpression(array(
+ new ConstantExpression('foo', 0),
+ new ConstantExpression('bar', 0),
), 0),
));
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -60,14 +67,14 @@ public function testCompileWidgetWithVariables()
public function testCompileLabelWithLabel()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Constant('my label', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConstantExpression('my label', 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -80,14 +87,14 @@ public function testCompileLabelWithLabel()
public function testCompileLabelWithNullLabel()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Constant(null, 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConstantExpression(null, 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@@ -102,14 +109,14 @@ public function testCompileLabelWithNullLabel()
public function testCompileLabelWithEmptyStringLabel()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Constant('', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConstantExpression('', 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@@ -124,13 +131,13 @@ public function testCompileLabelWithEmptyStringLabel()
public function testCompileLabelWithDefaultLabel()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -143,18 +150,18 @@ public function testCompileLabelWithDefaultLabel()
public function testCompileLabelWithAttributes()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Constant(null, 0),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant('foo', 0),
- new \Twig_Node_Expression_Constant('bar', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConstantExpression(null, 0),
+ new ArrayExpression(array(
+ new ConstantExpression('foo', 0),
+ new ConstantExpression('bar', 0),
), 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@@ -170,20 +177,20 @@ public function testCompileLabelWithAttributes()
public function testCompileLabelWithLabelAndAttributes()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Constant('value in argument', 0),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant('foo', 0),
- new \Twig_Node_Expression_Constant('bar', 0),
- new \Twig_Node_Expression_Constant('label', 0),
- new \Twig_Node_Expression_Constant('value in attributes', 0),
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConstantExpression('value in argument', 0),
+ new ArrayExpression(array(
+ new ConstantExpression('foo', 0),
+ new ConstantExpression('bar', 0),
+ new ConstantExpression('label', 0),
+ new ConstantExpression('value in attributes', 0),
), 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
$this->assertEquals(
sprintf(
@@ -196,22 +203,22 @@ public function testCompileLabelWithLabelAndAttributes()
public function testCompileLabelWithLabelThatEvaluatesToNull()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Conditional(
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConditionalExpression(
// if
- new \Twig_Node_Expression_Constant(true, 0),
+ new ConstantExpression(true, 0),
// then
- new \Twig_Node_Expression_Constant(null, 0),
+ new ConstantExpression(null, 0),
// else
- new \Twig_Node_Expression_Constant(null, 0),
+ new ConstantExpression(null, 0),
0
),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@@ -227,28 +234,28 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
{
- $arguments = new \Twig_Node(array(
- new \Twig_Node_Expression_Name('form', 0),
- new \Twig_Node_Expression_Conditional(
+ $arguments = new Node(array(
+ new NameExpression('form', 0),
+ new ConditionalExpression(
// if
- new \Twig_Node_Expression_Constant(true, 0),
+ new ConstantExpression(true, 0),
// then
- new \Twig_Node_Expression_Constant(null, 0),
+ new ConstantExpression(null, 0),
// else
- new \Twig_Node_Expression_Constant(null, 0),
+ new ConstantExpression(null, 0),
0
),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant('foo', 0),
- new \Twig_Node_Expression_Constant('bar', 0),
- new \Twig_Node_Expression_Constant('label', 0),
- new \Twig_Node_Expression_Constant('value in attributes', 0),
+ new ArrayExpression(array(
+ new ConstantExpression('foo', 0),
+ new ConstantExpression('bar', 0),
+ new ConstantExpression('label', 0),
+ new ConstantExpression('value in attributes', 0),
), 0),
));
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
- $compiler = new \Twig_Compiler(new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
+ $compiler = new Compiler(new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock()));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@@ -264,11 +271,11 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
protected function getVariableGetter($name)
{
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}
diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
index 683d47af27aea..c4d67fc962666 100644
--- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
@@ -13,6 +13,10 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\TransNode;
+use Twig\Compiler;
+use Twig\Environment;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\TextNode;
/**
* @author Asmir Mustafic
@@ -21,12 +25,12 @@ class TransNodeTest extends TestCase
{
public function testCompileStrict()
{
- $body = new \Twig_Node_Text('trans %var%', 0);
- $vars = new \Twig_Node_Expression_Name('foo', 0);
+ $body = new TextNode('trans %var%', 0);
+ $vars = new NameExpression('foo', 0);
$node = new TransNode($body, null, null, $vars);
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true));
- $compiler = new \Twig_Compiler($env);
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('strict_variables' => true));
+ $compiler = new Compiler($env);
$this->assertEquals(
sprintf(
@@ -40,11 +44,11 @@ public function testCompileStrict()
protected function getVariableGetterWithoutStrictCheck($name)
{
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}
@@ -53,15 +57,15 @@ protected function getVariableGetterWithoutStrictCheck($name)
protected function getVariableGetterWithStrictCheck($name)
{
- if (\Twig_Environment::MAJOR_VERSION >= 2) {
+ if (Environment::MAJOR_VERSION >= 2) {
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
}
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
}
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
}
diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
index da9f43a6c4e0e..eb4c9a83e86d7 100644
--- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php
@@ -14,6 +14,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
+use Twig\Environment;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Node;
class TranslationDefaultDomainNodeVisitorTest extends TestCase
{
@@ -21,9 +24,9 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
private static $domain = 'domain';
/** @dataProvider getDefaultDomainAssignmentTestData */
- public function testDefaultDomainAssignment(\Twig_Node $node)
+ public function testDefaultDomainAssignment(Node $node)
{
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag
@@ -47,9 +50,9 @@ public function testDefaultDomainAssignment(\Twig_Node $node)
}
/** @dataProvider getDefaultDomainAssignmentTestData */
- public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node)
+ public function testNewModuleWithoutDefaultDomainTag(Node $node)
{
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag
@@ -80,10 +83,10 @@ public function getDefaultDomainAssignmentTestData()
array(TwigNodeProvider::getTransTag(self::$message)),
// with named arguments
array(TwigNodeProvider::getTransFilter(self::$message, null, array(
- 'arguments' => new \Twig_Node_Expression_Array(array(), 0),
+ 'arguments' => new ArrayExpression(array(), 0),
))),
array(TwigNodeProvider::getTransChoiceFilter(self::$message), null, array(
- 'arguments' => new \Twig_Node_Expression_Array(array(), 0),
+ 'arguments' => new ArrayExpression(array(), 0),
)),
);
}
diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
index d12fff532aaa1..9c2d0ab9e40e5 100644
--- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php
@@ -13,13 +13,19 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
+use Twig\Environment;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\FilterExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Node\Node;
class TranslationNodeVisitorTest extends TestCase
{
/** @dataProvider getMessagesExtractionTestData */
- public function testMessagesExtraction(\Twig_Node $node, array $expectedMessages)
+ public function testMessagesExtraction(Node $node, array $expectedMessages)
{
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$visitor = new TranslationNodeVisitor();
$visitor->enable();
$visitor->enterNode($node, $env);
@@ -31,12 +37,12 @@ public function testMessageExtractionWithInvalidDomainNode()
{
$message = 'new key';
- $node = new \Twig_Node_Expression_Filter(
- new \Twig_Node_Expression_Constant($message, 0),
- new \Twig_Node_Expression_Constant('trans', 0),
- new \Twig_Node(array(
- new \Twig_Node_Expression_Array(array(), 0),
- new \Twig_Node_Expression_Name('variable', 0),
+ $node = new FilterExpression(
+ new ConstantExpression($message, 0),
+ new ConstantExpression('trans', 0),
+ new Node(array(
+ new ArrayExpression(array(), 0),
+ new NameExpression('variable', 0),
)),
0
);
diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
index 502cad38dec0b..49eac23e8aeda 100644
--- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
+++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
@@ -13,19 +13,26 @@
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
use Symfony\Bridge\Twig\Node\TransNode;
+use Twig\Node\BodyNode;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\FilterExpression;
+use Twig\Node\ModuleNode;
+use Twig\Node\Node;
+use Twig\Source;
class TwigNodeProvider
{
public static function getModule($content)
{
- return new \Twig_Node_Module(
- new \Twig_Node_Expression_Constant($content, 0),
+ return new ModuleNode(
+ new ConstantExpression($content, 0),
null,
- new \Twig_Node_Expression_Array(array(), 0),
- new \Twig_Node_Expression_Array(array(), 0),
- new \Twig_Node_Expression_Array(array(), 0),
+ new ArrayExpression(array(), 0),
+ new ArrayExpression(array(), 0),
+ new ArrayExpression(array(), 0),
null,
- new \Twig_Source('', '')
+ new Source('', '')
);
}
@@ -33,15 +40,15 @@ public static function getTransFilter($message, $domain = null, $arguments = nul
{
if (!$arguments) {
$arguments = $domain ? array(
- new \Twig_Node_Expression_Array(array(), 0),
- new \Twig_Node_Expression_Constant($domain, 0),
+ new ArrayExpression(array(), 0),
+ new ConstantExpression($domain, 0),
) : array();
}
- return new \Twig_Node_Expression_Filter(
- new \Twig_Node_Expression_Constant($message, 0),
- new \Twig_Node_Expression_Constant('trans', 0),
- new \Twig_Node($arguments),
+ return new FilterExpression(
+ new ConstantExpression($message, 0),
+ new ConstantExpression('trans', 0),
+ new Node($arguments),
0
);
}
@@ -50,16 +57,16 @@ public static function getTransChoiceFilter($message, $domain = null, $arguments
{
if (!$arguments) {
$arguments = $domain ? array(
- new \Twig_Node_Expression_Constant(0, 0),
- new \Twig_Node_Expression_Array(array(), 0),
- new \Twig_Node_Expression_Constant($domain, 0),
+ new ConstantExpression(0, 0),
+ new ArrayExpression(array(), 0),
+ new ConstantExpression($domain, 0),
) : array();
}
- return new \Twig_Node_Expression_Filter(
- new \Twig_Node_Expression_Constant($message, 0),
- new \Twig_Node_Expression_Constant('transchoice', 0),
- new \Twig_Node($arguments),
+ return new FilterExpression(
+ new ConstantExpression($message, 0),
+ new ConstantExpression('transchoice', 0),
+ new Node($arguments),
0
);
}
@@ -67,15 +74,15 @@ public static function getTransChoiceFilter($message, $domain = null, $arguments
public static function getTransTag($message, $domain = null)
{
return new TransNode(
- new \Twig_Node_Body(array(), array('data' => $message)),
- $domain ? new \Twig_Node_Expression_Constant($domain, 0) : null
+ new BodyNode(array(), array('data' => $message)),
+ $domain ? new ConstantExpression($domain, 0) : null
);
}
public static function getTransDefaultDomainTag($domain)
{
return new TransDefaultDomainNode(
- new \Twig_Node_Expression_Constant($domain, 0)
+ new ConstantExpression($domain, 0)
);
}
}
diff --git a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
index 8931be061f9d2..0972b15e23fdc 100644
--- a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
@@ -14,6 +14,12 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Node\FormThemeNode;
+use Twig\Environment;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Expression\ConstantExpression;
+use Twig\Node\Expression\NameExpression;
+use Twig\Parser;
+use Twig\Source;
class FormThemeTokenParserTest extends TestCase
{
@@ -22,10 +28,10 @@ class FormThemeTokenParserTest extends TestCase
*/
public function testCompile($source, $expected)
{
- $env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
+ $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new FormThemeTokenParser());
- $stream = $env->tokenize(new \Twig_Source($source, ''));
- $parser = new \Twig_Parser($env);
+ $stream = $env->tokenize(new Source($source, ''));
+ $parser = new Parser($env);
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
}
@@ -36,10 +42,10 @@ public function getTestsForFormTheme()
array(
'{% form_theme form "tpl1" %}',
new FormThemeNode(
- new \Twig_Node_Expression_Name('form', 1),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant(0, 1),
- new \Twig_Node_Expression_Constant('tpl1', 1),
+ new NameExpression('form', 1),
+ new ArrayExpression(array(
+ new ConstantExpression(0, 1),
+ new ConstantExpression('tpl1', 1),
), 1),
1,
'form_theme'
@@ -48,12 +54,12 @@ public function getTestsForFormTheme()
array(
'{% form_theme form "tpl1" "tpl2" %}',
new FormThemeNode(
- new \Twig_Node_Expression_Name('form', 1),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant(0, 1),
- new \Twig_Node_Expression_Constant('tpl1', 1),
- new \Twig_Node_Expression_Constant(1, 1),
- new \Twig_Node_Expression_Constant('tpl2', 1),
+ new NameExpression('form', 1),
+ new ArrayExpression(array(
+ new ConstantExpression(0, 1),
+ new ConstantExpression('tpl1', 1),
+ new ConstantExpression(1, 1),
+ new ConstantExpression('tpl2', 1),
), 1),
1,
'form_theme'
@@ -62,8 +68,8 @@ public function getTestsForFormTheme()
array(
'{% form_theme form with "tpl1" %}',
new FormThemeNode(
- new \Twig_Node_Expression_Name('form', 1),
- new \Twig_Node_Expression_Constant('tpl1', 1),
+ new NameExpression('form', 1),
+ new ConstantExpression('tpl1', 1),
1,
'form_theme'
),
@@ -71,10 +77,10 @@ public function getTestsForFormTheme()
array(
'{% form_theme form with ["tpl1"] %}',
new FormThemeNode(
- new \Twig_Node_Expression_Name('form', 1),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant(0, 1),
- new \Twig_Node_Expression_Constant('tpl1', 1),
+ new NameExpression('form', 1),
+ new ArrayExpression(array(
+ new ConstantExpression(0, 1),
+ new ConstantExpression('tpl1', 1),
), 1),
1,
'form_theme'
@@ -83,12 +89,12 @@ public function getTestsForFormTheme()
array(
'{% form_theme form with ["tpl1", "tpl2"] %}',
new FormThemeNode(
- new \Twig_Node_Expression_Name('form', 1),
- new \Twig_Node_Expression_Array(array(
- new \Twig_Node_Expression_Constant(0, 1),
- new \Twig_Node_Expression_Constant('tpl1', 1),
- new \Twig_Node_Expression_Constant(1, 1),
- new \Twig_Node_Expression_Constant('tpl2', 1),
+ new NameExpression('form', 1),
+ new ArrayExpression(array(
+ new ConstantExpression(0, 1),
+ new ConstantExpression('tpl1', 1),
+ new ConstantExpression(1, 1),
+ new ConstantExpression('tpl2', 1),
), 1),
1,
'form_theme'
diff --git a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
index 0b1fb28b0e10c..013598a40b17f 100644
--- a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
@@ -15,6 +15,9 @@
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Translation\TwigExtractor;
use Symfony\Component\Translation\MessageCatalogue;
+use Twig\Environment;
+use Twig\Error\Error;
+use Twig\Loader\ArrayLoader;
class TwigExtractorTest extends TestCase
{
@@ -23,8 +26,8 @@ class TwigExtractorTest extends TestCase
*/
public function testExtract($template, $messages)
{
- $loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock();
- $twig = new \Twig_Environment($loader, array(
+ $loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
+ $twig = new Environment($loader, array(
'strict_variables' => true,
'debug' => true,
'cache' => false,
@@ -73,19 +76,19 @@ public function getExtractData()
}
/**
- * @expectedException \Twig_Error
+ * @expectedException \Twig\Error\Error
* @dataProvider resourcesWithSyntaxErrorsProvider
*/
public function testExtractSyntaxError($resources)
{
- $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
+ $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
$extractor = new TwigExtractor($twig);
try {
$extractor->extract($resources, new MessageCatalogue('en'));
- } catch (\Twig_Error $e) {
+ } catch (Error $e) {
if (method_exists($e, 'getSourceContext')) {
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
$this->assertSame(1, $e->getLine());
@@ -114,8 +117,8 @@ public function resourcesWithSyntaxErrorsProvider()
*/
public function testExtractWithFiles($resource)
{
- $loader = new \Twig_Loader_Array(array());
- $twig = new \Twig_Environment($loader, array(
+ $loader = new ArrayLoader(array());
+ $twig = new Environment($loader, array(
'strict_variables' => true,
'debug' => true,
'cache' => false,
diff --git a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php
index e2082df3dd75b..a74c59e8d28c9 100644
--- a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php
+++ b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php
@@ -14,6 +14,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Component\Templating\TemplateReference;
+use Twig\Environment;
+use Twig\Loader\ArrayLoader;
class TwigEngineTest extends TestCase
{
@@ -21,7 +23,7 @@ public function testExistsWithTemplateInstances()
{
$engine = $this->getTwig();
- $this->assertTrue($engine->exists($this->getMockForAbstractClass('Twig_Template', array(), '', false)));
+ $this->assertTrue($engine->exists($this->getMockForAbstractClass('Twig\Template', array(), '', false)));
}
public function testExistsWithNonExistentTemplates()
@@ -57,7 +59,7 @@ public function testRender()
}
/**
- * @expectedException \Twig_Error_Syntax
+ * @expectedException \Twig\Error\SyntaxError
*/
public function testRenderWithError()
{
@@ -68,7 +70,7 @@ public function testRenderWithError()
protected function getTwig()
{
- $twig = new \Twig_Environment(new \Twig_Loader_Array(array(
+ $twig = new Environment(new ArrayLoader(array(
'index' => 'foo',
'error' => '{{ foo }',
)));
diff --git a/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php
index 269ead64f5d40..7cdbb77b4349b 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/DumpTokenParser.php
@@ -12,6 +12,8 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\DumpNode;
+use Twig\Token;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Token Parser for the 'dump' tag.
@@ -25,18 +27,18 @@
*
* @author Julien Galenski
*/
-class DumpTokenParser extends \Twig_TokenParser
+class DumpTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*/
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$values = null;
- if (!$this->parser->getStream()->test(\Twig_Token::BLOCK_END_TYPE)) {
+ if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
}
- $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
}
diff --git a/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php
index daf87824e7b21..12c2541851e63 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/FormThemeTokenParser.php
@@ -12,39 +12,43 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\FormThemeNode;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Node;
+use Twig\Token;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Token Parser for the 'form_theme' tag.
*
* @author Fabien Potencier
*/
-class FormThemeTokenParser extends \Twig_TokenParser
+class FormThemeTokenParser extends AbstractTokenParser
{
/**
* Parses a token and returns a node.
*
- * @param \Twig_Token $token A Twig_Token instance
+ * @param Token $token
*
- * @return \Twig_Node A Twig_Node instance
+ * @return Node
*/
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$form = $this->parser->getExpressionParser()->parseExpression();
- if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
+ if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();
$resources = $this->parser->getExpressionParser()->parseExpression();
} else {
- $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
+ $resources = new ArrayExpression(array(), $stream->getCurrent()->getLine());
do {
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
- } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
+ } while (!$stream->test(Token::BLOCK_END_TYPE));
}
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
return new FormThemeNode($form, $resources, $lineno, $this->getTag());
}
diff --git a/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php
index 2983e4cb6b03b..82c58d40bbf8d 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/StopwatchTokenParser.php
@@ -12,13 +12,16 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\StopwatchNode;
+use Twig\Node\Expression\AssignNameExpression;
+use Twig\Token;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Token Parser for the stopwatch tag.
*
* @author Wouter J
*/
-class StopwatchTokenParser extends \Twig_TokenParser
+class StopwatchTokenParser extends AbstractTokenParser
{
protected $stopwatchIsAvailable;
@@ -27,7 +30,7 @@ public function __construct($stopwatchIsAvailable)
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
}
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
@@ -35,20 +38,20 @@ public function parse(\Twig_Token $token)
// {% stopwatch 'bar' %}
$name = $this->parser->getExpressionParser()->parseExpression();
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
// {% endstopwatch %}
$body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true);
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
if ($this->stopwatchIsAvailable) {
- return new StopwatchNode($name, $body, new \Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag());
+ return new StopwatchNode($name, $body, new AssignNameExpression($this->parser->getVarName(), $token->getLine()), $lineno, $this->getTag());
}
return $body;
}
- public function decideStopwatchEnd(\Twig_Token $token)
+ public function decideStopwatchEnd(Token $token)
{
return $token->test('endstopwatch');
}
diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
index fa61a2f1486c5..2b4a9f3fc4636 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
@@ -12,6 +12,12 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\TransNode;
+use Twig\Error\SyntaxError;
+use Twig\Node\Expression\AbstractExpression;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Node;
+use Twig\Node\TextNode;
+use Twig\Token;
/**
* Token Parser for the 'transchoice' tag.
@@ -23,18 +29,18 @@ class TransChoiceTokenParser extends TransTokenParser
/**
* Parses a token and returns a node.
*
- * @param \Twig_Token $token A Twig_Token instance
+ * @param Token $token
*
- * @return \Twig_Node A Twig_Node instance
+ * @return Node
*
- * @throws \Twig_Error_Syntax
+ * @throws SyntaxError
*/
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- $vars = new \Twig_Node_Expression_Array(array(), $lineno);
+ $vars = new ArrayExpression(array(), $lineno);
$count = $this->parser->getExpressionParser()->parseExpression();
@@ -59,15 +65,15 @@ public function parse(\Twig_Token $token)
$locale = $this->parser->getExpressionParser()->parseExpression();
}
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
- if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
- throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
+ if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
+ throw new SyntaxError('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
}
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
}
diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php
index 09832ea972d91..4096a011a300d 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/TransDefaultDomainTokenParser.php
@@ -12,26 +12,29 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
+use Twig\Node\Node;
+use Twig\Token;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Token Parser for the 'trans_default_domain' tag.
*
* @author Fabien Potencier
*/
-class TransDefaultDomainTokenParser extends \Twig_TokenParser
+class TransDefaultDomainTokenParser extends AbstractTokenParser
{
/**
* Parses a token and returns a node.
*
- * @param \Twig_Token $token A Twig_Token instance
+ * @param Token $token
*
- * @return \Twig_Node A Twig_Node instance
+ * @return Node
*/
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
- $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
+ $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
return new TransDefaultDomainNode($expr, $token->getLine(), $this->getTag());
}
diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
index 4c8e7d3eeea38..848a080710fa1 100644
--- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
+++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
@@ -12,32 +12,39 @@
namespace Symfony\Bridge\Twig\TokenParser;
use Symfony\Bridge\Twig\Node\TransNode;
+use Twig\Error\SyntaxError;
+use Twig\Node\Expression\AbstractExpression;
+use Twig\Node\Expression\ArrayExpression;
+use Twig\Node\Node;
+use Twig\Node\TextNode;
+use Twig\Token;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Token Parser for the 'trans' tag.
*
* @author Fabien Potencier
*/
-class TransTokenParser extends \Twig_TokenParser
+class TransTokenParser extends AbstractTokenParser
{
/**
* Parses a token and returns a node.
*
- * @param \Twig_Token $token A Twig_Token instance
+ * @param Token $token
*
- * @return \Twig_Node A Twig_Node instance
+ * @return Node
*
- * @throws \Twig_Error_Syntax
+ * @throws SyntaxError
*/
- public function parse(\Twig_Token $token)
+ public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
- $vars = new \Twig_Node_Expression_Array(array(), $lineno);
+ $vars = new ArrayExpression(array(), $lineno);
$domain = null;
$locale = null;
- if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
+ if (!$stream->test(Token::BLOCK_END_TYPE)) {
if ($stream->test('with')) {
// {% trans with vars %}
$stream->next();
@@ -54,20 +61,20 @@ public function parse(\Twig_Token $token)
// {% trans into "fr" %}
$stream->next();
$locale = $this->parser->getExpressionParser()->parseExpression();
- } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
- throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
+ } elseif (!$stream->test(Token::BLOCK_END_TYPE)) {
+ throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
}
}
// {% trans %}message{% endtrans %}
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
- if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
- throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
+ if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
+ throw new SyntaxError('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
}
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Token::BLOCK_END_TYPE);
return new TransNode($body, $domain, null, $vars, $locale, $lineno, $this->getTag());
}
diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
index 35995dbd64518..bd35fe5a8b1eb 100644
--- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
+++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
@@ -16,6 +16,9 @@
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\MessageCatalogue;
+use Twig\Environment;
+use Twig\Error\Error;
+use Twig\Source;
/**
* TwigExtractor extracts translation messages from a twig template.
@@ -42,11 +45,11 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
/**
* The twig environment.
*
- * @var \Twig_Environment
+ * @var Environment
*/
private $twig;
- public function __construct(\Twig_Environment $twig)
+ public function __construct(Environment $twig)
{
$this->twig = $twig;
}
@@ -60,12 +63,12 @@ public function extract($resource, MessageCatalogue $catalogue)
foreach ($files as $file) {
try {
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
- } catch (\Twig_Error $e) {
+ } catch (Error $e) {
if ($file instanceof \SplFileInfo) {
$path = $file->getRealPath() ?: $file->getPathname();
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
if (method_exists($e, 'setSourceContext')) {
- $e->setSourceContext(new \Twig_Source('', $name, $path));
+ $e->setSourceContext(new Source('', $name, $path));
} else {
$e->setTemplateName($name);
}
@@ -89,7 +92,7 @@ protected function extractTemplate($template, MessageCatalogue $catalogue)
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
$visitor->enable();
- $this->twig->parse($this->twig->tokenize(new \Twig_Source($template, '')));
+ $this->twig->parse($this->twig->tokenize(new Source($template, '')));
foreach ($visitor->getMessages() as $message) {
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
diff --git a/src/Symfony/Bridge/Twig/TwigEngine.php b/src/Symfony/Bridge/Twig/TwigEngine.php
index 760461b5be578..bc0a4fecc9af5 100644
--- a/src/Symfony/Bridge/Twig/TwigEngine.php
+++ b/src/Symfony/Bridge/Twig/TwigEngine.php
@@ -15,6 +15,11 @@
use Symfony\Component\Templating\StreamingEngineInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
+use Twig\Environment;
+use Twig\Error\Error;
+use Twig\Error\LoaderError;
+use Twig\Loader\ExistsLoaderInterface;
+use Twig\Template;
/**
* This engine knows how to render Twig templates.
@@ -26,13 +31,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
protected $environment;
protected $parser;
- /**
- * Constructor.
- *
- * @param \Twig_Environment $environment A \Twig_Environment instance
- * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
- */
- public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser)
+ public function __construct(Environment $environment, TemplateNameParserInterface $parser)
{
$this->environment = $environment;
$this->parser = $parser;
@@ -41,9 +40,9 @@ public function __construct(\Twig_Environment $environment, TemplateNameParserIn
/**
* {@inheritdoc}
*
- * It also supports \Twig_Template as name parameter.
+ * It also supports Template as name parameter.
*
- * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template
+ * @throws Error if something went wrong like a thrown exception while rendering the template
*/
public function render($name, array $parameters = array())
{
@@ -53,9 +52,9 @@ public function render($name, array $parameters = array())
/**
* {@inheritdoc}
*
- * It also supports \Twig_Template as name parameter.
+ * It also supports Template as name parameter.
*
- * @throws \Twig_Error if something went wrong like a thrown exception while rendering the template
+ * @throws Error if something went wrong like a thrown exception while rendering the template
*/
public function stream($name, array $parameters = array())
{
@@ -65,25 +64,25 @@ public function stream($name, array $parameters = array())
/**
* {@inheritdoc}
*
- * It also supports \Twig_Template as name parameter.
+ * It also supports Template as name parameter.
*/
public function exists($name)
{
- if ($name instanceof \Twig_Template) {
+ if ($name instanceof Template) {
return true;
}
$loader = $this->environment->getLoader();
- if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
+ if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists((string) $name);
}
try {
// cast possible TemplateReferenceInterface to string because the
- // EngineInterface supports them but Twig_LoaderInterface does not
+ // EngineInterface supports them but LoaderInterface does not
$loader->getSourceContext((string) $name)->getCode();
- } catch (\Twig_Error_Loader $e) {
+ } catch (LoaderError $e) {
return false;
}
@@ -93,11 +92,11 @@ public function exists($name)
/**
* {@inheritdoc}
*
- * It also supports \Twig_Template as name parameter.
+ * It also supports Template as name parameter.
*/
public function supports($name)
{
- if ($name instanceof \Twig_Template) {
+ if ($name instanceof Template) {
return true;
}
@@ -109,22 +108,22 @@ public function supports($name)
/**
* Loads the given template.
*
- * @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of
- * TemplateReferenceInterface or \Twig_Template
+ * @param string|TemplateReferenceInterface|Template $name A template name or an instance of
+ * TemplateReferenceInterface or Template
*
- * @return \Twig_Template A \Twig_Template instance
+ * @return Template
*
* @throws \InvalidArgumentException if the template does not exist
*/
protected function load($name)
{
- if ($name instanceof \Twig_Template) {
+ if ($name instanceof Template) {
return $name;
}
try {
return $this->environment->loadTemplate((string) $name);
- } catch (\Twig_Error_Loader $e) {
+ } catch (LoaderError $e) {
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
}
diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json
index 7c022313667d6..a711b77d7987c 100644
--- a/src/Symfony/Bridge/Twig/composer.json
+++ b/src/Symfony/Bridge/Twig/composer.json
@@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.9",
- "twig/twig": "~1.28|~2.0"
+ "twig/twig": "~1.34|~2.4"
},
"require-dev": {
"symfony/asset": "~2.7|~3.0.0",
diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php
index 223f0216ba9ad..33f94650449fb 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php
+++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php
@@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Translation\TranslatorInterface;
@@ -22,11 +23,24 @@
*/
class TranslationsCacheWarmer implements CacheWarmerInterface
{
+ private $container;
private $translator;
- public function __construct(TranslatorInterface $translator)
+ /**
+ * TranslationsCacheWarmer constructor.
+ *
+ * @param ContainerInterface|TranslatorInterface $container
+ */
+ public function __construct($container)
{
- $this->translator = $translator;
+ // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
+ if ($container instanceof ContainerInterface) {
+ $this->container = $container;
+ } elseif ($container instanceof TranslatorInterface) {
+ $this->translator = $container;
+ } else {
+ throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument.', __CLASS__));
+ }
}
/**
@@ -34,6 +48,10 @@ public function __construct(TranslatorInterface $translator)
*/
public function warmUp($cacheDir)
{
+ if (null === $this->translator) {
+ $this->translator = $this->container->get('translator');
+ }
+
if ($this->translator instanceof WarmableInterface) {
$this->translator->warmUp($cacheDir);
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php
index 3e1c324f00203..c5f9ee0ecd21d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php
@@ -23,7 +23,7 @@ abstract class ServerCommand extends ContainerAwareCommand
*/
public function isEnabled()
{
- if (PHP_VERSION_ID < 50400 || defined('HHVM_VERSION')) {
+ if (\PHP_VERSION_ID < 50400 || defined('HHVM_VERSION')) {
return false;
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml
index ea85f517aa399..14226ba93083f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml
@@ -159,7 +159,7 @@
-
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php
index cdf19e3ada807..06071e51b276c 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php
@@ -154,7 +154,7 @@ public function fileExcerpt($file, $line)
*/
public function formatFile($file, $line, $text = null)
{
- if (PHP_VERSION_ID >= 50400) {
+ if (\PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php
index a0cac9a908b24..6d32a37fd0ec9 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php
@@ -72,8 +72,8 @@ private function getContainer()
;
$loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader')
- ->disableOriginalConstructor()
- ->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php
index db533c09742ba..cd15b8c5e82fc 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php
@@ -76,8 +76,8 @@ private function getContainer()
;
$loader = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader')
- ->disableOriginalConstructor()
- ->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
index 8c9fcd507eb30..79eee03302f93 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
@@ -161,7 +161,7 @@ public function testdenyAccessUnlessGranted()
public function testRenderViewTwig()
{
- $twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
+ $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
@@ -177,7 +177,7 @@ public function testRenderViewTwig()
public function testRenderTwig()
{
- $twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
+ $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
@@ -193,7 +193,7 @@ public function testRenderTwig()
public function testStreamTwig()
{
- $twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
+ $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->at(0))->method('has')->will($this->returnValue(false));
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php
index 04e6447ee93ea..6afb5e3203f28 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php
@@ -22,7 +22,7 @@ class TemplateControllerTest extends TestCase
{
public function testTwig()
{
- $twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
+ $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php
index cc85cdb02acb2..5fca1cc8b4674 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragment/LegacyContainerAwareHIncludeFragmentRendererTest.php
@@ -25,7 +25,7 @@ public function testRender()
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container->expects($this->once())
->method('get')
- ->will($this->returnValue($this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock()))
+ ->will($this->returnValue($this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock()))
;
$renderer = new ContainerAwareHIncludeFragmentRenderer($container);
$renderer->render('/', Request::create('/'));
diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php
index 97c94fdd14bf9..70658f67232d3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php
@@ -85,7 +85,7 @@ public function extract($resource, MessageCatalogue $catalog)
foreach ($files as $file) {
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
- if (PHP_VERSION_ID >= 70000) {
+ if (\PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json
index 8c35dc3bfd66e..b00704d7c5363 100644
--- a/src/Symfony/Bundle/FrameworkBundle/composer.json
+++ b/src/Symfony/Bundle/FrameworkBundle/composer.json
@@ -25,7 +25,7 @@
"symfony/event-dispatcher": "~2.8|~3.0.0",
"symfony/finder": "^2.0.5|~3.0.0",
"symfony/http-foundation": "~2.7",
- "symfony/http-kernel": "^2.8.18",
+ "symfony/http-kernel": "^2.8.22",
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "~2.3|~3.0.0",
"symfony/routing": "^2.8.17",
@@ -51,7 +51,7 @@
"symfony/yaml": "^2.0.5|~3.0.0",
"symfony/property-info": "~2.8|~3.0.0",
"phpdocumentor/reflection": "^1.0.7",
- "twig/twig": "~1.23|~2.0",
+ "twig/twig": "~1.34|~2.4",
"sensio/framework-extra-bundle": "^3.0.2"
},
"conflict": {
diff --git a/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php b/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php
index d1eae0ef20487..40c931795f659 100644
--- a/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php
+++ b/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php
@@ -14,6 +14,8 @@
@trigger_error('The '.__NAMESPACE__.'\LogoutUrlExtension class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.', E_USER_DEPRECATED);
use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* LogoutUrlHelper provides generator functions for the logout URL to Twig.
@@ -22,7 +24,7 @@
*
* @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.
*/
-class LogoutUrlExtension extends \Twig_Extension
+class LogoutUrlExtension extends AbstractExtension
{
private $helper;
@@ -37,8 +39,8 @@ public function __construct(LogoutUrlHelper $helper)
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('logout_url', array($this, 'getLogoutUrl')),
- new \Twig_SimpleFunction('logout_path', array($this, 'getLogoutPath')),
+ new TwigFunction('logout_url', array($this, 'getLogoutUrl')),
+ new TwigFunction('logout_path', array($this, 'getLogoutPath')),
);
}
diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json
index c6a42f162e2e4..34117bff7cb6e 100644
--- a/src/Symfony/Bundle/SecurityBundle/composer.json
+++ b/src/Symfony/Bundle/SecurityBundle/composer.json
@@ -37,7 +37,7 @@
"symfony/yaml": "^2.0.5|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"doctrine/doctrine-bundle": "~1.2",
- "twig/twig": "~1.28|~2.0"
+ "twig/twig": "~1.34|~2.4"
},
"autoload": {
"psr-4": { "Symfony\\Bundle\\SecurityBundle\\": "" },
diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php
index 9eea901f6dde4..89f8d701cd83f 100644
--- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php
+++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php
@@ -16,6 +16,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
use Symfony\Component\Templating\TemplateReference;
+use Twig\Error\Error;
/**
* Generates the Twig cache for all templates.
@@ -76,7 +77,7 @@ public function warmUp($cacheDir)
try {
$twig->loadTemplate($template);
- } catch (\Twig_Error $e) {
+ } catch (Error $e) {
// problem during compilation, give up
}
}
diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php
index aefb5c7296b97..9a60a92e85375 100644
--- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php
+++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php
@@ -11,7 +11,10 @@
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
+use Twig\Environment;
+use Twig\Error\Error;
/**
* Generates the Twig cache for all templates.
@@ -20,12 +23,27 @@
*/
class TemplateCacheWarmer implements CacheWarmerInterface
{
+ private $container;
private $twig;
private $iterator;
- public function __construct(\Twig_Environment $twig, \Traversable $iterator)
+ /**
+ * TemplateCacheWarmer constructor.
+ *
+ * @param ContainerInterface|Environment $container
+ * @param \Traversable $iterator
+ */
+ public function __construct($container, \Traversable $iterator)
{
- $this->twig = $twig;
+ // As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
+ if ($container instanceof ContainerInterface) {
+ $this->container = $container;
+ } elseif ($container instanceof Environment) {
+ $this->twig = $container;
+ } else {
+ throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Environment as first argument.', __CLASS__));
+ }
+
$this->iterator = $iterator;
}
@@ -34,10 +52,14 @@ public function __construct(\Twig_Environment $twig, \Traversable $iterator)
*/
public function warmUp($cacheDir)
{
+ if (null === $this->twig) {
+ $this->twig = $this->container->get('twig');
+ }
+
foreach ($this->iterator as $template) {
try {
$this->twig->loadTemplate($template);
- } catch (\Twig_Error $e) {
+ } catch (Error $e) {
// problem during compilation, give up
// might be a syntax error or a non-Twig template
}
diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
index 1fcfbd94027cc..fafe49d5ff585 100644
--- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
+++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
@@ -15,6 +15,9 @@
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
+use Twig\Environment;
+use Twig\Error\LoaderError;
+use Twig\Loader\ExistsLoaderInterface;
/**
* ExceptionController renders error or exception pages for a given
@@ -32,7 +35,7 @@ class ExceptionController
*/
protected $debug;
- public function __construct(\Twig_Environment $twig, $debug)
+ public function __construct(Environment $twig, $debug)
{
$this->twig = $twig;
$this->debug = $debug;
@@ -129,7 +132,7 @@ protected function templateExists($template)
$template = (string) $template;
$loader = $this->twig->getLoader();
- if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
+ if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists($template);
}
@@ -137,7 +140,7 @@ protected function templateExists($template)
$loader->getSourceContext($template)->getCode();
return true;
- } catch (\Twig_Error_Loader $e) {
+ } catch (LoaderError $e) {
}
return false;
diff --git a/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php b/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php
index e09479a2845ff..40f209999a635 100644
--- a/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php
+++ b/src/Symfony/Bundle/TwigBundle/Debug/TimedTwigEngine.php
@@ -17,6 +17,7 @@
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Config\FileLocatorInterface;
+use Twig\Environment;
/**
* Times the time spent to render a template.
@@ -29,15 +30,7 @@ class TimedTwigEngine extends TwigEngine
{
protected $stopwatch;
- /**
- * Constructor.
- *
- * @param \Twig_Environment $environment A \Twig_Environment instance
- * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
- * @param FileLocatorInterface $locator A FileLocatorInterface instance
- * @param Stopwatch $stopwatch A Stopwatch instance
- */
- public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch)
+ public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch)
{
parent::__construct($environment, $parser, $locator);
diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
index 008f9b7e769dd..1c27fe1c04af4 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
@@ -170,7 +170,7 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
->variableNode('autoescape')->defaultValue('name')->end()
->scalarNode('autoescape_service')->defaultNull()->end()
->scalarNode('autoescape_service_method')->defaultNull()->end()
- ->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end()
+ ->scalarNode('base_template_class')->example('Twig\Template')->cannotBeEmpty()->end()
->scalarNode('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php
index bf37559b9920c..1612b6eb5fec2 100644
--- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php
+++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configurator/EnvironmentConfigurator.php
@@ -11,6 +11,11 @@
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Configurator;
+use Twig\Environment;
+
+// BC/FC with namespaced Twig
+class_exists('Twig\Environment');
+
/**
* Twig environment configurator.
*
@@ -35,14 +40,14 @@ public function __construct($dateFormat, $intervalFormat, $timezone, $decimals,
$this->thousandsSeparator = $thousandsSeparator;
}
- public function configure(\Twig_Environment $environment)
+ public function configure(Environment $environment)
{
- $environment->getExtension('Twig_Extension_Core')->setDateFormat($this->dateFormat, $this->intervalFormat);
+ $environment->getExtension('Twig\Extension\CoreExtension')->setDateFormat($this->dateFormat, $this->intervalFormat);
if (null !== $this->timezone) {
- $environment->getExtension('Twig_Extension_Core')->setTimezone($this->timezone);
+ $environment->getExtension('Twig\Extension\CoreExtension')->setTimezone($this->timezone);
}
- $environment->getExtension('Twig_Extension_Core')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator);
+ $environment->getExtension('Twig\Extension\CoreExtension')->setNumberFormat($this->decimals, $this->decimalPoint, $this->thousandsSeparator);
}
}
diff --git a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
index 8b4759ea270a8..5fee94d07c099 100644
--- a/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
+++ b/src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
@@ -14,6 +14,8 @@
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
+use Twig\Extension\AbstractExtension;
+use Twig\TokenParser\AbstractTokenParser;
/**
* Twig extension for Symfony actions helper.
@@ -22,7 +24,7 @@
*
* @deprecated since version 2.2, to be removed in 3.0.
*/
-class ActionsExtension extends \Twig_Extension
+class ActionsExtension extends AbstractExtension
{
private $handler;
@@ -69,7 +71,7 @@ public function renderUri($uri, array $options = array())
/**
* Returns the token parser instance to add to the existing list.
*
- * @return array An array of \Twig_TokenParser instances
+ * @return AbstractTokenParser[]
*/
public function getTokenParsers()
{
diff --git a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
index 976086920e07b..892e9cc739012 100644
--- a/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
+++ b/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
@@ -11,10 +11,12 @@
namespace Symfony\Bundle\TwigBundle\Extension;
+@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED);
+
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\RequestContext;
-
-@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED);
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
/**
* Twig extension for Symfony assets helper.
@@ -23,7 +25,7 @@
*
* @deprecated since 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\AssetExtension instead.
*/
-class AssetsExtension extends \Twig_Extension
+class AssetsExtension extends AbstractExtension
{
private $container;
private $context;
@@ -42,8 +44,8 @@ public function __construct(ContainerInterface $container, RequestContext $reque
public function getFunctions()
{
return array(
- new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
- new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion')),
+ new TwigFunction('asset', array($this, 'getAssetUrl')),
+ new TwigFunction('assets_version', array($this, 'getAssetsVersion')),
);
}
diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
index 53fe300e29a62..68a7b4560c95d 100644
--- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
+++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
@@ -14,6 +14,8 @@
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
+use Twig\Error\LoaderError;
+use Twig\Loader\FilesystemLoader as BaseFilesystemLoader;
/**
* FilesystemLoader extends the default Twig filesystem loader
@@ -21,7 +23,7 @@
*
* @author Fabien Potencier
*/
-class FilesystemLoader extends \Twig_Loader_Filesystem
+class FilesystemLoader extends BaseFilesystemLoader
{
protected $locator;
protected $parser;
@@ -58,11 +60,11 @@ public function exists($name)
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
- * @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
+ * @param bool $throw When true, a LoaderError exception will be thrown if a template could not be found
*
* @return string The path to the template file
*
- * @throws \Twig_Error_Loader if the template could not be found
+ * @throws LoaderError if the template could not be found
*/
protected function findTemplate($template, $throw = true)
{
@@ -76,7 +78,7 @@ protected function findTemplate($template, $throw = true)
$previous = null;
try {
$file = parent::findTemplate($logicalName);
- } catch (\Twig_Error_Loader $e) {
+ } catch (LoaderError $e) {
$twigLoaderException = $e;
// for BC
diff --git a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php
index 4e3b12dae1978..e9a378f399139 100644
--- a/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php
+++ b/src/Symfony/Bundle/TwigBundle/Node/RenderNode.php
@@ -11,6 +11,10 @@
namespace Symfony\Bundle\TwigBundle\Node;
+use Twig\Compiler;
+use Twig\Node\Expression\AbstractExpression;
+use Twig\Node\Node;
+
/**
* Represents a render node.
*
@@ -18,19 +22,14 @@
*
* @deprecated since version 2.2, to be removed in 3.0.
*/
-class RenderNode extends \Twig_Node
+class RenderNode extends Node
{
- public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $options, $lineno, $tag = null)
+ public function __construct(AbstractExpression $expr, AbstractExpression $options, $lineno, $tag = null)
{
parent::__construct(array('expr' => $expr, 'options' => $options), array(), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param \Twig_Compiler $compiler A Twig_Compiler instance
- */
- public function compile(\Twig_Compiler $compiler)
+ public function compile(Compiler $compiler)
{
$compiler
->addDebugInfo($this)
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
index 4ea5ecf0c2031..541ac4a559738 100644
--- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
@@ -5,9 +5,9 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
- Twig_Environment
+ Twig\Environment
Symfony\Bundle\TwigBundle\Loader\FilesystemLoader
- Twig_Loader_Chain
+ Twig\Loader\ChainLoader
Symfony\Bundle\TwigBundle\TwigEngine
Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer
Symfony\Bridge\Twig\Extension\TranslationExtension
@@ -60,11 +60,11 @@
-
+
-
+
@@ -76,7 +76,7 @@
-
+
@@ -130,7 +130,7 @@
-
+