diff --git a/composer.json b/composer.json index 13ad974465..f91e8fc1a8 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "php": ">=5.5.9", "doctrine/common": "~2.4", "fig/link-util": "^1.0", - "twig/twig": "~1.32|~2.2", + "twig/twig": "~1.34|~2.4", "psr/cache": "~1.0", "psr/container": "^1.0", "psr/link": "^1.0", diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 9c635c9508..b59d85ea0b 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -34,7 +34,7 @@ CHANGELOG // ... $rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig); // require Twig 1.30+ - $twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array( + $twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader(array( TwigRenderer::class => function () use ($rendererEngine, $csrfTokenManager) { return new TwigRenderer($rendererEngine, $csrfTokenManager); }, diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 1bc355e0c4..e6357df51e 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Twig\Environment; /** * Lists twig functions, filters, globals and tests present in the current project. @@ -35,18 +36,13 @@ class DebugCommand extends Command parent::__construct($name); } - /** - * Sets the twig environment. - * - * @param \Twig_Environment $twig - */ - public function setTwigEnvironment(\Twig_Environment $twig) + public function setTwigEnvironment(Environment $twig) { $this->twig = $twig; } /** - * @return \Twig_Environment $twig + * @return Environment $twig */ protected function getTwigEnvironment() { diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index b252ee274c..d20b9cf193 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -18,6 +18,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Finder\Finder; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Loader\ArrayLoader; +use Twig\Source; /** * Command that will validate your template syntax and output encountered errors. @@ -37,18 +41,13 @@ class LintCommand extends Command parent::__construct($name); } - /** - * Sets the twig environment. - * - * @param \Twig_Environment $twig - */ - public function setTwigEnvironment(\Twig_Environment $twig) + public function setTwigEnvironment(Environment $twig) { $this->twig = $twig; } /** - * @return \Twig_Environment $twig + * @return Environment $twig */ protected function getTwigEnvironment() { @@ -111,7 +110,7 @@ EOF return $this->display($input, $output, $io, $filesInfo); } - private function getFilesInfo(\Twig_Environment $twig, array $filenames) + private function getFilesInfo(Environment $twig, array $filenames) { $filesInfo = array(); foreach ($filenames as $filename) { @@ -134,16 +133,16 @@ EOF throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename)); } - private function validate(\Twig_Environment $twig, $template, $file) + private function validate(Environment $twig, $template, $file) { $realLoader = $twig->getLoader(); try { - $temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template)); + $temporaryLoader = new ArrayLoader(array((string) $file => $template)); $twig->setLoader($temporaryLoader); - $nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file))); + $nodeTree = $twig->parse($twig->tokenize(new Source($template, (string) $file))); $twig->compile($nodeTree); $twig->setLoader($realLoader); - } catch (\Twig_Error $e) { + } catch (Error $e) { $twig->setLoader($realLoader); return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e); @@ -205,7 +204,7 @@ EOF return min($errors, 1); } - private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null) + private function renderException(OutputInterface $output, $template, Error $exception, $file = null) { $line = $exception->getTemplateLine(); diff --git a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php index f075709654..382ce13987 100644 --- a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php +++ b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php @@ -15,6 +15,9 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector; use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Twig\Markup; +use Twig\Profiler\Dumper\HtmlDumper; +use Twig\Profiler\Profile; /** * TwigDataCollector. @@ -26,7 +29,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf private $profile; private $computed; - public function __construct(\Twig_Profiler_Profile $profile) + public function __construct(Profile $profile) { $this->profile = $profile; } @@ -73,7 +76,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf public function getHtmlCallGraph() { - $dumper = new \Twig_Profiler_Dumper_Html(); + $dumper = new HtmlDumper(); $dump = $dumper->dump($this->getProfile()); // needed to remove the hardcoded CSS styles @@ -87,14 +90,14 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf '', ), $dump); - return new \Twig_Markup($dump, 'UTF-8'); + return new Markup($dump, 'UTF-8'); } public function getProfile() { if (null === $this->profile) { if (PHP_VERSION_ID >= 70000) { - $this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile'))); + $this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile', 'Twig\Profiler\Profile'))); } else { $this->profile = unserialize($this->data['profile']); } @@ -112,7 +115,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf return $this->computed[$index]; } - private function computeData(\Twig_Profiler_Profile $profile) + private function computeData(Profile $profile) { $data = array( 'template_count' => 0, diff --git a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php index f599a9eb5c..d5d70fb397 100644 --- a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php @@ -12,13 +12,15 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Asset\Packages; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for the Symfony Asset component. * * @author Fabien Potencier */ -class AssetExtension extends \Twig_Extension +class AssetExtension extends AbstractExtension { private $packages; @@ -33,8 +35,8 @@ class AssetExtension extends \Twig_Extension public function getFunctions() { return array( - new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')), - new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')), + new TwigFunction('asset', array($this, 'getAssetUrl')), + new TwigFunction('asset_version', array($this, 'getAssetVersion')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php index 9861277db0..83a8f7eed4 100644 --- a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php @@ -12,13 +12,15 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; +use Twig\Extension\AbstractExtension; +use Twig\TwigFilter; /** * Twig extension relate to PHP code and used by the profiler and the default exception templates. * * @author Fabien Potencier */ -class CodeExtension extends \Twig_Extension +class CodeExtension extends AbstractExtension { private $fileLinkFormat; private $rootDir; @@ -44,15 +46,15 @@ class CodeExtension extends \Twig_Extension 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('format_log_message', array($this, 'formatLogMessage'), 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('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))), + new TwigFilter('file_link', array($this, 'getFileLink')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php index 2407f61013..767163f87d 100644 --- a/src/Symfony/Bridge/Twig/Extension/DumpExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/DumpExtension.php @@ -14,13 +14,17 @@ namespace Symfony\Bridge\Twig\Extension; 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; private $dumper; @@ -34,7 +38,7 @@ class DumpExtension extends \Twig_Extension 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)), ); } @@ -48,7 +52,7 @@ class DumpExtension extends \Twig_Extension return 'dump'; } - public function dump(\Twig_Environment $env, $context) + public function dump(Environment $env, $context) { if (!$env->isDebug()) { return; @@ -57,7 +61,7 @@ class DumpExtension extends \Twig_Extension 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 6b30a27941..fc64fa3e37 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 81a8683c35..362879e43a 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -15,6 +15,12 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Form\TwigRendererInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Form\ChoiceList\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. @@ -22,7 +28,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView; * @author Fabien Potencier * @author Bernhard Schussek */ -class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface +class FormExtension extends AbstractExtension implements InitRuntimeInterface { /** * @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below @@ -32,7 +38,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti public function __construct($renderer = null) { if ($renderer instanceof TwigRendererInterface) { - @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig_Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED); } elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) { throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__)); } @@ -44,7 +50,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti * * To be removed in 4.0 */ - public function initRuntime(\Twig_Environment $environment) + public function initRuntime(Environment $environment) { if ($this->renderer instanceof TwigRendererInterface) { $this->renderer->setEnvironment($environment); @@ -70,15 +76,15 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti public function getFunctions() { return array( - 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('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')), + 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('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')), ); } @@ -88,7 +94,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti public function getFilters() { return array( - new \Twig_SimpleFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')), + new TwigFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')), ); } @@ -98,7 +104,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti public function getTests() { return array( - new \Twig_SimpleTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'), + new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php index 69d6d326f4..90b515ee32 100644 --- a/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php @@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension; 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 @@ class HttpFoundationExtension extends \Twig_Extension 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 43b23bb9f6..45142e7402 100644 --- a/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php @@ -12,20 +12,22 @@ namespace Symfony\Bridge\Twig\Extension; 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 { public function getFunctions() { return array( - new \Twig_SimpleFunction('render', array(HttpKernelRuntime::class, 'renderFragment'), array('is_safe' => array('html'))), - new \Twig_SimpleFunction('render_*', array(HttpKernelRuntime::class, 'renderFragmentStrategy'), array('is_safe' => array('html'))), - new \Twig_SimpleFunction('controller', static::class.'::controller'), + new TwigFunction('render', array(HttpKernelRuntime::class, 'renderFragment'), array('is_safe' => array('html'))), + new TwigFunction('render_*', array(HttpKernelRuntime::class, 'renderFragmentStrategy'), array('is_safe' => array('html'))), + new TwigFunction('controller', static::class.'::controller'), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php b/src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php index ea105e8d95..17abb77989 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 @@ class LogoutUrlExtension extends \Twig_Extension 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 648a6c8036..21214f8119 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 @@ class ProfilerExtension extends \Twig_Extension_Profiler $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 @@ class ProfilerExtension extends \Twig_Extension_Profiler 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 81cef949c7..97b1ea3136 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 @@ class RoutingExtension extends \Twig_Extension 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 @@ class RoutingExtension extends \Twig_Extension * - 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 @@ class RoutingExtension extends \Twig_Extension $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 fa5fae2e77..193726a684 100644 --- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension; 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 @@ class SecurityExtension extends \Twig_Extension 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 52af92324c..635188b738 100644 --- a/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/StopwatchExtension.php @@ -13,13 +13,14 @@ namespace Symfony\Bridge\Twig\Extension; 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 f1f2fbd20b..5155169a81 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -17,18 +17,22 @@ use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser; 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 @@ class TranslationExtension extends \Twig_Extension 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/WebLinkExtension.php b/src/Symfony/Bridge/Twig/Extension/WebLinkExtension.php index 14e1fc2736..3d90c3bf21 100644 --- a/src/Symfony/Bridge/Twig/Extension/WebLinkExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/WebLinkExtension.php @@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension; use Fig\Link\GenericLinkProvider; use Fig\Link\Link; use Symfony\Component\HttpFoundation\RequestStack; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * Twig extension for the Symfony WebLink component. * * @author Kévin Dunglas */ -class WebLinkExtension extends \Twig_Extension +class WebLinkExtension extends AbstractExtension { private $requestStack; @@ -35,12 +37,12 @@ class WebLinkExtension extends \Twig_Extension public function getFunctions() { return array( - new \Twig_SimpleFunction('link', array($this, 'link')), - new \Twig_SimpleFunction('preload', array($this, 'preload')), - new \Twig_SimpleFunction('dns_prefetch', array($this, 'dnsPrefetch')), - new \Twig_SimpleFunction('preconnect', array($this, 'preconnect')), - new \Twig_SimpleFunction('prefetch', array($this, 'prefetch')), - new \Twig_SimpleFunction('prerender', array($this, 'prerender')), + new TwigFunction('link', array($this, 'link')), + new TwigFunction('preload', array($this, 'preload')), + new TwigFunction('dns_prefetch', array($this, 'dnsPrefetch')), + new TwigFunction('preconnect', array($this, 'preconnect')), + new TwigFunction('prefetch', array($this, 'prefetch')), + new TwigFunction('prerender', array($this, 'prerender')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php index 86fc9726db..2d19857c96 100644 --- a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php @@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Transition; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** * WorkflowExtension. * * @author Grégoire Pineau */ -class WorkflowExtension extends \Twig_Extension +class WorkflowExtension extends AbstractExtension { private $workflowRegistry; @@ -31,10 +33,10 @@ class WorkflowExtension extends \Twig_Extension public function getFunctions() { return array( - new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')), - new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')), - new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')), - new \Twig_SimpleFunction('workflow_marked_places', array($this, 'getMarkedPlaces')), + new TwigFunction('workflow_can', array($this, 'canTransition')), + new TwigFunction('workflow_transitions', array($this, 'getEnabledTransitions')), + new TwigFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')), + new TwigFunction('workflow_marked_places', array($this, 'getMarkedPlaces')), ); } diff --git a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php index df33135db9..79418fb8ff 100644 --- a/src/Symfony/Bridge/Twig/Extension/YamlExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/YamlExtension.php @@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension; 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 2f526100f5..9718c29cdb 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRenderer.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRenderer.php @@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\FormRenderer; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; +use Twig\Environment; /** * @author Bernhard Schussek @@ -34,7 +35,7 @@ class TwigRenderer extends FormRenderer implements TwigRendererInterface /** * {@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 406726ccdc..7e375f45e2 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -13,6 +13,8 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\AbstractRendererEngine; use Symfony\Component\Form\FormView; +use Twig\Environment; +use Twig\Template; /** * @author Bernhard Schussek @@ -20,16 +22,16 @@ use Symfony\Component\Form\FormView; class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface { /** - * @var \Twig_Environment + * @var Environment */ private $environment; /** - * @var \Twig_Template + * @var Template */ private $template; - public function __construct(array $defaultThemes = array(), \Twig_Environment $environment = null) + public function __construct(array $defaultThemes = array(), Environment $environment = null) { if (null === $environment) { @trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED); @@ -44,7 +46,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE * * @deprecated since version 3.3, to be removed in 4.0 */ - public function setEnvironment(\Twig_Environment $environment) + public function setEnvironment(Environment $environment) { if ($this->environment) { @trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Pass the Twig Environment as second argument of the constructor instead.', __METHOD__), E_USER_DEPRECATED); @@ -166,13 +168,13 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE */ 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 2fd0cbda79..a58f491f1c 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php @@ -12,6 +12,10 @@ 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 @@ -20,10 +24,5 @@ use Symfony\Component\Form\FormRendererEngineInterface; */ 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 85133248f3..3bcbf5992d 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php @@ -12,6 +12,10 @@ 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 @@ -20,10 +24,5 @@ use Symfony\Component\Form\FormRendererInterface; */ 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 a66781e365..d820d75cc7 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 @@ class DumpNode extends \Twig_Node /** * {@inheritdoc} */ - public function compile(\Twig_Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->write("if (\$this->env->isDebug()) {\n") @@ -44,7 +47,7 @@ class DumpNode extends \Twig_Node ->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 a1330413e7..06d2400c4e 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 6c046c3801..0698fd9001 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 @@ namespace Symfony\Bridge\Twig\Node; * * @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 47457e2dc5..dcdba5c4db 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->getRuntime(\'Symfony\Bridge\Twig\Form\TwigRenderer\')->searchAndRenderBlock('); @@ -39,7 +44,7 @@ class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function $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 @@ class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function // 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 95d755a78c..fac770c249 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 adee71ffc5..c9c82b33e5 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 7b2f9c0904..020810f7b7 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 @@ class TransNode extends \Twig_Node 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 @@ class TransNode extends \Twig_Node $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 @@ class TransNode extends \Twig_Node 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 e64d6eae23..c69ca843e8 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php @@ -13,13 +13,22 @@ namespace Symfony\Bridge\Twig\NodeVisitor; use Symfony\Bridge\Twig\Node\TransNode; use Symfony\Bridge\Twig\Node\TransDefaultDomainNode; +use Twig\Environment; +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\NodeVisitor\AbstractNodeVisitor; /** * TranslationDefaultDomainNodeVisitor. * * @author Fabien Potencier */ -class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor +class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor { /** * @var Scope @@ -37,23 +46,23 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor /** * {@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 Node_Block || $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 Node_Set(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine()); } } @@ -61,7 +70,7 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor 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 +80,7 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor } 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 +98,13 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor /** * {@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 Node_Block || $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 6e3880d09e..01f230b9ef 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 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor /** * {@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 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor $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 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor /** * {@inheritdoc} */ - protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { return $node; } @@ -99,12 +104,12 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor } /** - * @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 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor } /** - * @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 1b63cdd1b8..ef7698c39c 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\Bridge\Twig\Command\LintCommand; 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 @@ class LintCommandTest extends TestCase */ 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 df95e4b450..ce80418c83 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php @@ -16,6 +16,8 @@ use Symfony\Bridge\Twig\Extension\DumpExtension; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\VarDumper; use Symfony\Component\VarDumper\Cloner\VarCloner; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class DumpExtensionTest extends TestCase { @@ -25,7 +27,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, @@ -65,7 +67,7 @@ class DumpExtensionTest extends TestCase 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, @@ -121,7 +123,7 @@ class DumpExtensionTest extends TestCase '' ); $extension = new DumpExtension(new VarCloner(), $dumper); - $twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array( + $twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array( 'debug' => true, '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 d689bad20b..b2ee22c6a9 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/ExpressionExtensionTest.php @@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Tests\Extension; use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Extension\ExpressionExtension; +use Twig\Environment; +use Twig\Loader\ArrayLoader; 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 1c8e5dcd49..4cbc55b46a 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 614b59f582..f82a5d2e33 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\StubTranslator; 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 { @@ -39,7 +40,7 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori __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(new FormExtension()); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php index aceda8153d..93f08ed252 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\StubTranslator; 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 { @@ -35,7 +36,7 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest __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(new FormExtension()); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 9967299744..5367650e9d 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\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; 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 { @@ -36,7 +37,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest __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 8d4396a54c..5868e42ca5 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\Bridge\Twig\Extension\TranslationExtension; 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 { @@ -35,7 +36,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest __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(new FormExtension()); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php index 8909b3e4e4..9f19847eb8 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php @@ -17,11 +17,13 @@ use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; 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() { @@ -75,11 +77,11 @@ class HttpKernelExtensionTest extends TestCase 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()); - $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $loader->expects($this->any())->method('load')->will($this->returnValueMap(array( array('Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)), ))); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php index 5fa4e9cd36..fdff039851 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php @@ -13,6 +13,9 @@ namespace Symfony\Bridge\Twig\Tests\Extension; 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/RuntimeLoaderProvider.php b/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php index a6c397ffd4..90db2c5d6b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/RuntimeLoaderProvider.php @@ -12,12 +12,13 @@ namespace Symfony\Bridge\Twig\Tests\Extension; use Symfony\Bridge\Twig\Form\TwigRenderer; +use Twig\Environment; trait RuntimeLoaderProvider { - protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer) + protected function registerTwigRuntimeLoader(Environment $environment, TwigRenderer $renderer) { - $loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $loader->expects($this->any())->method('load')->will($this->returnValueMap(array( array('Symfony\Bridge\Twig\Form\TwigRenderer', $renderer), ))); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php index c50252eaaf..25b2e029ee 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php @@ -13,11 +13,14 @@ namespace Symfony\Bridge\Twig\Tests\Extension; 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 @@ class StopwatchExtensionTest extends TestCase */ 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 446697d3dd..36016d7f49 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\Bridge\Twig\Extension\TranslationExtension; 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 @@ class TranslationExtensionTest extends TestCase { 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 @@ class TranslationExtensionTest extends TestCase } /** - * @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 @@ class TranslationExtensionTest extends TestCase } /** - * @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 @@ class TranslationExtensionTest extends TestCase } /** - * @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 @@ class TranslationExtensionTest extends TestCase } 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 7e61f30938..0201c56a49 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php @@ -13,6 +13,10 @@ namespace Symfony\Bridge\Twig\Tests\Node; 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 @@ class DumpNodeTest extends TestCase { $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 @@ EOTXT; { $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 @@ EOTXT; 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()) { @@ -93,14 +97,14 @@ EOTXT; 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()) { diff --git a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php index ea645548f9..c40fcbdc90 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php @@ -13,15 +13,21 @@ namespace Symfony\Bridge\Twig\Tests\Node; 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 @@ class FormThemeTest extends TestCase 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 @@ class FormThemeTest extends TestCase trim($compiler->compile($node)->getSource()) ); - $resources = new \Twig_Node_Expression_Constant('tpl1', 0); + $resources = new ConstantExpression('tpl1', 0); $node = new FormThemeNode($form, $resources, 0); diff --git a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php index a95dcc0de3..fe91422a35 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php @@ -13,18 +13,25 @@ namespace Symfony\Bridge\Twig\Tests\Node; 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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 @@ class SearchAndRenderBlockNodeTest extends TestCase 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. diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index 6e500fb801..56b2770d35 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -13,6 +13,10 @@ namespace Symfony\Bridge\Twig\Tests\Node; 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( @@ -49,7 +53,7 @@ class TransNodeTest extends TestCase 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); } diff --git a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php index da9f43a6c4..eb4c9a83e8 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php @@ -14,6 +14,9 @@ namespace Symfony\Bridge\Twig\Tests\NodeVisitor; 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 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase } /** @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 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase 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 d12fff532a..9c2d0ab9e4 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php @@ -13,13 +13,19 @@ namespace Symfony\Bridge\Twig\Tests\NodeVisitor; 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 @@ class TranslationNodeVisitorTest extends TestCase { $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 502cad38de..49eac23e8a 100644 --- a/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php +++ b/src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php @@ -13,19 +13,26 @@ namespace Symfony\Bridge\Twig\Tests\NodeVisitor; 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 @@ class TwigNodeProvider { 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 @@ class TwigNodeProvider { 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 @@ class TwigNodeProvider 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 8931be061f..0972b15e23 100644 --- a/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php @@ -14,6 +14,12 @@ namespace Symfony\Bridge\Twig\Tests\TokenParser; 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 @@ class FormThemeTokenParserTest extends TestCase 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 @@ class FormThemeTokenParserTest extends TestCase 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 @@ class FormThemeTokenParserTest extends TestCase 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 @@ class FormThemeTokenParserTest extends TestCase 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 @@ class FormThemeTokenParserTest extends TestCase 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 0b1fb28b0e..013598a40b 100644 --- a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php @@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase; 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 @@ class TwigExtractorTest extends TestCase } /** - * @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 @@ class TwigExtractorTest extends TestCase */ 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 e2082df3dd..a74c59e8d2 100644 --- a/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php +++ b/src/Symfony/Bridge/Twig/Tests/TwigEngineTest.php @@ -14,6 +14,8 @@ namespace Symfony\Bridge\Twig\Tests; 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 @@ class TwigEngineTest extends TestCase { $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 @@ class TwigEngineTest extends TestCase } /** - * @expectedException \Twig_Error_Syntax + * @expectedException \Twig\Error\SyntaxError */ public function testRenderWithError() { @@ -68,7 +70,7 @@ class TwigEngineTest extends TestCase 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 269ead64f5..7cdbb77b43 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 @@ use Symfony\Bridge\Twig\Node\DumpNode; * * @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 daf87824e7..12c2541851 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 2983e4cb6b..82c58d40bb 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 @@ class StopwatchTokenParser extends \Twig_TokenParser $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 @@ class StopwatchTokenParser extends \Twig_TokenParser // {% 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 fa61a2f148..2b4a9f3fc4 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 @@ class TransChoiceTokenParser extends TransTokenParser $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 09832ea972..4096a011a3 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 4c8e7d3eee..848a080710 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 @@ class TransTokenParser extends \Twig_TokenParser // {% 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 35995dbd64..bd35fe5a8b 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -16,6 +16,9 @@ use Symfony\Component\Finder\SplFileInfo; 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 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface 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 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface $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 760461b5be..bc0a4fecc9 100644 --- a/src/Symfony/Bridge/Twig/TwigEngine.php +++ b/src/Symfony/Bridge/Twig/TwigEngine.php @@ -15,6 +15,11 @@ use Symfony\Component\Templating\EngineInterface; 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 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * {@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 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * {@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 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * {@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 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * {@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 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface /** * 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 38949fad20..a7f1e23747 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.5.9", - "twig/twig": "~1.28|~2.0" + "twig/twig": "~1.34|~2.4" }, "require-dev": { "fig/link-util": "^1.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 1055b00e3b..6d0cee247d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -25,6 +25,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Templating\EngineInterface; +use Twig\Environment; /** * Provides common features needed in controllers. @@ -59,7 +60,7 @@ abstract class AbstractController implements ServiceSubscriberInterface 'session' => '?'.SessionInterface::class, 'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class, 'templating' => '?'.EngineInterface::class, - 'twig' => '?'.\Twig_Environment::class, + 'twig' => '?'.Environment::class, 'doctrine' => '?'.ManagerRegistry::class, 'form.factory' => '?'.FormFactoryInterface::class, 'security.token_storage' => '?'.TokenStorageInterface::class, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php index 2bd18aa441..3feabfd12e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php @@ -317,7 +317,7 @@ abstract class ControllerTraitTest extends TestCase 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 = new Container(); @@ -331,7 +331,7 @@ abstract class ControllerTraitTest extends TestCase 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 = new Container(); @@ -345,7 +345,7 @@ abstract class ControllerTraitTest extends TestCase public function testStreamTwig() { - $twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $container = new Container(); $container->set('twig', $twig); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php index 04e6447ee9..6afb5e3203 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/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 70b922c1fc..05fb5b96a6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -56,7 +56,7 @@ "symfony/web-link": "~3.3", "doctrine/annotations": "~1.0", "phpdocumentor/reflection-docblock": "^3.0", - "twig/twig": "~1.26|~2.0", + "twig/twig": "~1.34|~2.4", "sensio/framework-extra-bundle": "^3.0.2" }, "conflict": { diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index df6049b059..5c23309a46 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -41,7 +41,7 @@ "symfony/yaml": "~2.8|~3.0", "symfony/expression-language": "~2.8|~3.0", "doctrine/doctrine-bundle": "~1.4", - "twig/twig": "~1.28|~2.0" + "twig/twig": "~1.34|~2.4" }, "conflict": { "symfony/var-dumper": "<3.3" diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index 22184833f0..fa666dccf8 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -17,6 +17,8 @@ use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface; use Symfony\Component\Templating\TemplateReference; +use Twig\Environment; +use Twig\Error\Error; /** * Generates the Twig cache for all templates. @@ -77,7 +79,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe try { $twig->loadTemplate($template); - } catch (\Twig_Error $e) { + } catch (Error $e) { // problem during compilation, give up } } @@ -99,7 +101,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe public static function getSubscribedServices() { return array( - 'twig' => \Twig_Environment::class, + 'twig' => Environment::class, ); } diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php index aefb5c7296..8946c1a98b 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php @@ -12,6 +12,8 @@ namespace Symfony\Bundle\TwigBundle\CacheWarmer; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; +use Twig\Environment; +use Twig\Error\Error; /** * Generates the Twig cache for all templates. @@ -23,7 +25,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface private $twig; private $iterator; - public function __construct(\Twig_Environment $twig, \Traversable $iterator) + public function __construct(Environment $twig, \Traversable $iterator) { $this->twig = $twig; $this->iterator = $iterator; @@ -37,7 +39,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface 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/ContainerAwareRuntimeLoader.php b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php index e2988f3aae..377649602d 100644 --- a/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php +++ b/src/Symfony/Bundle/TwigBundle/ContainerAwareRuntimeLoader.php @@ -11,19 +11,20 @@ namespace Symfony\Bundle\TwigBundle; -@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED); +@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig\RuntimeLoader\ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED); use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Twig\RuntimeLoader\RuntimeLoaderInterface; /** * Loads Twig extension runtimes via the service container. * * @author Fabien Potencier * - * @deprecated since version 3.3, will be removed in 4.0. Use \Twig_ContainerRuntimeLoader instead. + * @deprecated since version 3.3, will be removed in 4.0. Use \Twig\Loader\ContainerRuntimeLoader instead. */ -class ContainerAwareRuntimeLoader implements \Twig_RuntimeLoaderInterface +class ContainerAwareRuntimeLoader implements RuntimeLoaderInterface { private $container; private $mapping; diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index f9e86c4daa..d648d63dd5 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -15,6 +15,9 @@ use Symfony\Component\Debug\Exception\FlattenException; 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 @@ class ExceptionController $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 @@ class ExceptionController $loader->getSourceContext($template)->getCode(); return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index c0661d9e70..4880d2534d 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -123,7 +123,7 @@ class Configuration implements ConfigurationInterface ->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 bf37559b99..1612b6eb5f 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 @@ class EnvironmentConfigurator $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/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 916ca53c74..362355dd8d 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -18,6 +18,8 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\WebLink\HttpHeaderSerializer; +use Twig\Extension\ExtensionInterface; +use Twig\Loader\LoaderInterface; /** * TwigExtension. @@ -144,10 +146,10 @@ class TwigExtension extends Extension $container->getDefinition('twig')->replaceArgument(1, $config); - $container->registerForAutoconfiguration(\Twig_ExtensionInterface::class) - ->addTag('twig.extension'); - $container->registerForAutoconfiguration(\Twig_LoaderInterface::class) - ->addTag('twig.loader'); + $container->registerForAutoconfiguration(\Twig_ExtensionInterface::class)->addTag('twig.extension'); + $container->registerForAutoconfiguration(\Twig_LoaderInterface::class)->addTag('twig.loader'); + $container->registerForAutoconfiguration(ExtensionInterface::class)->addTag('twig.extension'); + $container->registerForAutoconfiguration(LoaderInterface::class)->addTag('twig.loader'); if (PHP_VERSION_ID < 70000) { $this->addClassesToCompile(array( diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 0a9ac7a3ca..2b9b2502ae 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -14,6 +14,8 @@ namespace Symfony\Bundle\TwigBundle\Loader; 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 @@ use Symfony\Component\Templating\TemplateReferenceInterface; * * @author Fabien Potencier */ -class FilesystemLoader extends \Twig_Loader_Filesystem +class FilesystemLoader extends BaseFilesystemLoader { protected $locator; protected $parser; @@ -59,11 +61,11 @@ class FilesystemLoader extends \Twig_Loader_Filesystem * 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) { @@ -77,7 +79,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem $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/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index ca427869a9..2f12f8f02e 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -7,7 +7,7 @@ - + @@ -20,6 +20,7 @@ + %kernel.environment% @@ -48,20 +49,20 @@ - + %kernel.project_dir% - + - + @@ -108,7 +109,7 @@ - + @@ -145,7 +146,7 @@ - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php index 920a833c6b..cf5722727b 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -15,13 +15,15 @@ use Symfony\Bundle\TwigBundle\Tests\TestCase; use Symfony\Bundle\TwigBundle\Controller\ExceptionController; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\HttpFoundation\Request; +use Twig\Environment; +use Twig\Loader\ArrayLoader; class ExceptionControllerTest extends TestCase { public function testShowActionCanBeForcedToShowErrorPage() { - $twig = new \Twig_Environment( - new \Twig_Loader_Array(array( + $twig = new Environment( + new ArrayLoader(array( '@Twig/Exception/error404.html.twig' => 'ok', )) ); @@ -40,8 +42,8 @@ class ExceptionControllerTest extends TestCase public function testFallbackToHtmlIfNoTemplateForRequestedFormat() { - $twig = new \Twig_Environment( - new \Twig_Loader_Array(array( + $twig = new Environment( + new ArrayLoader(array( '@Twig/Exception/error.html.twig' => 'html', )) ); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php index 94c00c2cab..6ce77c5497 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php @@ -30,7 +30,7 @@ class ExtensionPassTest extends TestCase $container->register('twig.extension.debug.stopwatch'); $container->register('twig.extension.expression'); - $nativeTwigLoader = new Definition('\Twig_Loader_Filesystem'); + $nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader'); $nativeTwigLoader->addMethodCall('addPath', array()); $container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 4d78b77265..25c3886379 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -32,7 +32,7 @@ class TwigExtensionTest extends TestCase $container->loadFromExtension('twig', array()); $this->compileContainer($container); - $this->assertEquals('Twig_Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); + $this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); $this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); @@ -53,7 +53,7 @@ class TwigExtensionTest extends TestCase $this->loadFromFile($container, 'full', $format); $this->compileContainer($container); - $this->assertEquals('Twig_Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); + $this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); // Form resources $resources = $container->getParameter('twig.form.resources'); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index a7abdecb87..b9294e35b3 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -52,7 +52,7 @@ class FilesystemLoaderTest extends TestCase } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testTwigErrorIfLocatorThrowsInvalid() { @@ -76,7 +76,7 @@ class FilesystemLoaderTest extends TestCase } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError */ public function testTwigErrorIfLocatorReturnsFalse() { @@ -100,7 +100,7 @@ class FilesystemLoaderTest extends TestCase } /** - * @expectedException \Twig_Error_Loader + * @expectedException \Twig\Error\LoaderError * @expectedExceptionMessageRegExp /Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/ */ public function testTwigErrorIfTemplateDoesNotExist() diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 503c55f6af..cc13c280b1 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -17,6 +17,8 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Environment; +use Twig\Error\Error; /** * This engine renders Twig templates. @@ -27,14 +29,7 @@ class TwigEngine extends BaseEngine implements EngineInterface { protected $locator; - /** - * Constructor. - * - * @param \Twig_Environment $environment A \Twig_Environment instance - * @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance - * @param FileLocatorInterface $locator A FileLocatorInterface instance - */ - public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator) + public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator) { parent::__construct($environment, $parser); @@ -48,7 +43,7 @@ class TwigEngine extends BaseEngine implements EngineInterface { try { return parent::render($name, $parameters); - } catch (\Twig_Error $e) { + } catch (Error $e) { if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) { try { // try to get the real name of the template where the error occurred @@ -66,7 +61,7 @@ class TwigEngine extends BaseEngine implements EngineInterface /** * {@inheritdoc} * - * @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 renderResponse($view, array $parameters = array(), Response $response = null) { diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 454349b0f0..11f071b19c 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -21,7 +21,7 @@ "symfony/twig-bridge": "^3.3", "symfony/http-foundation": "~2.8|~3.0", "symfony/http-kernel": "^3.3", - "twig/twig": "^1.32|^2.2" + "twig/twig": "~1.34|~2.4" }, "require-dev": { "symfony/asset": "~2.8|~3.0", diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index fd0dbecd2b..3f9d873e1d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -15,6 +15,9 @@ use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; /** * ExceptionController. @@ -27,7 +30,7 @@ class ExceptionController protected $debug; protected $profiler; - public function __construct(Profiler $profiler = null, \Twig_Environment $twig, $debug) + public function __construct(Profiler $profiler = null, Environment $twig, $debug) { $this->profiler = $profiler; $this->twig = $twig; @@ -112,7 +115,7 @@ class ExceptionController protected function templateExists($template) { $loader = $this->twig->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface) { + if ($loader instanceof ExistsLoaderInterface) { return $loader->exists($template); } @@ -120,7 +123,7 @@ class ExceptionController $loader->getSource($template); return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 33092d3646..37f47df6a6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Twig\Environment; /** * ProfilerController. @@ -42,13 +43,13 @@ class ProfilerController * * @param UrlGeneratorInterface $generator The URL Generator * @param Profiler $profiler The profiler - * @param \Twig_Environment $twig The twig environment + * @param Environment $twig The twig environment * @param array $templates The templates * @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration) * @param ContentSecurityPolicyHandler $cspHandler The Content-Security-Policy handler * @param string $baseDir The project root directory */ - public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null) + public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null) { $this->generator = $generator; $this->profiler = $profiler; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php index 3ea170d7ea..80946ac428 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php @@ -20,6 +20,7 @@ use Symfony\Component\Routing\RouterInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; +use Twig\Environment; /** * RouterController. @@ -33,7 +34,7 @@ class RouterController private $matcher; private $routes; - public function __construct(Profiler $profiler = null, \Twig_Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) + public function __construct(Profiler $profiler = null, Environment $twig, UrlMatcherInterface $matcher = null, RouteCollection $routes = null) { $this->profiler = $profiler; $this->twig = $twig; diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index a40c42c88e..6ffdbc7ad0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Twig\Environment; /** * WebDebugToolbarListener injects the Web Debug Toolbar. @@ -43,7 +44,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface protected $excludedAjaxPaths; private $cspHandler; - public function __construct(\Twig_Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt', ContentSecurityPolicyHandler $cspHandler = null) + public function __construct(Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt', ContentSecurityPolicyHandler $cspHandler = null) { $this->twig = $twig; $this->urlGenerator = $urlGenerator; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php b/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php index 999604b7ef..29fe3a31c8 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php @@ -14,6 +14,11 @@ namespace Symfony\Bundle\WebProfilerBundle\Profiler; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Profiler\Profile; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Template; /** * Profiler Templates Manager. @@ -27,14 +32,7 @@ class TemplateManager protected $templates; protected $profiler; - /** - * Constructor. - * - * @param Profiler $profiler - * @param \Twig_Environment $twig - * @param array $templates - */ - public function __construct(Profiler $profiler, \Twig_Environment $twig, array $templates) + public function __construct(Profiler $profiler, Environment $twig, array $templates) { $this->profiler = $profiler; $this->twig = $twig; @@ -67,7 +65,7 @@ class TemplateManager * * @param Profile $profile * - * @return \Twig_Template[] + * @return Template[] * * @deprecated not used anymore internally */ @@ -124,19 +122,19 @@ class TemplateManager protected function templateExists($template) { $loader = $this->twig->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface) { + if ($loader instanceof ExistsLoaderInterface) { return $loader->exists($template); } try { - if ($loader instanceof \Twig_SourceContextLoaderInterface) { + if ($loader instanceof SourceContextLoaderInterface) { $loader->getSourceContext($template); } else { $loader->getSource($template); } return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php index 060313f875..839c9f21d9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php @@ -25,7 +25,7 @@ class ProfilerControllerTest extends TestCase public function testEmptyToken($token) { $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() @@ -51,7 +51,7 @@ class ProfilerControllerTest extends TestCase */ public function testReturns404onTokenNotFound($withCsp) { - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() @@ -81,7 +81,7 @@ class ProfilerControllerTest extends TestCase */ public function testSearchResult($withCsp) { - $twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $profiler = $this ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') ->disableOriginalConstructor() diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index 28dbb976d3..af0573e5a3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -52,9 +52,9 @@ class WebProfilerExtensionTest extends TestCase $this->container = new ContainerBuilder(); $this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')); - $this->container->register('twig', 'Twig_Environment'); - $this->container->register('twig_loader', 'Twig_Loader_Array')->addArgument(array()); - $this->container->register('twig', 'Twig_Environment')->addArgument(new Reference('twig_loader')); + $this->container->register('twig', 'Twig\Environment'); + $this->container->register('twig_loader', 'Twig\Loader\ArrayLoader')->addArgument(array()); + $this->container->register('twig', 'Twig\Environment')->addArgument(new Reference('twig_loader')); $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php index dff05c182c..5e5e7a21fe 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php @@ -291,7 +291,7 @@ class WebDebugToolbarListenerTest extends TestCase protected function getTwigMock($render = 'WDT') { - $templating = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $templating = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $templating->expects($this->any()) ->method('render') ->will($this->returnValue($render)); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php index 4ac2c7de5f..7b8f9a8df5 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Profiler; use Symfony\Bundle\WebProfilerBundle\Tests\TestCase; use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager; +use Twig\Environment; /** * Test for TemplateManager class. @@ -22,7 +23,7 @@ use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager; class TemplateManagerTest extends TestCase { /** - * @var \Twig_Environment + * @var Environment */ protected $twigEnvironment; @@ -46,7 +47,7 @@ class TemplateManagerTest extends TestCase 'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'), 'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'), 'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'), - ); + ); $this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates); } @@ -129,16 +130,16 @@ class TemplateManagerTest extends TestCase protected function mockTwigEnvironment() { - $this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); + $this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $this->twigEnvironment->expects($this->any()) ->method('loadTemplate') ->will($this->returnValue('loadedTemplate')); - if (interface_exists('\Twig_SourceContextLoaderInterface')) { - $loader = $this->getMockBuilder('\Twig_SourceContextLoaderInterface')->getMock(); + if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) { + $loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock(); } else { - $loader = $this->getMockBuilder('\Twig_LoaderInterface')->getMock(); + $loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(); } $this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader)); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php index 4662cbf56b..f552e5f206 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php @@ -14,13 +14,17 @@ namespace Symfony\Bundle\WebProfilerBundle\Twig; use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Dumper\HtmlDumper; +use Twig\Environment; +use Twig\Extension\ProfilerExtension; +use Twig\Profiler\Profile; +use Twig\TwigFunction; /** * Twig extension for the profiler. * * @author Fabien Potencier */ -class WebProfilerExtension extends \Twig_Extension_Profiler +class WebProfilerExtension extends ProfilerExtension { /** * @var ValueExporter @@ -48,12 +52,12 @@ class WebProfilerExtension extends \Twig_Extension_Profiler $this->dumper->setOutput($this->output = fopen('php://memory', 'r+b')); } - public function enter(\Twig_Profiler_Profile $profile) + public function enter(Profile $profile) { ++$this->stackLevel; } - public function leave(\Twig_Profiler_Profile $profile) + public function leave(Profile $profile) { if (0 === --$this->stackLevel) { $this->dumper->setOutput($this->output = fopen('php://memory', 'r+b')); @@ -65,17 +69,17 @@ class WebProfilerExtension extends \Twig_Extension_Profiler */ public function getFunctions() { - $profilerDump = function (\Twig_Environment $env, $value, $maxDepth = 0) { + $profilerDump = function (Environment $env, $value, $maxDepth = 0) { return $value instanceof Data ? $this->dumpData($env, $value, $maxDepth) : twig_escape_filter($env, $this->dumpValue($value)); }; return array( - new \Twig_SimpleFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)), - new \Twig_SimpleFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)), + new TwigFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)), + new TwigFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)), ); } - public function dumpData(\Twig_Environment $env, Data $data, $maxDepth = 0) + public function dumpData(Environment $env, Data $data, $maxDepth = 0) { $this->dumper->setCharset($env->getCharset()); $this->dumper->dump($data, null, array( @@ -89,7 +93,7 @@ class WebProfilerExtension extends \Twig_Extension_Profiler return str_replace("\n$1"', $message); diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index 276f8f68cc..626ac4d307 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -21,8 +21,8 @@ "symfony/polyfill-php70": "~1.0", "symfony/routing": "~2.8|~3.0", "symfony/twig-bridge": "~2.8|~3.0", - "twig/twig": "~1.28|~2.0", - "symfony/var-dumper": "~3.3" + "symfony/var-dumper": "~3.3", + "twig/twig": "~1.34|~2.4" }, "require-dev": { "symfony/config": "~2.8|~3.0", diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index 72eca3deb0..5523ea2337 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -116,7 +116,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher public function hasListeners($eventName = null) { if (null === $eventName) { - return count($this->listenerIds) || count($this->listeners) || parent::hasListeners(); + return $this->listenerIds || $this->listeners || parent::hasListeners(); } if (isset($this->listenerIds[$eventName])) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php index b3fd66927f..9443f21664 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php @@ -56,6 +56,7 @@ abstract class AbstractEventDispatcherTest extends TestCase { $this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo')); $this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo')); + $this->assertTrue($this->dispatcher->hasListeners()); $this->assertTrue($this->dispatcher->hasListeners(self::preFoo)); $this->assertTrue($this->dispatcher->hasListeners(self::postFoo)); $this->assertCount(1, $this->dispatcher->getListeners(self::preFoo)); diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index b638ba7905..b50386cb96 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -20,6 +20,7 @@ use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\Dumper\DataDumperInterface; +use Twig\Template; /** * @author Nicolas Grekas @@ -91,7 +92,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface $line = $trace[$i]['line']; break; - } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) { + } elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof Template) { $template = $trace[$i]['object']; $name = $template->getTemplateName(); $src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false); diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index c163a09073..ec2a40716a 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -16,6 +16,9 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Templating\EngineInterface; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\UriSigner; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; /** * Implements the Hinclude rendering strategy. @@ -32,10 +35,10 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer /** * Constructor. * - * @param EngineInterface|\Twig_Environment $templating An EngineInterface or a \Twig_Environment instance - * @param UriSigner $signer A UriSigner instance - * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) - * @param string $charset + * @param EngineInterface|Environment $templating An EngineInterface or a Twig instance + * @param UriSigner $signer A UriSigner instance + * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) + * @param string $charset */ public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null, $charset = 'utf-8') { @@ -48,14 +51,14 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer /** * Sets the templating engine to use to render the default content. * - * @param EngineInterface|\Twig_Environment|null $templating An EngineInterface or a \Twig_Environment instance + * @param EngineInterface|Environment|null $templating An EngineInterface or an Environment instance * * @throws \InvalidArgumentException */ public function setTemplating($templating) { - if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof \Twig_Environment) { - throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of \Twig_Environment or Symfony\Component\Templating\EngineInterface'); + if (null !== $templating && !$templating instanceof EngineInterface && !$templating instanceof Environment) { + throw new \InvalidArgumentException('The hinclude rendering strategy needs an instance of Twig\Environment or Symfony\Component\Templating\EngineInterface'); } $this->templating = $templating; @@ -136,7 +139,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer } $loader = $this->templating->getLoader(); - if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) { + if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) { return $loader->exists($template); } @@ -148,7 +151,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer } return true; - } catch (\Twig_Error_Loader $e) { + } catch (LoaderError $e) { } return false; diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index a680eb05e8..babc8663b6 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -43,7 +43,8 @@ "conflict": { "symfony/config": "<2.8", "symfony/dependency-injection": "<3.3", - "symfony/var-dumper": "<3.3" + "symfony/var-dumper": "<3.3", + "twig/twig": "<1.34|<2.4,>=2" }, "suggest": { "symfony/browser-kit": "", diff --git a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php index e2a4200c52..f52972a0ef 100644 --- a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php @@ -198,7 +198,7 @@ class ExceptionCaster $ellipsis = isset($ellipsis['ellipsis']) ? $ellipsis['ellipsis'] : 0; if (file_exists($f['file']) && 0 <= self::$srcContext) { - if (!empty($f['class']) && is_subclass_of($f['class'], 'Twig_Template') && method_exists($f['class'], 'getDebugInfo')) { + if (!empty($f['class']) && (is_subclass_of($f['class'], 'Twig\Template') || is_subclass_of($f['class'], 'Twig_Template')) && method_exists($f['class'], 'getDebugInfo')) { $template = isset($f['object']) ? $f['object'] : unserialize(sprintf('O:%d:"%s":0:{}', strlen($f['class']), $f['class'])); $ellipsis = 0; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php index 94ad5fe099..3f6a2e8ec3 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php @@ -171,7 +171,7 @@ EODUMP; } /** - * @requires function Twig_Template::getSourceContext + * @requires function Twig\Template::getSourceContext */ public function testFrameWithTwig() { diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index c57dbf7823..c4348dfa57 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -15,6 +15,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Test\VarDumperTestTrait; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; /** * @author Nicolas Grekas @@ -291,14 +293,14 @@ EOTXT } /** - * @requires function Twig_Template::getSourceContext + * @requires function Twig\Template::getSourceContext */ public function testThrowingCaster() { $out = fopen('php://memory', 'r+b'); require_once __DIR__.'/../Fixtures/Twig.php'; - $twig = new \__TwigTemplate_VarDumperFixture_u75a09(new \Twig_Environment(new \Twig_Loader_Filesystem())); + $twig = new \__TwigTemplate_VarDumperFixture_u75a09(new Environment(new FilesystemLoader())); $dumper = new CliDumper(); $dumper->setColors(false); @@ -314,7 +316,7 @@ EOTXT ':stream' => eval('return function () use ($twig) { try { $twig->render(array()); - } catch (\Twig_Error_Runtime $e) { + } catch (\Twig\Error\RuntimeError $e) { throw $e->getPrevious(); } };'), @@ -340,7 +342,7 @@ stream resource {@{$ref} %sTemplate.php:%d: { : try { : \$this->doDisplay(\$context, \$blocks); - : } catch (Twig_Error \$e) { + : } catch (Twig%sError \$e) { } %sTemplate.php:%d: { : { diff --git a/src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php b/src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php index bf64d85c1e..fe2542929b 100644 --- a/src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php +++ b/src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php @@ -1,11 +1,11 @@ path ?: __FILE__); + return new Twig\Source(" foo bar\n twig source\n\n", 'foo.twig', $this->path ?: __FILE__); } } diff --git a/src/Symfony/Component/VarDumper/composer.json b/src/Symfony/Component/VarDumper/composer.json index 464462663e..930896026a 100644 --- a/src/Symfony/Component/VarDumper/composer.json +++ b/src/Symfony/Component/VarDumper/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "ext-iconv": "*", - "twig/twig": "~1.20|~2.0" + "twig/twig": "~1.34|~2.4" }, "conflict": { "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"