Use namespaced Twig
This commit is contained in:
parent
78c4a5ff43
commit
c3d1262208
@ -21,7 +21,7 @@
|
||||
"paragonie/random_compat": "~1.0",
|
||||
"symfony/polyfill-apcu": "~1.1",
|
||||
"symfony/polyfill-mbstring": "~1.1",
|
||||
"twig/twig": "~1.28|~2.0",
|
||||
"twig/twig": "~1.34|~2.4",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"replace": {
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Lists twig functions, filters, globals and tests present in the current project.
|
||||
@ -34,18 +35,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()
|
||||
{
|
||||
|
@ -17,6 +17,10 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
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.
|
||||
@ -36,18 +40,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()
|
||||
{
|
||||
@ -117,7 +116,7 @@ EOF
|
||||
return $this->display($input, $output, $filesInfo);
|
||||
}
|
||||
|
||||
private function getFilesInfo(\Twig_Environment $twig, array $filenames)
|
||||
private function getFilesInfo(Environment $twig, array $filenames)
|
||||
{
|
||||
$filesInfo = array();
|
||||
foreach ($filenames as $filename) {
|
||||
@ -140,16 +139,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);
|
||||
@ -207,7 +206,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();
|
||||
|
||||
|
@ -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,9 +76,9 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||
|
||||
public function getHtmlCallGraph()
|
||||
{
|
||||
$dumper = new \Twig_Profiler_Dumper_Html();
|
||||
$dumper = new HtmlDumper();
|
||||
|
||||
return new \Twig_Markup($dumper->dump($this->getProfile()), 'UTF-8');
|
||||
return new Markup($dumper->dump($this->getProfile()), 'UTF-8');
|
||||
}
|
||||
|
||||
public function getProfile()
|
||||
@ -96,7 +99,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,
|
||||
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Twig extension for the Symfony Asset component.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class AssetExtension extends \Twig_Extension
|
||||
class AssetExtension extends AbstractExtension
|
||||
{
|
||||
private $packages;
|
||||
private $foundationExtension;
|
||||
@ -40,9 +42,9 @@ 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 \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')),
|
||||
new TwigFunction('asset', array($this, 'getAssetUrl')),
|
||||
new TwigFunction('asset_version', array($this, 'getAssetVersion')),
|
||||
new TwigFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,15 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
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 <fabien@symfony.com>
|
||||
*/
|
||||
class CodeExtension extends \Twig_Extension
|
||||
class CodeExtension extends AbstractExtension
|
||||
{
|
||||
private $fileLinkFormat;
|
||||
private $rootDir;
|
||||
@ -42,14 +45,14 @@ 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('file_link', array($this, 'getFileLink')),
|
||||
new TwigFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('format_args_as_text', array($this, 'formatArgsAsText')),
|
||||
new TwigFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
|
||||
new TwigFilter('file_link', array($this, 'getFileLink')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <p@tchwork.com>
|
||||
*/
|
||||
class DumpExtension extends \Twig_Extension
|
||||
class DumpExtension extends AbstractExtension
|
||||
{
|
||||
private $cloner;
|
||||
|
||||
@ -32,7 +36,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)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -46,7 +50,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;
|
||||
@ -55,7 +59,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;
|
||||
}
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,12 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
||||
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Extension\InitRuntimeInterface;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\TwigTest;
|
||||
|
||||
/**
|
||||
* FormExtension extends Twig with form capabilities.
|
||||
@ -21,7 +27,7 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
|
||||
class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
||||
{
|
||||
/**
|
||||
* This property is public so that it can be accessed directly from compiled
|
||||
@ -39,7 +45,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initRuntime(\Twig_Environment $environment)
|
||||
public function initRuntime(Environment $environment)
|
||||
{
|
||||
$this->renderer->setEnvironment($environment);
|
||||
}
|
||||
@ -61,16 +67,16 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
|
||||
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('csrf_token', array($this, 'renderCsrfToken')),
|
||||
new TwigFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
|
||||
new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||
new TwigFunction('csrf_token', array($this, 'renderCsrfToken')),
|
||||
);
|
||||
}
|
||||
|
||||
@ -80,7 +86,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFilter('humanize', array($this, 'humanize')),
|
||||
new TwigFilter('humanize', array($this, 'humanize')),
|
||||
);
|
||||
}
|
||||
|
||||
@ -90,7 +96,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleTest('selectedchoice', array($this, 'isSelectedChoice')),
|
||||
new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Provides integration with the HttpKernel component.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class HttpKernelExtension extends \Twig_Extension
|
||||
class HttpKernelExtension extends AbstractExtension
|
||||
{
|
||||
private $handler;
|
||||
|
||||
@ -36,9 +38,9 @@ class HttpKernelExtension extends \Twig_Extension
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
|
||||
new \Twig_SimpleFunction('controller', array($this, 'controller')),
|
||||
new TwigFunction('render', array($this, 'renderFragment'), array('is_safe' => array('html'))),
|
||||
new TwigFunction('render_*', array($this, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
|
||||
new TwigFunction('controller', array($this, 'controller')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <jmikola@gmail.com>
|
||||
*/
|
||||
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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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);
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
use Symfony\Component\Security\Acl\Voter\FieldVote;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* SecurityExtension exposes security context features.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class SecurityExtension extends \Twig_Extension
|
||||
class SecurityExtension extends AbstractExtension
|
||||
{
|
||||
private $securityChecker;
|
||||
|
||||
@ -47,7 +49,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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <wouter@wouterj.nl>
|
||||
*/
|
||||
class StopwatchExtension extends \Twig_Extension
|
||||
class StopwatchExtension extends AbstractExtension
|
||||
{
|
||||
private $stopwatch;
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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()
|
||||
{
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bridge\Twig\Form;
|
||||
|
||||
use Symfony\Component\Form\FormRenderer;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
@ -33,7 +34,7 @@ class TwigRenderer extends FormRenderer implements TwigRendererInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEnvironment(\Twig_Environment $environment)
|
||||
public function setEnvironment(Environment $environment)
|
||||
{
|
||||
$this->engine->setEnvironment($environment);
|
||||
}
|
||||
|
@ -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 <bschussek@gmail.com>
|
||||
@ -20,19 +22,19 @@ 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;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEnvironment(\Twig_Environment $environment)
|
||||
public function setEnvironment(Environment $environment)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
}
|
||||
@ -150,13 +152,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.
|
||||
|
@ -12,16 +12,15 @@
|
||||
namespace Symfony\Bridge\Twig\Form;
|
||||
|
||||
use Symfony\Component\Form\FormRendererEngineInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
// BC/FC with namespaced Twig
|
||||
class_exists('Twig\Environment');
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface TwigRendererEngineInterface extends FormRendererEngineInterface
|
||||
{
|
||||
/**
|
||||
* Sets Twig's environment.
|
||||
*
|
||||
* @param \Twig_Environment $environment
|
||||
*/
|
||||
public function setEnvironment(\Twig_Environment $environment);
|
||||
public function setEnvironment(Environment $environment);
|
||||
}
|
||||
|
@ -12,16 +12,15 @@
|
||||
namespace Symfony\Bridge\Twig\Form;
|
||||
|
||||
use Symfony\Component\Form\FormRendererInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
// BC/FC with namespaced Twig
|
||||
class_exists('Twig\Environment');
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface TwigRendererInterface extends FormRendererInterface
|
||||
{
|
||||
/**
|
||||
* Sets Twig's environment.
|
||||
*
|
||||
* @param \Twig_Environment $environment
|
||||
*/
|
||||
public function setEnvironment(\Twig_Environment $environment);
|
||||
public function setEnvironment(Environment $environment);
|
||||
}
|
||||
|
@ -11,14 +11,17 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Julien Galenski <julien.galenski@gmail.com>
|
||||
*/
|
||||
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()
|
||||
|
@ -11,22 +11,20 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
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)
|
||||
|
@ -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 <bschussek@gmail.com>
|
||||
*/
|
||||
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'));
|
||||
|
@ -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 <bschussek@gmail.com>
|
||||
*/
|
||||
class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
|
||||
class SearchAndRenderBlockNode extends FunctionExpression
|
||||
{
|
||||
public function compile(\Twig_Compiler $compiler)
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$compiler->addDebugInfo($this);
|
||||
$compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(');
|
||||
@ -39,7 +44,7 @@ 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) {
|
||||
|
@ -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 <wouter@wouterj.nl>
|
||||
*/
|
||||
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)
|
||||
|
@ -11,22 +11,21 @@
|
||||
|
||||
namespace Symfony\Bridge\Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\AbstractExpression;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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('/(?<!%)%([^%]+)%/', $msg, $matches);
|
||||
|
||||
foreach ($matches[1] as $var) {
|
||||
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -15,6 +15,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\Twig\Extension\DumpExtension;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
|
||||
class DumpExtensionTest extends TestCase
|
||||
{
|
||||
@ -24,7 +26,7 @@ class DumpExtensionTest extends TestCase
|
||||
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
|
||||
{
|
||||
$extension = new DumpExtension(new VarCloner());
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array(
|
||||
$twig = new Environment(new ArrayLoader(array('template' => $template)), array(
|
||||
'debug' => $debug,
|
||||
'cache' => false,
|
||||
'optimizations' => 0,
|
||||
@ -64,7 +66,7 @@ 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,
|
||||
|
@ -13,6 +13,8 @@ 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
|
||||
{
|
||||
@ -21,7 +23,7 @@ class ExpressionExtensionTest extends TestCase
|
||||
public function testExpressionCreation()
|
||||
{
|
||||
$template = "{{ expression('1 == 1') }}";
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_Array(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
||||
$twig = new Environment(new ArrayLoader(array('template' => $template)), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
||||
$twig->addExtension(new ExpressionExtension());
|
||||
|
||||
$output = $twig->render('template');
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
@ -48,7 +49,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($this->extension);
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
@ -48,7 +49,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($this->extension);
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
@ -49,7 +50,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
|
||||
|
@ -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
|
||||
{
|
||||
@ -48,7 +49,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($this->extension);
|
||||
|
@ -16,11 +16,13 @@ use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
|
||||
class HttpKernelExtensionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Twig_Error_Runtime
|
||||
* @expectedException \Twig\Error\RuntimeError
|
||||
*/
|
||||
public function testFragmentWithError()
|
||||
{
|
||||
@ -74,8 +76,8 @@ 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($renderer));
|
||||
|
||||
return $twig->render('index');
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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()) {
|
||||
@ -94,14 +98,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()) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 <goetas@gmail.com>
|
||||
@ -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(
|
||||
@ -53,7 +57,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);
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
|
@ -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,
|
||||
|
@ -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 }',
|
||||
)));
|
||||
|
@ -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 <julien.galenski@gmail.com>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
@ -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 <wouter@wouterj.nl>
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.9",
|
||||
"twig/twig": "~1.28|~2.0"
|
||||
"twig/twig": "~1.34|~2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/asset": "~2.7",
|
||||
|
@ -25,7 +25,7 @@ class LegacyContainerAwareHIncludeFragmentRendererTest extends TestCase
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnValue($this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock()))
|
||||
->will($this->returnValue($this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock()))
|
||||
;
|
||||
$renderer = new ContainerAwareHIncludeFragmentRenderer($container);
|
||||
$renderer->render('/', Request::create('/'));
|
||||
|
@ -24,7 +24,7 @@
|
||||
"symfony/event-dispatcher": "~2.5",
|
||||
"symfony/finder": "^2.0.5",
|
||||
"symfony/http-foundation": "~2.7",
|
||||
"symfony/http-kernel": "~2.7.25|^2.8.18",
|
||||
"symfony/http-kernel": "~2.7.29|^2.8.22",
|
||||
"symfony/filesystem": "~2.3",
|
||||
"symfony/routing": "~2.7.24|^2.8.17",
|
||||
"symfony/security-core": "~2.6.13|~2.7.9|~2.8",
|
||||
|
@ -14,6 +14,8 @@ namespace Symfony\Bundle\SecurityBundle\Twig\Extension;
|
||||
@trigger_error('The '.__NAMESPACE__.'\LogoutUrlExtension class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* LogoutUrlHelper provides generator functions for the logout URL to Twig.
|
||||
@ -22,7 +24,7 @@ use Symfony\Bundle\SecurityBundle\Templating\Helper\LogoutUrlHelper;
|
||||
*
|
||||
* @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\LogoutUrlExtension instead.
|
||||
*/
|
||||
class LogoutUrlExtension extends \Twig_Extension
|
||||
class LogoutUrlExtension extends AbstractExtension
|
||||
{
|
||||
private $helper;
|
||||
|
||||
@ -37,8 +39,8 @@ 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')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
"symfony/yaml": "^2.0.5",
|
||||
"symfony/expression-language": "~2.6",
|
||||
"doctrine/doctrine-bundle": "~1.2",
|
||||
"twig/twig": "~1.28|~2.0",
|
||||
"twig/twig": "~1.34|~2.4",
|
||||
"ircmaxell/password-compat": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Bundle\TwigBundle\CacheWarmer;
|
||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
|
||||
use Twig\Error\Error;
|
||||
|
||||
/**
|
||||
* Generates the Twig cache for all templates.
|
||||
@ -65,7 +66,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface
|
||||
|
||||
try {
|
||||
$twig->loadTemplate($template);
|
||||
} catch (\Twig_Error $e) {
|
||||
} catch (Error $e) {
|
||||
// problem during compilation, give up
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Templating\TemplateReferenceInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Loader\ExistsLoaderInterface;
|
||||
|
||||
/**
|
||||
* ExceptionController renders error or exception pages for a given
|
||||
@ -34,7 +37,7 @@ class ExceptionController
|
||||
*/
|
||||
protected $debug;
|
||||
|
||||
public function __construct(\Twig_Environment $twig, $debug)
|
||||
public function __construct(Environment $twig, $debug)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->debug = $debug;
|
||||
@ -131,7 +134,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);
|
||||
}
|
||||
|
||||
@ -139,7 +142,7 @@ class ExceptionController
|
||||
$loader->getSourceContext($template)->getCode();
|
||||
|
||||
return true;
|
||||
} catch (\Twig_Error_Loader $e) {
|
||||
} catch (LoaderError $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -17,6 +17,7 @@ use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Times the time spent to render a template.
|
||||
@ -29,15 +30,7 @@ class TimedTwigEngine extends TwigEngine
|
||||
{
|
||||
protected $stopwatch;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \Twig_Environment $environment A \Twig_Environment instance
|
||||
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
|
||||
* @param FileLocatorInterface $locator A FileLocatorInterface instance
|
||||
* @param Stopwatch $stopwatch A Stopwatch instance
|
||||
*/
|
||||
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch)
|
||||
public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $locator, Stopwatch $stopwatch)
|
||||
{
|
||||
parent::__construct($environment, $parser, $locator);
|
||||
|
||||
|
@ -170,7 +170,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()
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ namespace Symfony\Bundle\TwigBundle\Extension;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
|
||||
/**
|
||||
* Twig extension for Symfony actions helper.
|
||||
@ -22,7 +24,7 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
*
|
||||
* @deprecated since version 2.2, to be removed in 3.0.
|
||||
*/
|
||||
class ActionsExtension extends \Twig_Extension
|
||||
class ActionsExtension extends AbstractExtension
|
||||
{
|
||||
private $handler;
|
||||
|
||||
@ -69,7 +71,7 @@ class ActionsExtension extends \Twig_Extension
|
||||
/**
|
||||
* Returns the token parser instance to add to the existing list.
|
||||
*
|
||||
* @return array An array of \Twig_TokenParser instances
|
||||
* @return AbstractTokenParser[]
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
|
@ -11,10 +11,12 @@
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\Extension;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\AssetsExtension class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Bridge\Twig\Extension\AssetExtension class instead.', E_USER_DEPRECATED);
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Twig extension for Symfony assets helper.
|
||||
@ -23,7 +25,7 @@ use Symfony\Component\Routing\RequestContext;
|
||||
*
|
||||
* @deprecated since 2.7, to be removed in 3.0. Use Symfony\Bridge\Twig\Extension\AssetExtension instead.
|
||||
*/
|
||||
class AssetsExtension extends \Twig_Extension
|
||||
class AssetsExtension extends AbstractExtension
|
||||
{
|
||||
private $container;
|
||||
private $context;
|
||||
@ -42,8 +44,8 @@ class AssetsExtension extends \Twig_Extension
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
|
||||
new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion')),
|
||||
new TwigFunction('asset', array($this, 'getAssetUrl')),
|
||||
new TwigFunction('assets_version', array($this, 'getAssetsVersion')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
class FilesystemLoader extends \Twig_Loader_Filesystem
|
||||
class FilesystemLoader extends BaseFilesystemLoader
|
||||
{
|
||||
protected $locator;
|
||||
protected $parser;
|
||||
@ -58,11 +60,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)
|
||||
{
|
||||
@ -76,7 +78,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
|
||||
|
@ -11,6 +11,10 @@
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\AbstractExpression;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* Represents a render node.
|
||||
*
|
||||
@ -18,19 +22,14 @@ namespace Symfony\Bundle\TwigBundle\Node;
|
||||
*
|
||||
* @deprecated since version 2.2, to be removed in 3.0.
|
||||
*/
|
||||
class RenderNode extends \Twig_Node
|
||||
class RenderNode extends Node
|
||||
{
|
||||
public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $options, $lineno, $tag = null)
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $options, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('expr' => $expr, 'options' => $options), array(), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param \Twig_Compiler $compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile(\Twig_Compiler $compiler)
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
|
@ -5,9 +5,9 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="twig.class">Twig_Environment</parameter>
|
||||
<parameter key="twig.class">Twig\Environment</parameter>
|
||||
<parameter key="twig.loader.filesystem.class">Symfony\Bundle\TwigBundle\Loader\FilesystemLoader</parameter>
|
||||
<parameter key="twig.loader.chain.class">Twig_Loader_Chain</parameter>
|
||||
<parameter key="twig.loader.chain.class">Twig\Loader\ChainLoader</parameter>
|
||||
<parameter key="templating.engine.twig.class">Symfony\Bundle\TwigBundle\TwigEngine</parameter>
|
||||
<parameter key="twig.cache_warmer.class">Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer</parameter>
|
||||
<parameter key="twig.extension.trans.class">Symfony\Bridge\Twig\Extension\TranslationExtension</parameter>
|
||||
@ -51,7 +51,7 @@
|
||||
<argument type="service" id="templating.finder" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
|
||||
<service id="twig.loader.native_filesystem" class="Twig\Loader\FilesystemLoader" public="false">
|
||||
<argument type="collection" />
|
||||
<tag name="twig.loader"/>
|
||||
</service>
|
||||
@ -63,7 +63,7 @@
|
||||
<argument type="service" id="debug.stopwatch" on-invalid="null" />
|
||||
</service>
|
||||
|
||||
<service id="twig.profile" class="Twig_Profiler_Profile" />
|
||||
<service id="twig.profile" class="Twig\Profiler\Profile" />
|
||||
|
||||
<service id="data_collector.twig" class="Symfony\Bridge\Twig\DataCollector\TwigDataCollector" public="false">
|
||||
<tag name="data_collector" template="@WebProfiler/Collector/twig.html.twig" id="twig" priority="255" />
|
||||
@ -117,7 +117,7 @@
|
||||
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false" />
|
||||
<service id="twig.extension.debug" class="Twig\Extension\DebugExtension" public="false" />
|
||||
|
||||
<service id="twig.translation.extractor" class="%twig.translation.extractor.class%">
|
||||
<argument type="service" id="twig" />
|
||||
|
@ -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(
|
||||
'TwigBundle: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(
|
||||
'TwigBundle:Exception:error.html.twig' => 'html',
|
||||
))
|
||||
);
|
||||
|
@ -26,7 +26,7 @@ class ExtensionPassTest extends TestCase
|
||||
$container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable');
|
||||
$container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine');
|
||||
|
||||
$nativeTwigLoader = new Definition('\Twig_Loader_Filesystem');
|
||||
$nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader');
|
||||
$nativeTwigLoader->addMethodCall('addPath', array());
|
||||
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);
|
||||
|
||||
|
@ -66,7 +66,7 @@ class TwigExtensionTest extends TestCase
|
||||
$container->loadFromExtension('twig', array());
|
||||
$this->compileContainer($container);
|
||||
|
||||
$this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');
|
||||
$this->assertEquals('Twig\Environment', $container->getParameter('twig.class'), '->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');
|
||||
|
||||
@ -87,7 +87,7 @@ class TwigExtensionTest extends TestCase
|
||||
$this->loadFromFile($container, 'full', $format);
|
||||
$this->compileContainer($container);
|
||||
|
||||
$this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');
|
||||
$this->assertEquals('Twig\Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');
|
||||
|
||||
// Form resources
|
||||
$resources = $container->getParameter('twig.form.resources');
|
||||
|
@ -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()
|
||||
|
@ -14,6 +14,11 @@ namespace Symfony\Bundle\TwigBundle\Tests\TokenParser;
|
||||
use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||
use Symfony\Bundle\TwigBundle\Node\RenderNode;
|
||||
use Twig\Environment;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Parser;
|
||||
use Twig\Source;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
@ -25,10 +30,10 @@ class LegacyRenderTokenParserTest 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 RenderTokenParser());
|
||||
$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));
|
||||
}
|
||||
@ -39,8 +44,8 @@ class LegacyRenderTokenParserTest extends TestCase
|
||||
array(
|
||||
'{% render "foo" %}',
|
||||
new RenderNode(
|
||||
new \Twig_Node_Expression_Constant('foo', 1),
|
||||
new \Twig_Node_Expression_Array(array(), 1),
|
||||
new ConstantExpression('foo', 1),
|
||||
new ArrayExpression(array(), 1),
|
||||
1,
|
||||
'render'
|
||||
),
|
||||
@ -48,10 +53,10 @@ class LegacyRenderTokenParserTest extends TestCase
|
||||
array(
|
||||
'{% render "foo", {foo: 1} %}',
|
||||
new RenderNode(
|
||||
new \Twig_Node_Expression_Constant('foo', 1),
|
||||
new \Twig_Node_Expression_Array(array(
|
||||
new \Twig_Node_Expression_Constant('foo', 1),
|
||||
new \Twig_Node_Expression_Constant('1', 1),
|
||||
new ConstantExpression('foo', 1),
|
||||
new ArrayExpression(array(
|
||||
new ConstantExpression('foo', 1),
|
||||
new ConstantExpression('1', 1),
|
||||
), 1),
|
||||
1,
|
||||
'render'
|
||||
|
@ -12,6 +12,10 @@
|
||||
namespace Symfony\Bundle\TwigBundle\TokenParser;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\Node\RenderNode;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
|
||||
/**
|
||||
* Token Parser for the render tag.
|
||||
@ -20,29 +24,29 @@ use Symfony\Bundle\TwigBundle\Node\RenderNode;
|
||||
*
|
||||
* @deprecated since version 2.2, to be removed in 3.0.
|
||||
*/
|
||||
class RenderTokenParser extends \Twig_TokenParser
|
||||
class RenderTokenParser 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();
|
||||
|
||||
// options
|
||||
if ($this->parser->getStream()->test(\Twig_Token::PUNCTUATION_TYPE, ',')) {
|
||||
if ($this->parser->getStream()->test(Token::PUNCTUATION_TYPE, ',')) {
|
||||
$this->parser->getStream()->next();
|
||||
|
||||
$options = $this->parser->getExpressionParser()->parseExpression();
|
||||
} else {
|
||||
$options = new \Twig_Node_Expression_Array(array(), $token->getLine());
|
||||
$options = new ArrayExpression(array(), $token->getLine());
|
||||
}
|
||||
|
||||
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new RenderNode($expr, $options, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ 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;
|
||||
use Twig\FileExtensionEscapingStrategy;
|
||||
|
||||
/**
|
||||
* This engine renders Twig templates.
|
||||
@ -27,14 +30,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);
|
||||
|
||||
@ -43,13 +39,13 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.7, to be removed in 3.0.
|
||||
* Inject the escaping strategy on \Twig_Environment instead.
|
||||
* Inject the escaping strategy on Twig instead.
|
||||
*/
|
||||
public function setDefaultEscapingStrategy($strategy)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig_Environment object instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Inject the escaping strategy in the Twig\Environment object instead.', E_USER_DEPRECATED);
|
||||
|
||||
$this->environment->getExtension('Twig_Extension_Escaper')->setDefaultStrategy($strategy);
|
||||
$this->environment->getExtension('Twig\Extension\EscaperExtension')->setDefaultStrategy($strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,9 +54,9 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||
*/
|
||||
public function guessDefaultEscapingStrategy($name)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig\FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return \Twig_FileExtensionEscapingStrategy::guess($name);
|
||||
return FileExtensionEscapingStrategy::guess($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +66,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
|
||||
@ -88,7 +84,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)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
"php": ">=5.3.9",
|
||||
"symfony/asset": "~2.7",
|
||||
"symfony/twig-bridge": "~2.7",
|
||||
"twig/twig": "~1.28|~2.0",
|
||||
"twig/twig": "~1.34|~2.4",
|
||||
"symfony/http-foundation": "~2.5",
|
||||
"symfony/http-kernel": "~2.7.23|^2.8.16"
|
||||
},
|
||||
|
@ -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;
|
||||
|
@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* ProfilerController.
|
||||
@ -39,11 +40,11 @@ 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)
|
||||
*/
|
||||
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal')
|
||||
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, $toolbarPosition = 'normal')
|
||||
{
|
||||
$this->generator = $generator;
|
||||
$this->profiler = $profiler;
|
||||
|
@ -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;
|
||||
|
@ -18,6 +18,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.
|
||||
@ -41,7 +42,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|
||||
protected $position;
|
||||
protected $excludedAjaxPaths;
|
||||
|
||||
public function __construct(\Twig_Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt')
|
||||
public function __construct(Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt')
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
|
@ -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
|
||||
*/
|
||||
@ -123,19 +121,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;
|
||||
|
@ -24,7 +24,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()
|
||||
@ -48,7 +48,7 @@ class ProfilerControllerTest extends TestCase
|
||||
public function testReturns404onTokenNotFound()
|
||||
{
|
||||
$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()
|
||||
@ -76,7 +76,7 @@ class ProfilerControllerTest extends TestCase
|
||||
public function testSearchResult()
|
||||
{
|
||||
$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()
|
||||
|
@ -52,9 +52,9 @@ class WebProfilerExtensionTest extends TestCase
|
||||
$this->container->addScope(new Scope('request'));
|
||||
$this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
|
||||
$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);
|
||||
|
@ -288,7 +288,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));
|
||||
|
@ -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));
|
||||
|
||||
|
@ -12,13 +12,15 @@
|
||||
namespace Symfony\Bundle\WebProfilerBundle\Twig;
|
||||
|
||||
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Twig extension for the profiler.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class WebProfilerExtension extends \Twig_Extension
|
||||
class WebProfilerExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var ValueExporter
|
||||
@ -31,7 +33,7 @@ class WebProfilerExtension extends \Twig_Extension
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new \Twig_SimpleFunction('profiler_dump', array($this, 'dumpValue')),
|
||||
new TwigFunction('profiler_dump', array($this, 'dumpValue')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
"symfony/http-kernel": "~2.4",
|
||||
"symfony/routing": "~2.2",
|
||||
"symfony/twig-bridge": "~2.7",
|
||||
"twig/twig": "~1.28|~2.0"
|
||||
"twig/twig": "~1.34|~2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/config": "~2.2",
|
||||
|
@ -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 <p@tchwork.com>
|
||||
@ -96,7 +97,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);
|
||||
|
@ -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;
|
||||
@ -140,7 +143,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);
|
||||
}
|
||||
|
||||
@ -152,7 +155,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Twig_Error_Loader $e) {
|
||||
} catch (LoaderError $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -40,7 +40,8 @@
|
||||
"symfony/var-dumper": "~2.6"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/config": "<2.7"
|
||||
"symfony/config": "<2.7",
|
||||
"twig/twig": "<1.34|<2.4,>=2"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/browser-kit": "",
|
||||
|
Reference in New Issue
Block a user