Merge branch '3.2' into 3.3
* 3.2: typo [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null) Use namespaced Twig
This commit is contained in:
commit
e5a698e215
|
@ -19,7 +19,7 @@
|
||||||
"php": ">=5.5.9",
|
"php": ">=5.5.9",
|
||||||
"doctrine/common": "~2.4",
|
"doctrine/common": "~2.4",
|
||||||
"fig/link-util": "^1.0",
|
"fig/link-util": "^1.0",
|
||||||
"twig/twig": "~1.32|~2.2",
|
"twig/twig": "~1.34|~2.4",
|
||||||
"psr/cache": "~1.0",
|
"psr/cache": "~1.0",
|
||||||
"psr/container": "^1.0",
|
"psr/container": "^1.0",
|
||||||
"psr/link": "^1.0",
|
"psr/link": "^1.0",
|
||||||
|
|
|
@ -34,7 +34,7 @@ CHANGELOG
|
||||||
// ...
|
// ...
|
||||||
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
|
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
|
||||||
// require Twig 1.30+
|
// require Twig 1.30+
|
||||||
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
|
$twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader(array(
|
||||||
TwigRenderer::class => function () use ($rendererEngine, $csrfTokenManager) {
|
TwigRenderer::class => function () use ($rendererEngine, $csrfTokenManager) {
|
||||||
return new TwigRenderer($rendererEngine, $csrfTokenManager);
|
return new TwigRenderer($rendererEngine, $csrfTokenManager);
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists twig functions, filters, globals and tests present in the current project.
|
* Lists twig functions, filters, globals and tests present in the current project.
|
||||||
|
@ -35,18 +36,13 @@ class DebugCommand extends Command
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setTwigEnvironment(Environment $twig)
|
||||||
* Sets the twig environment.
|
|
||||||
*
|
|
||||||
* @param \Twig_Environment $twig
|
|
||||||
*/
|
|
||||||
public function setTwigEnvironment(\Twig_Environment $twig)
|
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Twig_Environment $twig
|
* @return Environment $twig
|
||||||
*/
|
*/
|
||||||
protected function getTwigEnvironment()
|
protected function getTwigEnvironment()
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,10 @@ use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Finder\Finder;
|
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.
|
* Command that will validate your template syntax and output encountered errors.
|
||||||
|
@ -37,18 +41,13 @@ class LintCommand extends Command
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setTwigEnvironment(Environment $twig)
|
||||||
* Sets the twig environment.
|
|
||||||
*
|
|
||||||
* @param \Twig_Environment $twig
|
|
||||||
*/
|
|
||||||
public function setTwigEnvironment(\Twig_Environment $twig)
|
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Twig_Environment $twig
|
* @return Environment $twig
|
||||||
*/
|
*/
|
||||||
protected function getTwigEnvironment()
|
protected function getTwigEnvironment()
|
||||||
{
|
{
|
||||||
|
@ -111,7 +110,7 @@ EOF
|
||||||
return $this->display($input, $output, $io, $filesInfo);
|
return $this->display($input, $output, $io, $filesInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFilesInfo(\Twig_Environment $twig, array $filenames)
|
private function getFilesInfo(Environment $twig, array $filenames)
|
||||||
{
|
{
|
||||||
$filesInfo = array();
|
$filesInfo = array();
|
||||||
foreach ($filenames as $filename) {
|
foreach ($filenames as $filename) {
|
||||||
|
@ -134,16 +133,16 @@ EOF
|
||||||
throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
|
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();
|
$realLoader = $twig->getLoader();
|
||||||
try {
|
try {
|
||||||
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
|
$temporaryLoader = new ArrayLoader(array((string) $file => $template));
|
||||||
$twig->setLoader($temporaryLoader);
|
$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->compile($nodeTree);
|
||||||
$twig->setLoader($realLoader);
|
$twig->setLoader($realLoader);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
$twig->setLoader($realLoader);
|
$twig->setLoader($realLoader);
|
||||||
|
|
||||||
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
|
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
|
||||||
|
@ -205,7 +204,7 @@ EOF
|
||||||
return min($errors, 1);
|
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();
|
$line = $exception->getTemplateLine();
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||||
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
|
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Twig\Markup;
|
||||||
|
use Twig\Profiler\Dumper\HtmlDumper;
|
||||||
|
use Twig\Profiler\Profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwigDataCollector.
|
* TwigDataCollector.
|
||||||
|
@ -26,7 +29,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||||
private $profile;
|
private $profile;
|
||||||
private $computed;
|
private $computed;
|
||||||
|
|
||||||
public function __construct(\Twig_Profiler_Profile $profile)
|
public function __construct(Profile $profile)
|
||||||
{
|
{
|
||||||
$this->profile = $profile;
|
$this->profile = $profile;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +76,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||||
|
|
||||||
public function getHtmlCallGraph()
|
public function getHtmlCallGraph()
|
||||||
{
|
{
|
||||||
$dumper = new \Twig_Profiler_Dumper_Html();
|
$dumper = new HtmlDumper();
|
||||||
$dump = $dumper->dump($this->getProfile());
|
$dump = $dumper->dump($this->getProfile());
|
||||||
|
|
||||||
// needed to remove the hardcoded CSS styles
|
// needed to remove the hardcoded CSS styles
|
||||||
|
@ -87,14 +90,14 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||||
'<span class="status-success">',
|
'<span class="status-success">',
|
||||||
), $dump);
|
), $dump);
|
||||||
|
|
||||||
return new \Twig_Markup($dump, 'UTF-8');
|
return new Markup($dump, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProfile()
|
public function getProfile()
|
||||||
{
|
{
|
||||||
if (null === $this->profile) {
|
if (null === $this->profile) {
|
||||||
if (PHP_VERSION_ID >= 70000) {
|
if (PHP_VERSION_ID >= 70000) {
|
||||||
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
|
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile', 'Twig\Profiler\Profile')));
|
||||||
} else {
|
} else {
|
||||||
$this->profile = unserialize($this->data['profile']);
|
$this->profile = unserialize($this->data['profile']);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +115,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
|
||||||
return $this->computed[$index];
|
return $this->computed[$index];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function computeData(\Twig_Profiler_Profile $profile)
|
private function computeData(Profile $profile)
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
'template_count' => 0,
|
'template_count' => 0,
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Asset\Packages;
|
use Symfony\Component\Asset\Packages;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for the Symfony Asset component.
|
* Twig extension for the Symfony Asset component.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class AssetExtension extends \Twig_Extension
|
class AssetExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $packages;
|
private $packages;
|
||||||
|
|
||||||
|
@ -33,8 +35,8 @@ class AssetExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
|
new TwigFunction('asset', array($this, 'getAssetUrl')),
|
||||||
new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')),
|
new TwigFunction('asset_version', array($this, 'getAssetVersion')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension relate to PHP code and used by the profiler and the default exception templates.
|
* Twig extension relate to PHP code and used by the profiler and the default exception templates.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class CodeExtension extends \Twig_Extension
|
class CodeExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $fileLinkFormat;
|
private $fileLinkFormat;
|
||||||
private $rootDir;
|
private $rootDir;
|
||||||
|
@ -44,15 +46,15 @@ class CodeExtension extends \Twig_Extension
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
|
new TwigFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
|
new TwigFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
|
new TwigFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('format_args_as_text', array($this, 'formatArgsAsText')),
|
new TwigFilter('format_args_as_text', array($this, 'formatArgsAsText')),
|
||||||
new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
|
new TwigFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
|
new TwigFilter('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 TwigFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))),
|
new TwigFilter('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')),
|
new TwigFilter('file_link', array($this, 'getFileLink')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,17 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
use Symfony\Bridge\Twig\TokenParser\DumpTokenParser;
|
use Symfony\Bridge\Twig\TokenParser\DumpTokenParser;
|
||||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
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.
|
* Provides integration of the dump() function with Twig.
|
||||||
*
|
*
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
*/
|
*/
|
||||||
class DumpExtension extends \Twig_Extension
|
class DumpExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $cloner;
|
private $cloner;
|
||||||
private $dumper;
|
private $dumper;
|
||||||
|
@ -34,7 +38,7 @@ class DumpExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
|
new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +52,7 @@ class DumpExtension extends \Twig_Extension
|
||||||
return 'dump';
|
return 'dump';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dump(\Twig_Environment $env, $context)
|
public function dump(Environment $env, $context)
|
||||||
{
|
{
|
||||||
if (!$env->isDebug()) {
|
if (!$env->isDebug()) {
|
||||||
return;
|
return;
|
||||||
|
@ -57,7 +61,7 @@ class DumpExtension extends \Twig_Extension
|
||||||
if (2 === func_num_args()) {
|
if (2 === func_num_args()) {
|
||||||
$vars = array();
|
$vars = array();
|
||||||
foreach ($context as $key => $value) {
|
foreach ($context as $key => $value) {
|
||||||
if (!$value instanceof \Twig_Template) {
|
if (!$value instanceof Template) {
|
||||||
$vars[$key] = $value;
|
$vars[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\ExpressionLanguage\Expression;
|
use Symfony\Component\ExpressionLanguage\Expression;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExpressionExtension gives a way to create Expressions from a template.
|
* ExpressionExtension gives a way to create Expressions from a template.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class ExpressionExtension extends \Twig_Extension
|
class ExpressionExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@ -26,7 +28,7 @@ class ExpressionExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('expression', array($this, 'createExpression')),
|
new TwigFunction('expression', array($this, 'createExpression')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,12 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
||||||
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\Extension\InitRuntimeInterface;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
use Twig\TwigTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormExtension extends Twig with form capabilities.
|
* FormExtension extends Twig with form capabilities.
|
||||||
|
@ -22,7 +28,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
|
class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below
|
* @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below
|
||||||
|
@ -32,7 +38,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||||
public function __construct($renderer = null)
|
public function __construct($renderer = null)
|
||||||
{
|
{
|
||||||
if ($renderer instanceof TwigRendererInterface) {
|
if ($renderer instanceof TwigRendererInterface) {
|
||||||
@trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig_Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED);
|
||||||
} elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) {
|
} elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__));
|
throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__));
|
||||||
}
|
}
|
||||||
|
@ -44,7 +50,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||||
*
|
*
|
||||||
* To be removed in 4.0
|
* To be removed in 4.0
|
||||||
*/
|
*/
|
||||||
public function initRuntime(\Twig_Environment $environment)
|
public function initRuntime(Environment $environment)
|
||||||
{
|
{
|
||||||
if ($this->renderer instanceof TwigRendererInterface) {
|
if ($this->renderer instanceof TwigRendererInterface) {
|
||||||
$this->renderer->setEnvironment($environment);
|
$this->renderer->setEnvironment($environment);
|
||||||
|
@ -70,15 +76,15 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
|
new TwigFunction('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 TwigFunction('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 TwigFunction('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 TwigFunction('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 TwigFunction('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 TwigFunction('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 TwigFunction('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 TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFunction('csrf_token', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')),
|
new TwigFunction('csrf_token', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +94,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')),
|
new TwigFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +104,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
||||||
public function getTests()
|
public function getTests()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
|
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\RequestContext;
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for the Symfony HttpFoundation component.
|
* Twig extension for the Symfony HttpFoundation component.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class HttpFoundationExtension extends \Twig_Extension
|
class HttpFoundationExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $requestStack;
|
private $requestStack;
|
||||||
private $requestContext;
|
private $requestContext;
|
||||||
|
@ -37,8 +39,8 @@ class HttpFoundationExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('absolute_url', array($this, 'generateAbsoluteUrl')),
|
new TwigFunction('absolute_url', array($this, 'generateAbsoluteUrl')),
|
||||||
new \Twig_SimpleFunction('relative_path', array($this, 'generateRelativePath')),
|
new TwigFunction('relative_path', array($this, 'generateRelativePath')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,20 +12,22 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
use Symfony\Component\HttpKernel\Controller\ControllerReference;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides integration with the HttpKernel component.
|
* Provides integration with the HttpKernel component.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class HttpKernelExtension extends \Twig_Extension
|
class HttpKernelExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('render', array(HttpKernelRuntime::class, 'renderFragment'), array('is_safe' => array('html'))),
|
new TwigFunction('render', array(HttpKernelRuntime::class, 'renderFragment'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFunction('render_*', array(HttpKernelRuntime::class, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
|
new TwigFunction('render_*', array(HttpKernelRuntime::class, 'renderFragmentStrategy'), array('is_safe' => array('html'))),
|
||||||
new \Twig_SimpleFunction('controller', static::class.'::controller'),
|
new TwigFunction('controller', static::class.'::controller'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
|
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LogoutUrlHelper provides generator functions for the logout URL to Twig.
|
* LogoutUrlHelper provides generator functions for the logout URL to Twig.
|
||||||
*
|
*
|
||||||
* @author Jeremy Mikola <jmikola@gmail.com>
|
* @author Jeremy Mikola <jmikola@gmail.com>
|
||||||
*/
|
*/
|
||||||
class LogoutUrlExtension extends \Twig_Extension
|
class LogoutUrlExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $generator;
|
private $generator;
|
||||||
|
|
||||||
|
@ -33,8 +35,8 @@ class LogoutUrlExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('logout_url', array($this, 'getLogoutUrl')),
|
new TwigFunction('logout_url', array($this, 'getLogoutUrl')),
|
||||||
new \Twig_SimpleFunction('logout_path', array($this, 'getLogoutPath')),
|
new TwigFunction('logout_path', array($this, 'getLogoutPath')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,18 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Stopwatch\Stopwatch;
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
use Twig\Extension\ProfilerExtension as BaseProfilerExtension;
|
||||||
|
use Twig\Profiler\Profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class ProfilerExtension extends \Twig_Extension_Profiler
|
class ProfilerExtension extends BaseProfilerExtension
|
||||||
{
|
{
|
||||||
private $stopwatch;
|
private $stopwatch;
|
||||||
private $events;
|
private $events;
|
||||||
|
|
||||||
public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch = null)
|
public function __construct(Profile $profile, Stopwatch $stopwatch = null)
|
||||||
{
|
{
|
||||||
parent::__construct($profile);
|
parent::__construct($profile);
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ class ProfilerExtension extends \Twig_Extension_Profiler
|
||||||
$this->events = new \SplObjectStorage();
|
$this->events = new \SplObjectStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enter(\Twig_Profiler_Profile $profile)
|
public function enter(Profile $profile)
|
||||||
{
|
{
|
||||||
if ($this->stopwatch && $profile->isTemplate()) {
|
if ($this->stopwatch && $profile->isTemplate()) {
|
||||||
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
|
$this->events[$profile] = $this->stopwatch->start($profile->getName(), 'template');
|
||||||
|
@ -38,7 +40,7 @@ class ProfilerExtension extends \Twig_Extension_Profiler
|
||||||
parent::enter($profile);
|
parent::enter($profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(\Twig_Profiler_Profile $profile)
|
public function leave(Profile $profile)
|
||||||
{
|
{
|
||||||
parent::leave($profile);
|
parent::leave($profile);
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,18 @@
|
||||||
namespace Symfony\Bridge\Twig\Extension;
|
namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
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.
|
* Provides integration of the Routing component with Twig.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class RoutingExtension extends \Twig_Extension
|
class RoutingExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $generator;
|
private $generator;
|
||||||
|
|
||||||
|
@ -35,8 +40,8 @@ class RoutingExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('url', array($this, 'getUrl'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
|
new TwigFunction('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('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'})
|
* - 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.
|
* 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
|
* @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)
|
public function isUrlGenerationSafe(\Twig_Node $argsNode)
|
||||||
{
|
{
|
||||||
|
@ -93,8 +100,8 @@ class RoutingExtension extends \Twig_Extension
|
||||||
$argsNode->hasNode(1) ? $argsNode->getNode(1) : null
|
$argsNode->hasNode(1) ? $argsNode->getNode(1) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
if (null === $paramsNode || $paramsNode instanceof \Twig_Node_Expression_Array && count($paramsNode) <= 2 &&
|
if (null === $paramsNode || $paramsNode instanceof ArrayExpression && count($paramsNode) <= 2 &&
|
||||||
(!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof \Twig_Node_Expression_Constant)
|
(!$paramsNode->hasNode(1) || $paramsNode->getNode(1) instanceof ConstantExpression)
|
||||||
) {
|
) {
|
||||||
return array('html');
|
return array('html');
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
use Symfony\Component\Security\Acl\Voter\FieldVote;
|
use Symfony\Component\Security\Acl\Voter\FieldVote;
|
||||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
|
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SecurityExtension exposes security context features.
|
* SecurityExtension exposes security context features.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class SecurityExtension extends \Twig_Extension
|
class SecurityExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $securityChecker;
|
private $securityChecker;
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class SecurityExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
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\Component\Stopwatch\Stopwatch;
|
||||||
use Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser;
|
use Symfony\Bridge\Twig\TokenParser\StopwatchTokenParser;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for the stopwatch helper.
|
* Twig extension for the stopwatch helper.
|
||||||
*
|
*
|
||||||
* @author Wouter J <wouter@wouterj.nl>
|
* @author Wouter J <wouter@wouterj.nl>
|
||||||
*/
|
*/
|
||||||
class StopwatchExtension extends \Twig_Extension
|
class StopwatchExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $stopwatch;
|
private $stopwatch;
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,22 @@ use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
||||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
|
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.
|
* Provides integration of the Translation component with Twig.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TranslationExtension extends \Twig_Extension
|
class TranslationExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $translator;
|
private $translator;
|
||||||
private $translationNodeVisitor;
|
private $translationNodeVisitor;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator, \Twig_NodeVisitorInterface $translationNodeVisitor = null)
|
public function __construct(TranslatorInterface $translator, NodeVisitorInterface $translationNodeVisitor = null)
|
||||||
{
|
{
|
||||||
if (!$translationNodeVisitor) {
|
if (!$translationNodeVisitor) {
|
||||||
$translationNodeVisitor = new TranslationNodeVisitor();
|
$translationNodeVisitor = new TranslationNodeVisitor();
|
||||||
|
@ -49,15 +53,15 @@ class TranslationExtension extends \Twig_Extension
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFilter('trans', array($this, 'trans')),
|
new TwigFilter('trans', array($this, 'trans')),
|
||||||
new \Twig_SimpleFilter('transchoice', array($this, 'transchoice')),
|
new TwigFilter('transchoice', array($this, 'transchoice')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the token parser instance to add to the existing list.
|
* Returns the token parser instance to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return array An array of Twig_TokenParser instances
|
* @return AbstractTokenParser[]
|
||||||
*/
|
*/
|
||||||
public function getTokenParsers()
|
public function getTokenParsers()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,13 +14,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
use Fig\Link\GenericLinkProvider;
|
use Fig\Link\GenericLinkProvider;
|
||||||
use Fig\Link\Link;
|
use Fig\Link\Link;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for the Symfony WebLink component.
|
* Twig extension for the Symfony WebLink component.
|
||||||
*
|
*
|
||||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||||
*/
|
*/
|
||||||
class WebLinkExtension extends \Twig_Extension
|
class WebLinkExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $requestStack;
|
private $requestStack;
|
||||||
|
|
||||||
|
@ -35,12 +37,12 @@ class WebLinkExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('link', array($this, 'link')),
|
new TwigFunction('link', array($this, 'link')),
|
||||||
new \Twig_SimpleFunction('preload', array($this, 'preload')),
|
new TwigFunction('preload', array($this, 'preload')),
|
||||||
new \Twig_SimpleFunction('dns_prefetch', array($this, 'dnsPrefetch')),
|
new TwigFunction('dns_prefetch', array($this, 'dnsPrefetch')),
|
||||||
new \Twig_SimpleFunction('preconnect', array($this, 'preconnect')),
|
new TwigFunction('preconnect', array($this, 'preconnect')),
|
||||||
new \Twig_SimpleFunction('prefetch', array($this, 'prefetch')),
|
new TwigFunction('prefetch', array($this, 'prefetch')),
|
||||||
new \Twig_SimpleFunction('prerender', array($this, 'prerender')),
|
new TwigFunction('prerender', array($this, 'prerender')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use Symfony\Component\Workflow\Transition;
|
use Symfony\Component\Workflow\Transition;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorkflowExtension.
|
* WorkflowExtension.
|
||||||
*
|
*
|
||||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||||
*/
|
*/
|
||||||
class WorkflowExtension extends \Twig_Extension
|
class WorkflowExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private $workflowRegistry;
|
private $workflowRegistry;
|
||||||
|
|
||||||
|
@ -31,10 +33,10 @@ class WorkflowExtension extends \Twig_Extension
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')),
|
new TwigFunction('workflow_can', array($this, 'canTransition')),
|
||||||
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
|
new TwigFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
|
||||||
new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
|
new TwigFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
|
||||||
new \Twig_SimpleFunction('workflow_marked_places', array($this, 'getMarkedPlaces')),
|
new TwigFunction('workflow_marked_places', array($this, 'getMarkedPlaces')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Extension;
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Dumper as YamlDumper;
|
use Symfony\Component\Yaml\Dumper as YamlDumper;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides integration of the Yaml component with Twig.
|
* Provides integration of the Yaml component with Twig.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class YamlExtension extends \Twig_Extension
|
class YamlExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@ -27,8 +29,8 @@ class YamlExtension extends \Twig_Extension
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFilter('yaml_encode', array($this, 'encode')),
|
new TwigFilter('yaml_encode', array($this, 'encode')),
|
||||||
new \Twig_SimpleFilter('yaml_dump', array($this, 'dump')),
|
new TwigFilter('yaml_dump', array($this, 'dump')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormRenderer;
|
use Symfony\Component\Form\FormRenderer;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
@ -34,7 +35,7 @@ class TwigRenderer extends FormRenderer implements TwigRendererInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setEnvironment(\Twig_Environment $environment)
|
public function setEnvironment(Environment $environment)
|
||||||
{
|
{
|
||||||
$this->engine->setEnvironment($environment);
|
$this->engine->setEnvironment($environment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ namespace Symfony\Bridge\Twig\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\AbstractRendererEngine;
|
use Symfony\Component\Form\AbstractRendererEngine;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
@ -20,16 +22,16 @@ use Symfony\Component\Form\FormView;
|
||||||
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
|
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Twig_Environment
|
* @var Environment
|
||||||
*/
|
*/
|
||||||
private $environment;
|
private $environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Twig_Template
|
* @var Template
|
||||||
*/
|
*/
|
||||||
private $template;
|
private $template;
|
||||||
|
|
||||||
public function __construct(array $defaultThemes = array(), \Twig_Environment $environment = null)
|
public function __construct(array $defaultThemes = array(), Environment $environment = null)
|
||||||
{
|
{
|
||||||
if (null === $environment) {
|
if (null === $environment) {
|
||||||
@trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED);
|
||||||
|
@ -44,7 +46,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
|
||||||
*
|
*
|
||||||
* @deprecated since version 3.3, to be removed in 4.0
|
* @deprecated since version 3.3, to be removed in 4.0
|
||||||
*/
|
*/
|
||||||
public function setEnvironment(\Twig_Environment $environment)
|
public function setEnvironment(Environment $environment)
|
||||||
{
|
{
|
||||||
if ($this->environment) {
|
if ($this->environment) {
|
||||||
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Pass the Twig Environment as second argument of the constructor instead.', __METHOD__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Pass the Twig Environment as second argument of the constructor instead.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
@ -166,13 +168,13 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
|
||||||
*/
|
*/
|
||||||
protected function loadResourcesFromTheme($cacheKey, &$theme)
|
protected function loadResourcesFromTheme($cacheKey, &$theme)
|
||||||
{
|
{
|
||||||
if (!$theme instanceof \Twig_Template) {
|
if (!$theme instanceof Template) {
|
||||||
/* @var \Twig_Template $theme */
|
/* @var Template $theme */
|
||||||
$theme = $this->environment->loadTemplate($theme);
|
$theme = $this->environment->loadTemplate($theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->template) {
|
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*
|
// we can call displayBlock() later on. It doesn't matter *which*
|
||||||
// template we use for that, since we pass the used blocks manually
|
// template we use for that, since we pass the used blocks manually
|
||||||
// anyway.
|
// anyway.
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
namespace Symfony\Bridge\Twig\Form;
|
namespace Symfony\Bridge\Twig\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormRendererEngineInterface;
|
use Symfony\Component\Form\FormRendererEngineInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
// BC/FC with namespaced Twig
|
||||||
|
class_exists('Twig\Environment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
@ -20,10 +24,5 @@ use Symfony\Component\Form\FormRendererEngineInterface;
|
||||||
*/
|
*/
|
||||||
interface TwigRendererEngineInterface extends FormRendererEngineInterface
|
interface TwigRendererEngineInterface extends FormRendererEngineInterface
|
||||||
{
|
{
|
||||||
/**
|
public function setEnvironment(Environment $environment);
|
||||||
* Sets Twig's environment.
|
|
||||||
*
|
|
||||||
* @param \Twig_Environment $environment
|
|
||||||
*/
|
|
||||||
public function setEnvironment(\Twig_Environment $environment);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
namespace Symfony\Bridge\Twig\Form;
|
namespace Symfony\Bridge\Twig\Form;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormRendererInterface;
|
use Symfony\Component\Form\FormRendererInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
// BC/FC with namespaced Twig
|
||||||
|
class_exists('Twig\Environment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
@ -20,10 +24,5 @@ use Symfony\Component\Form\FormRendererInterface;
|
||||||
*/
|
*/
|
||||||
interface TwigRendererInterface extends FormRendererInterface
|
interface TwigRendererInterface extends FormRendererInterface
|
||||||
{
|
{
|
||||||
/**
|
public function setEnvironment(Environment $environment);
|
||||||
* Sets Twig's environment.
|
|
||||||
*
|
|
||||||
* @param \Twig_Environment $environment
|
|
||||||
*/
|
|
||||||
public function setEnvironment(\Twig_Environment $environment);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,17 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Julien Galenski <julien.galenski@gmail.com>
|
* @author Julien Galenski <julien.galenski@gmail.com>
|
||||||
*/
|
*/
|
||||||
class DumpNode extends \Twig_Node
|
class DumpNode extends Node
|
||||||
{
|
{
|
||||||
private $varPrefix;
|
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();
|
$nodes = array();
|
||||||
if (null !== $values) {
|
if (null !== $values) {
|
||||||
|
@ -32,7 +35,7 @@ class DumpNode extends \Twig_Node
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function compile(\Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->write("if (\$this->env->isDebug()) {\n")
|
->write("if (\$this->env->isDebug()) {\n")
|
||||||
|
@ -44,7 +47,7 @@ class DumpNode extends \Twig_Node
|
||||||
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
||||||
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
|
->write(sprintf('foreach ($context as $%1$skey => $%1$sval) {'."\n", $this->varPrefix))
|
||||||
->indent()
|
->indent()
|
||||||
->write(sprintf('if (!$%sval instanceof \Twig_Template) {'."\n", $this->varPrefix))
|
->write(sprintf('if (!$%sval instanceof \Twig\Template) {'."\n", $this->varPrefix))
|
||||||
->indent()
|
->indent()
|
||||||
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
|
->write(sprintf('$%1$svars[$%1$skey] = $%1$sval;'."\n", $this->varPrefix))
|
||||||
->outdent()
|
->outdent()
|
||||||
|
|
|
@ -11,22 +11,20 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @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);
|
parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function compile(Compiler $compiler)
|
||||||
* Compiles the node to PHP.
|
|
||||||
*
|
|
||||||
* @param \Twig_Compiler $compiler A Twig_Compiler instance
|
|
||||||
*/
|
|
||||||
public function compile(\Twig_Compiler $compiler)
|
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\FunctionExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles a call to {@link \Symfony\Component\Form\FormRendererInterface::renderBlock()}.
|
* 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>
|
* @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);
|
$compiler->addDebugInfo($this);
|
||||||
$arguments = iterator_to_array($this->getNode('arguments'));
|
$arguments = iterator_to_array($this->getNode('arguments'));
|
||||||
|
|
|
@ -11,12 +11,17 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
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>
|
* @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->addDebugInfo($this);
|
||||||
$compiler->raw('$this->env->getRuntime(\'Symfony\Bridge\Twig\Form\TwigRenderer\')->searchAndRenderBlock(');
|
$compiler->raw('$this->env->getRuntime(\'Symfony\Bridge\Twig\Form\TwigRenderer\')->searchAndRenderBlock(');
|
||||||
|
@ -39,7 +44,7 @@ class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
|
||||||
$variables = isset($arguments[2]) ? $arguments[2] : null;
|
$variables = isset($arguments[2]) ? $arguments[2] : null;
|
||||||
$lineno = $label->getTemplateLine();
|
$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
|
// 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
|
// strip it away if it is empty, or integrate it into the array
|
||||||
// of variables at compile time.
|
// 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
|
// Only insert the label into the array if it is not empty
|
||||||
if (!twig_test_empty($label->getAttribute('value'))) {
|
if (!twig_test_empty($label->getAttribute('value'))) {
|
||||||
$originalVariables = $variables;
|
$originalVariables = $variables;
|
||||||
$variables = new \Twig_Node_Expression_Array(array(), $lineno);
|
$variables = new ArrayExpression(array(), $lineno);
|
||||||
$labelKey = new \Twig_Node_Expression_Constant('label', $lineno);
|
$labelKey = new ConstantExpression('label', $lineno);
|
||||||
|
|
||||||
if (null !== $originalVariables) {
|
if (null !== $originalVariables) {
|
||||||
foreach ($originalVariables->getKeyValuePairs() as $pair) {
|
foreach ($originalVariables->getKeyValuePairs() as $pair) {
|
||||||
|
|
|
@ -11,19 +11,23 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AssignNameExpression;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a stopwatch node.
|
* Represents a stopwatch node.
|
||||||
*
|
*
|
||||||
* @author Wouter J <wouter@wouterj.nl>
|
* @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);
|
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(\Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
|
|
|
@ -11,22 +11,21 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @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);
|
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function compile(Compiler $compiler)
|
||||||
* Compiles the node to PHP.
|
|
||||||
*
|
|
||||||
* @param \Twig_Compiler $compiler A Twig_Compiler instance
|
|
||||||
*/
|
|
||||||
public function compile(\Twig_Compiler $compiler)
|
|
||||||
{
|
{
|
||||||
// noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
|
// noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,23 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Node;
|
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>
|
* @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);
|
$nodes = array('body' => $body);
|
||||||
if (null !== $domain) {
|
if (null !== $domain) {
|
||||||
|
@ -35,17 +46,12 @@ class TransNode extends \Twig_Node
|
||||||
parent::__construct($nodes, array(), $lineno, $tag);
|
parent::__construct($nodes, array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function compile(Compiler $compiler)
|
||||||
* Compiles the node to PHP.
|
|
||||||
*
|
|
||||||
* @param \Twig_Compiler $compiler A Twig_Compiler instance
|
|
||||||
*/
|
|
||||||
public function compile(\Twig_Compiler $compiler)
|
|
||||||
{
|
{
|
||||||
$compiler->addDebugInfo($this);
|
$compiler->addDebugInfo($this);
|
||||||
|
|
||||||
$defaults = new \Twig_Node_Expression_Array(array(), -1);
|
$defaults = new ArrayExpression(array(), -1);
|
||||||
if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof \Twig_Node_Expression_Array) {
|
if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof ArrayExpression) {
|
||||||
$defaults = $this->getNode('vars');
|
$defaults = $this->getNode('vars');
|
||||||
$vars = null;
|
$vars = null;
|
||||||
}
|
}
|
||||||
|
@ -96,11 +102,11 @@ class TransNode extends \Twig_Node
|
||||||
$compiler->raw(");\n");
|
$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');
|
$msg = $body->getAttribute('value');
|
||||||
} elseif ($body instanceof \Twig_Node_Text) {
|
} elseif ($body instanceof TextNode) {
|
||||||
$msg = $body->getAttribute('data');
|
$msg = $body->getAttribute('data');
|
||||||
} else {
|
} else {
|
||||||
return array($body, $vars);
|
return array($body, $vars);
|
||||||
|
@ -109,18 +115,18 @@ class TransNode extends \Twig_Node
|
||||||
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
|
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
|
||||||
|
|
||||||
foreach ($matches[1] as $var) {
|
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 (!$vars->hasElement($key)) {
|
||||||
if ('count' === $var && $this->hasNode('count')) {
|
if ('count' === $var && $this->hasNode('count')) {
|
||||||
$vars->addElement($this->getNode('count'), $key);
|
$vars->addElement($this->getNode('count'), $key);
|
||||||
} else {
|
} else {
|
||||||
$varExpr = new \Twig_Node_Expression_Name($var, $body->getTemplateLine());
|
$varExpr = new NameExpression($var, $body->getTemplateLine());
|
||||||
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
||||||
$vars->addElement($varExpr, $key);
|
$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\TransNode;
|
||||||
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
|
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.
|
* TranslationDefaultDomainNodeVisitor.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
|
class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Scope
|
* @var Scope
|
||||||
|
@ -37,23 +46,23 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$this->scope = $this->scope->enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof TransDefaultDomainNode) {
|
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'));
|
$this->scope->set('domain', $node->getNode('expr'));
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
} else {
|
} else {
|
||||||
$var = $this->getVarName();
|
$var = $this->getVarName();
|
||||||
$name = new \Twig_Node_Expression_AssignName($var, $node->getTemplateLine());
|
$name = new AssignNameExpression($var, $node->getTemplateLine());
|
||||||
$this->scope->set('domain', new \Twig_Node_Expression_Name($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;
|
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');
|
$arguments = $node->getNode('arguments');
|
||||||
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
|
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
|
||||||
if ($this->isNamedArguments($arguments)) {
|
if ($this->isNamedArguments($arguments)) {
|
||||||
|
@ -71,7 +80,7 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
} else {
|
} else {
|
||||||
if (!$arguments->hasNode($ind)) {
|
if (!$arguments->hasNode($ind)) {
|
||||||
if (!$arguments->hasNode($ind - 1)) {
|
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'));
|
$arguments->setNode($ind, $this->scope->get('domain'));
|
||||||
|
@ -89,13 +98,13 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
|
protected function doLeaveNode(Node $node, Environment $env)
|
||||||
{
|
{
|
||||||
if ($node instanceof TransDefaultDomainNode) {
|
if ($node instanceof TransDefaultDomainNode) {
|
||||||
return false;
|
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();
|
$this->scope = $this->scope->leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,18 @@
|
||||||
namespace Symfony\Bridge\Twig\NodeVisitor;
|
namespace Symfony\Bridge\Twig\NodeVisitor;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\TransNode;
|
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.
|
* TranslationNodeVisitor extracts translation messages.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
class TranslationNodeVisitor extends AbstractNodeVisitor
|
||||||
{
|
{
|
||||||
const UNDEFINED_DOMAIN = '_undefined';
|
const UNDEFINED_DOMAIN = '_undefined';
|
||||||
|
|
||||||
|
@ -45,16 +50,16 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
|
protected function doEnterNode(Node $node, Environment $env)
|
||||||
{
|
{
|
||||||
if (!$this->enabled) {
|
if (!$this->enabled) {
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$node instanceof \Twig_Node_Expression_Filter &&
|
$node instanceof FilterExpression &&
|
||||||
'trans' === $node->getNode('filter')->getAttribute('value') &&
|
'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
|
// extract constant nodes with a trans filter
|
||||||
$this->messages[] = array(
|
$this->messages[] = array(
|
||||||
|
@ -62,9 +67,9 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
|
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
|
||||||
);
|
);
|
||||||
} elseif (
|
} elseif (
|
||||||
$node instanceof \Twig_Node_Expression_Filter &&
|
$node instanceof FilterExpression &&
|
||||||
'transchoice' === $node->getNode('filter')->getAttribute('value') &&
|
'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
|
// extract constant nodes with a trans filter
|
||||||
$this->messages[] = array(
|
$this->messages[] = array(
|
||||||
|
@ -85,7 +90,7 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
|
protected function doLeaveNode(Node $node, Environment $env)
|
||||||
{
|
{
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
@ -99,12 +104,12 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Twig_Node $arguments
|
* @param Node $arguments
|
||||||
* @param int $index
|
* @param int $index
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
|
private function getReadDomainFromArguments(Node $arguments, $index)
|
||||||
{
|
{
|
||||||
if ($arguments->hasNode('domain')) {
|
if ($arguments->hasNode('domain')) {
|
||||||
$argument = $arguments->getNode('domain');
|
$argument = $arguments->getNode('domain');
|
||||||
|
@ -118,13 +123,13 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Twig_Node $node
|
* @param Node $node
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @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');
|
return $node->getAttribute('value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ use Symfony\Bridge\Twig\Command\LintCommand;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class LintCommandTest extends TestCase
|
class LintCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -71,7 +73,7 @@ class LintCommandTest extends TestCase
|
||||||
*/
|
*/
|
||||||
private function createCommandTester()
|
private function createCommandTester()
|
||||||
{
|
{
|
||||||
$twig = new \Twig_Environment(new \Twig_Loader_Filesystem());
|
$twig = new Environment(new FilesystemLoader());
|
||||||
|
|
||||||
$command = new LintCommand();
|
$command = new LintCommand();
|
||||||
$command->setTwigEnvironment($twig);
|
$command->setTwigEnvironment($twig);
|
||||||
|
|
|
@ -16,6 +16,8 @@ use Symfony\Bridge\Twig\Extension\DumpExtension;
|
||||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||||
use Symfony\Component\VarDumper\VarDumper;
|
use Symfony\Component\VarDumper\VarDumper;
|
||||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class DumpExtensionTest extends TestCase
|
class DumpExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -25,7 +27,7 @@ class DumpExtensionTest extends TestCase
|
||||||
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
|
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
|
||||||
{
|
{
|
||||||
$extension = new DumpExtension(new VarCloner());
|
$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,
|
'debug' => $debug,
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
'optimizations' => 0,
|
'optimizations' => 0,
|
||||||
|
@ -65,7 +67,7 @@ class DumpExtensionTest extends TestCase
|
||||||
public function testDump($context, $args, $expectedOutput, $debug = true)
|
public function testDump($context, $args, $expectedOutput, $debug = true)
|
||||||
{
|
{
|
||||||
$extension = new DumpExtension(new VarCloner());
|
$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,
|
'debug' => $debug,
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
'optimizations' => 0,
|
'optimizations' => 0,
|
||||||
|
@ -121,7 +123,7 @@ class DumpExtensionTest extends TestCase
|
||||||
'</pre><script>Sfdump("%s")</script>'
|
'</pre><script>Sfdump("%s")</script>'
|
||||||
);
|
);
|
||||||
$extension = new DumpExtension(new VarCloner(), $dumper);
|
$extension = new DumpExtension(new VarCloner(), $dumper);
|
||||||
$twig = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array(
|
$twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array(
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
'optimizations' => 0,
|
'optimizations' => 0,
|
||||||
|
|
|
@ -13,13 +13,15 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Extension\ExpressionExtension;
|
use Symfony\Bridge\Twig\Extension\ExpressionExtension;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class ExpressionExtensionTest extends TestCase
|
class ExpressionExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testExpressionCreation()
|
public function testExpressionCreation()
|
||||||
{
|
{
|
||||||
$template = "{{ expression('1 == 1') }}";
|
$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());
|
$twig->addExtension(new ExpressionExtension());
|
||||||
|
|
||||||
$output = $twig->render('template');
|
$output = $twig->render('template');
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
|
|
||||||
namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
|
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)
|
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\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\Form\Tests\AbstractBootstrap3HorizontalLayoutTest;
|
use Symfony\Component\Form\Tests\AbstractBootstrap3HorizontalLayoutTest;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest
|
class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest
|
||||||
{
|
{
|
||||||
|
@ -39,7 +40,7 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori
|
||||||
__DIR__.'/Fixtures/templates/form',
|
__DIR__.'/Fixtures/templates/form',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
$environment = new Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
$environment->addExtension(new FormExtension());
|
$environment->addExtension(new FormExtension());
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest;
|
use Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
|
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
|
||||||
{
|
{
|
||||||
|
@ -35,7 +36,7 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
|
||||||
__DIR__.'/Fixtures/templates/form',
|
__DIR__.'/Fixtures/templates/form',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
$environment = new Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
$environment->addExtension(new FormExtension());
|
$environment->addExtension(new FormExtension());
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
|
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||||
{
|
{
|
||||||
|
@ -36,7 +37,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||||
__DIR__.'/Fixtures/templates/form',
|
__DIR__.'/Fixtures/templates/form',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
$environment = new Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
$environment->addGlobal('global', '');
|
$environment->addGlobal('global', '');
|
||||||
// the value can be any template that exists
|
// 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\Component\Form\Tests\AbstractTableLayoutTest;
|
||||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
||||||
{
|
{
|
||||||
|
@ -35,7 +36,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
||||||
__DIR__.'/Fixtures/templates/form',
|
__DIR__.'/Fixtures/templates/form',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
$environment = new Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
$environment->addGlobal('global', '');
|
$environment->addGlobal('global', '');
|
||||||
$environment->addExtension(new FormExtension());
|
$environment->addExtension(new FormExtension());
|
||||||
|
|
|
@ -17,11 +17,13 @@ use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class HttpKernelExtensionTest extends TestCase
|
class HttpKernelExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error_Runtime
|
* @expectedException \Twig\Error\RuntimeError
|
||||||
*/
|
*/
|
||||||
public function testFragmentWithError()
|
public function testFragmentWithError()
|
||||||
{
|
{
|
||||||
|
@ -75,11 +77,11 @@ class HttpKernelExtensionTest extends TestCase
|
||||||
|
|
||||||
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
|
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
|
||||||
{
|
{
|
||||||
$loader = new \Twig_Loader_Array(array('index' => $template));
|
$loader = new ArrayLoader(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 HttpKernelExtension());
|
$twig->addExtension(new HttpKernelExtension());
|
||||||
|
|
||||||
$loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock();
|
||||||
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
|
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
|
||||||
array('Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)),
|
array('Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)),
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -13,6 +13,9 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Node\Expression\FilterExpression;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
class RoutingExtensionTest extends TestCase
|
class RoutingExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -21,12 +24,12 @@ class RoutingExtensionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testEscaping($template, $mustBeEscaped)
|
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()));
|
$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()
|
public function getEscapingTemplates()
|
||||||
|
|
|
@ -12,12 +12,13 @@
|
||||||
namespace Symfony\Bridge\Twig\Tests\Extension;
|
namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
trait RuntimeLoaderProvider
|
trait RuntimeLoaderProvider
|
||||||
{
|
{
|
||||||
protected function registerTwigRuntimeLoader(\Twig_Environment $environment, TwigRenderer $renderer)
|
protected function registerTwigRuntimeLoader(Environment $environment, TwigRenderer $renderer)
|
||||||
{
|
{
|
||||||
$loader = $this->getMockBuilder('Twig_RuntimeLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock();
|
||||||
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
|
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
|
||||||
array('Symfony\Bridge\Twig\Form\TwigRenderer', $renderer),
|
array('Symfony\Bridge\Twig\Form\TwigRenderer', $renderer),
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -13,11 +13,14 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
|
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\RuntimeError;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class StopwatchExtensionTest extends TestCase
|
class StopwatchExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error_Syntax
|
* @expectedException \Twig\Error\SyntaxError
|
||||||
*/
|
*/
|
||||||
public function testFailIfStoppingWrongEvent()
|
public function testFailIfStoppingWrongEvent()
|
||||||
{
|
{
|
||||||
|
@ -29,12 +32,12 @@ class StopwatchExtensionTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testTiming($template, $events)
|
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)));
|
$twig->addExtension(new StopwatchExtension($this->getStopwatch($events)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$nodes = $twig->render('template');
|
$nodes = $twig->render('template');
|
||||||
} catch (\Twig_Error_Runtime $e) {
|
} catch (RuntimeError $e) {
|
||||||
throw $e->getPrevious();
|
throw $e->getPrevious();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
use Symfony\Component\Translation\MessageSelector;
|
use Symfony\Component\Translation\MessageSelector;
|
||||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader as TwigArrayLoader;
|
||||||
|
|
||||||
class TranslationExtensionTest extends TestCase
|
class TranslationExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -33,8 +35,8 @@ class TranslationExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
if ($expected != $this->getTemplate($template)->render($variables)) {
|
if ($expected != $this->getTemplate($template)->render($variables)) {
|
||||||
echo $template."\n";
|
echo $template."\n";
|
||||||
$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(new Translator('en', new MessageSelector())));
|
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
|
||||||
|
|
||||||
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n";
|
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.
|
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
|
||||||
*/
|
*/
|
||||||
public function testTransUnknownKeyword()
|
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.
|
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
|
||||||
*/
|
*/
|
||||||
public function testTransComplexBody()
|
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.
|
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
|
||||||
*/
|
*/
|
||||||
public function testTransChoiceComplexBody()
|
public function testTransChoiceComplexBody()
|
||||||
|
@ -189,11 +191,11 @@ class TranslationExtensionTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($template)) {
|
if (is_array($template)) {
|
||||||
$loader = new \Twig_Loader_Array($template);
|
$loader = new TwigArrayLoader($template);
|
||||||
} else {
|
} 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));
|
$twig->addExtension(new TranslationExtension($translator));
|
||||||
|
|
||||||
return $twig->loadTemplate('index');
|
return $twig->loadTemplate('index');
|
||||||
|
|
|
@ -13,6 +13,10 @@ namespace Symfony\Bridge\Twig\Tests\Node;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Node\DumpNode;
|
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
|
class DumpNodeTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -20,14 +24,14 @@ class DumpNodeTest extends TestCase
|
||||||
{
|
{
|
||||||
$node = new DumpNode('bar', null, 7);
|
$node = new DumpNode('bar', null, 7);
|
||||||
|
|
||||||
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
$env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
|
||||||
$compiler = new \Twig_Compiler($env);
|
$compiler = new Compiler($env);
|
||||||
|
|
||||||
$expected = <<<'EOTXT'
|
$expected = <<<'EOTXT'
|
||||||
if ($this->env->isDebug()) {
|
if ($this->env->isDebug()) {
|
||||||
$barvars = array();
|
$barvars = array();
|
||||||
foreach ($context as $barkey => $barval) {
|
foreach ($context as $barkey => $barval) {
|
||||||
if (!$barval instanceof \Twig_Template) {
|
if (!$barval instanceof \Twig\Template) {
|
||||||
$barvars[$barkey] = $barval;
|
$barvars[$barkey] = $barval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,14 +48,14 @@ EOTXT;
|
||||||
{
|
{
|
||||||
$node = new DumpNode('bar', null, 7);
|
$node = new DumpNode('bar', null, 7);
|
||||||
|
|
||||||
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
$env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
|
||||||
$compiler = new \Twig_Compiler($env);
|
$compiler = new Compiler($env);
|
||||||
|
|
||||||
$expected = <<<'EOTXT'
|
$expected = <<<'EOTXT'
|
||||||
if ($this->env->isDebug()) {
|
if ($this->env->isDebug()) {
|
||||||
$barvars = array();
|
$barvars = array();
|
||||||
foreach ($context as $barkey => $barval) {
|
foreach ($context as $barkey => $barval) {
|
||||||
if (!$barval instanceof \Twig_Template) {
|
if (!$barval instanceof \Twig\Template) {
|
||||||
$barvars[$barkey] = $barval;
|
$barvars[$barkey] = $barval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,13 +70,13 @@ EOTXT;
|
||||||
|
|
||||||
public function testOneVar()
|
public function testOneVar()
|
||||||
{
|
{
|
||||||
$vars = new \Twig_Node(array(
|
$vars = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('foo', 7),
|
new NameExpression('foo', 7),
|
||||||
));
|
));
|
||||||
$node = new DumpNode('bar', $vars, 7);
|
$node = new DumpNode('bar', $vars, 7);
|
||||||
|
|
||||||
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
$env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
|
||||||
$compiler = new \Twig_Compiler($env);
|
$compiler = new Compiler($env);
|
||||||
|
|
||||||
$expected = <<<'EOTXT'
|
$expected = <<<'EOTXT'
|
||||||
if ($this->env->isDebug()) {
|
if ($this->env->isDebug()) {
|
||||||
|
@ -93,14 +97,14 @@ EOTXT;
|
||||||
|
|
||||||
public function testMultiVars()
|
public function testMultiVars()
|
||||||
{
|
{
|
||||||
$vars = new \Twig_Node(array(
|
$vars = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('foo', 7),
|
new NameExpression('foo', 7),
|
||||||
new \Twig_Node_Expression_Name('bar', 7),
|
new NameExpression('bar', 7),
|
||||||
));
|
));
|
||||||
$node = new DumpNode('bar', $vars, 7);
|
$node = new DumpNode('bar', $vars, 7);
|
||||||
|
|
||||||
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
|
$env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
|
||||||
$compiler = new \Twig_Compiler($env);
|
$compiler = new Compiler($env);
|
||||||
|
|
||||||
$expected = <<<'EOTXT'
|
$expected = <<<'EOTXT'
|
||||||
if ($this->env->isDebug()) {
|
if ($this->env->isDebug()) {
|
||||||
|
|
|
@ -13,15 +13,21 @@ namespace Symfony\Bridge\Twig\Tests\Node;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Node\FormThemeNode;
|
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
|
class FormThemeTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
$form = new \Twig_Node_Expression_Name('form', 0);
|
$form = new NameExpression('form', 0);
|
||||||
$resources = new \Twig_Node(array(
|
$resources = new Node(array(
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 0),
|
new ConstantExpression('tpl1', 0),
|
||||||
new \Twig_Node_Expression_Constant('tpl2', 0),
|
new ConstantExpression('tpl2', 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new FormThemeNode($form, $resources, 0);
|
$node = new FormThemeNode($form, $resources, 0);
|
||||||
|
@ -32,17 +38,17 @@ class FormThemeTest extends TestCase
|
||||||
|
|
||||||
public function testCompile()
|
public function testCompile()
|
||||||
{
|
{
|
||||||
$form = new \Twig_Node_Expression_Name('form', 0);
|
$form = new NameExpression('form', 0);
|
||||||
$resources = new \Twig_Node_Expression_Array(array(
|
$resources = new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant(0, 0),
|
new ConstantExpression(0, 0),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 0),
|
new ConstantExpression('tpl1', 0),
|
||||||
new \Twig_Node_Expression_Constant(1, 0),
|
new ConstantExpression(1, 0),
|
||||||
new \Twig_Node_Expression_Constant('tpl2', 0),
|
new ConstantExpression('tpl2', 0),
|
||||||
), 0);
|
), 0);
|
||||||
|
|
||||||
$node = new FormThemeNode($form, $resources, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -52,7 +58,7 @@ class FormThemeTest extends TestCase
|
||||||
trim($compiler->compile($node)->getSource())
|
trim($compiler->compile($node)->getSource())
|
||||||
);
|
);
|
||||||
|
|
||||||
$resources = new \Twig_Node_Expression_Constant('tpl1', 0);
|
$resources = new ConstantExpression('tpl1', 0);
|
||||||
|
|
||||||
$node = new FormThemeNode($form, $resources, 0);
|
$node = new FormThemeNode($form, $resources, 0);
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,25 @@ namespace Symfony\Bridge\Twig\Tests\Node;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
|
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
|
class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCompileWidget()
|
public function testCompileWidget()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -37,17 +44,17 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileWidgetWithVariables()
|
public function testCompileWidgetWithVariables()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant('foo', 0),
|
new ConstantExpression('foo', 0),
|
||||||
new \Twig_Node_Expression_Constant('bar', 0),
|
new ConstantExpression('bar', 0),
|
||||||
), 0),
|
), 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -60,14 +67,14 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithLabel()
|
public function testCompileLabelWithLabel()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Constant('my label', 0),
|
new ConstantExpression('my label', 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -80,14 +87,14 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithNullLabel()
|
public function testCompileLabelWithNullLabel()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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!
|
// "label" => null must not be included in the output!
|
||||||
// Otherwise the default label is overwritten with null.
|
// Otherwise the default label is overwritten with null.
|
||||||
|
@ -102,14 +109,14 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithEmptyStringLabel()
|
public function testCompileLabelWithEmptyStringLabel()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Constant('', 0),
|
new ConstantExpression('', 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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!
|
// "label" => null must not be included in the output!
|
||||||
// Otherwise the default label is overwritten with null.
|
// Otherwise the default label is overwritten with null.
|
||||||
|
@ -124,13 +131,13 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithDefaultLabel()
|
public function testCompileLabelWithDefaultLabel()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -143,18 +150,18 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithAttributes()
|
public function testCompileLabelWithAttributes()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant('foo', 0),
|
new ConstantExpression('foo', 0),
|
||||||
new \Twig_Node_Expression_Constant('bar', 0),
|
new ConstantExpression('bar', 0),
|
||||||
), 0),
|
), 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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!
|
// "label" => null must not be included in the output!
|
||||||
// Otherwise the default label is overwritten with null.
|
// Otherwise the default label is overwritten with null.
|
||||||
|
@ -170,20 +177,20 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithLabelAndAttributes()
|
public function testCompileLabelWithLabelAndAttributes()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Constant('value in argument', 0),
|
new ConstantExpression('value in argument', 0),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant('foo', 0),
|
new ConstantExpression('foo', 0),
|
||||||
new \Twig_Node_Expression_Constant('bar', 0),
|
new ConstantExpression('bar', 0),
|
||||||
new \Twig_Node_Expression_Constant('label', 0),
|
new ConstantExpression('label', 0),
|
||||||
new \Twig_Node_Expression_Constant('value in attributes', 0),
|
new ConstantExpression('value in attributes', 0),
|
||||||
), 0),
|
), 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -196,22 +203,22 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithLabelThatEvaluatesToNull()
|
public function testCompileLabelWithLabelThatEvaluatesToNull()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Conditional(
|
new ConditionalExpression(
|
||||||
// if
|
// if
|
||||||
new \Twig_Node_Expression_Constant(true, 0),
|
new ConstantExpression(true, 0),
|
||||||
// then
|
// then
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
// else
|
// else
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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!
|
// "label" => null must not be included in the output!
|
||||||
// Otherwise the default label is overwritten with null.
|
// Otherwise the default label is overwritten with null.
|
||||||
|
@ -227,28 +234,28 @@ class SearchAndRenderBlockNodeTest extends TestCase
|
||||||
|
|
||||||
public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
|
public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
|
||||||
{
|
{
|
||||||
$arguments = new \Twig_Node(array(
|
$arguments = new Node(array(
|
||||||
new \Twig_Node_Expression_Name('form', 0),
|
new NameExpression('form', 0),
|
||||||
new \Twig_Node_Expression_Conditional(
|
new ConditionalExpression(
|
||||||
// if
|
// if
|
||||||
new \Twig_Node_Expression_Constant(true, 0),
|
new ConstantExpression(true, 0),
|
||||||
// then
|
// then
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
// else
|
// else
|
||||||
new \Twig_Node_Expression_Constant(null, 0),
|
new ConstantExpression(null, 0),
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant('foo', 0),
|
new ConstantExpression('foo', 0),
|
||||||
new \Twig_Node_Expression_Constant('bar', 0),
|
new ConstantExpression('bar', 0),
|
||||||
new \Twig_Node_Expression_Constant('label', 0),
|
new ConstantExpression('label', 0),
|
||||||
new \Twig_Node_Expression_Constant('value in attributes', 0),
|
new ConstantExpression('value in attributes', 0),
|
||||||
), 0),
|
), 0),
|
||||||
));
|
));
|
||||||
|
|
||||||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 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!
|
// "label" => null must not be included in the output!
|
||||||
// Otherwise the default label is overwritten with null.
|
// Otherwise the default label is overwritten with null.
|
||||||
|
|
|
@ -13,6 +13,10 @@ namespace Symfony\Bridge\Twig\Tests\Node;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Node\TransNode;
|
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>
|
* @author Asmir Mustafic <goetas@gmail.com>
|
||||||
|
@ -21,12 +25,12 @@ class TransNodeTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCompileStrict()
|
public function testCompileStrict()
|
||||||
{
|
{
|
||||||
$body = new \Twig_Node_Text('trans %var%', 0);
|
$body = new TextNode('trans %var%', 0);
|
||||||
$vars = new \Twig_Node_Expression_Name('foo', 0);
|
$vars = new NameExpression('foo', 0);
|
||||||
$node = new TransNode($body, null, null, $vars);
|
$node = new TransNode($body, null, null, $vars);
|
||||||
|
|
||||||
$env = new \Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true));
|
$env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('strict_variables' => true));
|
||||||
$compiler = new \Twig_Compiler($env);
|
$compiler = new Compiler($env);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -49,7 +53,7 @@ class TransNodeTest extends TestCase
|
||||||
|
|
||||||
protected function getVariableGetterWithStrictCheck($name)
|
protected function getVariableGetterWithStrictCheck($name)
|
||||||
{
|
{
|
||||||
if (\Twig_Environment::MAJOR_VERSION >= 2) {
|
if (Environment::MAJOR_VERSION >= 2) {
|
||||||
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
|
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 PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
|
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
|
||||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Node\Expression\ArrayExpression;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
class TranslationDefaultDomainNodeVisitorTest extends TestCase
|
class TranslationDefaultDomainNodeVisitorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -21,9 +24,9 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
|
||||||
private static $domain = 'domain';
|
private static $domain = 'domain';
|
||||||
|
|
||||||
/** @dataProvider getDefaultDomainAssignmentTestData */
|
/** @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();
|
$visitor = new TranslationDefaultDomainNodeVisitor();
|
||||||
|
|
||||||
// visit trans_default_domain tag
|
// visit trans_default_domain tag
|
||||||
|
@ -47,9 +50,9 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @dataProvider getDefaultDomainAssignmentTestData */
|
/** @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();
|
$visitor = new TranslationDefaultDomainNodeVisitor();
|
||||||
|
|
||||||
// visit trans_default_domain tag
|
// visit trans_default_domain tag
|
||||||
|
@ -80,10 +83,10 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
|
||||||
array(TwigNodeProvider::getTransTag(self::$message)),
|
array(TwigNodeProvider::getTransTag(self::$message)),
|
||||||
// with named arguments
|
// with named arguments
|
||||||
array(TwigNodeProvider::getTransFilter(self::$message, null, array(
|
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(
|
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 PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
|
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
|
class TranslationNodeVisitorTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @dataProvider getMessagesExtractionTestData */
|
/** @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 = new TranslationNodeVisitor();
|
||||||
$visitor->enable();
|
$visitor->enable();
|
||||||
$visitor->enterNode($node, $env);
|
$visitor->enterNode($node, $env);
|
||||||
|
@ -31,12 +37,12 @@ class TranslationNodeVisitorTest extends TestCase
|
||||||
{
|
{
|
||||||
$message = 'new key';
|
$message = 'new key';
|
||||||
|
|
||||||
$node = new \Twig_Node_Expression_Filter(
|
$node = new FilterExpression(
|
||||||
new \Twig_Node_Expression_Constant($message, 0),
|
new ConstantExpression($message, 0),
|
||||||
new \Twig_Node_Expression_Constant('trans', 0),
|
new ConstantExpression('trans', 0),
|
||||||
new \Twig_Node(array(
|
new Node(array(
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
new \Twig_Node_Expression_Name('variable', 0),
|
new NameExpression('variable', 0),
|
||||||
)),
|
)),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,19 +13,26 @@ namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
|
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
|
||||||
use Symfony\Bridge\Twig\Node\TransNode;
|
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
|
class TwigNodeProvider
|
||||||
{
|
{
|
||||||
public static function getModule($content)
|
public static function getModule($content)
|
||||||
{
|
{
|
||||||
return new \Twig_Node_Module(
|
return new ModuleNode(
|
||||||
new \Twig_Node_Expression_Constant($content, 0),
|
new ConstantExpression($content, 0),
|
||||||
null,
|
null,
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
null,
|
null,
|
||||||
new \Twig_Source('', '')
|
new Source('', '')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,15 +40,15 @@ class TwigNodeProvider
|
||||||
{
|
{
|
||||||
if (!$arguments) {
|
if (!$arguments) {
|
||||||
$arguments = $domain ? array(
|
$arguments = $domain ? array(
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
new \Twig_Node_Expression_Constant($domain, 0),
|
new ConstantExpression($domain, 0),
|
||||||
) : array();
|
) : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \Twig_Node_Expression_Filter(
|
return new FilterExpression(
|
||||||
new \Twig_Node_Expression_Constant($message, 0),
|
new ConstantExpression($message, 0),
|
||||||
new \Twig_Node_Expression_Constant('trans', 0),
|
new ConstantExpression('trans', 0),
|
||||||
new \Twig_Node($arguments),
|
new Node($arguments),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -50,16 +57,16 @@ class TwigNodeProvider
|
||||||
{
|
{
|
||||||
if (!$arguments) {
|
if (!$arguments) {
|
||||||
$arguments = $domain ? array(
|
$arguments = $domain ? array(
|
||||||
new \Twig_Node_Expression_Constant(0, 0),
|
new ConstantExpression(0, 0),
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new ArrayExpression(array(), 0),
|
||||||
new \Twig_Node_Expression_Constant($domain, 0),
|
new ConstantExpression($domain, 0),
|
||||||
) : array();
|
) : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \Twig_Node_Expression_Filter(
|
return new FilterExpression(
|
||||||
new \Twig_Node_Expression_Constant($message, 0),
|
new ConstantExpression($message, 0),
|
||||||
new \Twig_Node_Expression_Constant('transchoice', 0),
|
new ConstantExpression('transchoice', 0),
|
||||||
new \Twig_Node($arguments),
|
new Node($arguments),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -67,15 +74,15 @@ class TwigNodeProvider
|
||||||
public static function getTransTag($message, $domain = null)
|
public static function getTransTag($message, $domain = null)
|
||||||
{
|
{
|
||||||
return new TransNode(
|
return new TransNode(
|
||||||
new \Twig_Node_Body(array(), array('data' => $message)),
|
new BodyNode(array(), array('data' => $message)),
|
||||||
$domain ? new \Twig_Node_Expression_Constant($domain, 0) : null
|
$domain ? new ConstantExpression($domain, 0) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTransDefaultDomainTag($domain)
|
public static function getTransDefaultDomainTag($domain)
|
||||||
{
|
{
|
||||||
return new TransDefaultDomainNode(
|
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 PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
||||||
use Symfony\Bridge\Twig\Node\FormThemeNode;
|
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
|
class FormThemeTokenParserTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -22,10 +28,10 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testCompile($source, $expected)
|
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());
|
$env->addTokenParser(new FormThemeTokenParser());
|
||||||
$stream = $env->tokenize(new \Twig_Source($source, ''));
|
$stream = $env->tokenize(new Source($source, ''));
|
||||||
$parser = new \Twig_Parser($env);
|
$parser = new Parser($env);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
||||||
}
|
}
|
||||||
|
@ -36,10 +42,10 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
array(
|
array(
|
||||||
'{% form_theme form "tpl1" %}',
|
'{% form_theme form "tpl1" %}',
|
||||||
new FormThemeNode(
|
new FormThemeNode(
|
||||||
new \Twig_Node_Expression_Name('form', 1),
|
new NameExpression('form', 1),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant(0, 1),
|
new ConstantExpression(0, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 1),
|
new ConstantExpression('tpl1', 1),
|
||||||
), 1),
|
), 1),
|
||||||
1,
|
1,
|
||||||
'form_theme'
|
'form_theme'
|
||||||
|
@ -48,12 +54,12 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
array(
|
array(
|
||||||
'{% form_theme form "tpl1" "tpl2" %}',
|
'{% form_theme form "tpl1" "tpl2" %}',
|
||||||
new FormThemeNode(
|
new FormThemeNode(
|
||||||
new \Twig_Node_Expression_Name('form', 1),
|
new NameExpression('form', 1),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant(0, 1),
|
new ConstantExpression(0, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 1),
|
new ConstantExpression('tpl1', 1),
|
||||||
new \Twig_Node_Expression_Constant(1, 1),
|
new ConstantExpression(1, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl2', 1),
|
new ConstantExpression('tpl2', 1),
|
||||||
), 1),
|
), 1),
|
||||||
1,
|
1,
|
||||||
'form_theme'
|
'form_theme'
|
||||||
|
@ -62,8 +68,8 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
array(
|
array(
|
||||||
'{% form_theme form with "tpl1" %}',
|
'{% form_theme form with "tpl1" %}',
|
||||||
new FormThemeNode(
|
new FormThemeNode(
|
||||||
new \Twig_Node_Expression_Name('form', 1),
|
new NameExpression('form', 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 1),
|
new ConstantExpression('tpl1', 1),
|
||||||
1,
|
1,
|
||||||
'form_theme'
|
'form_theme'
|
||||||
),
|
),
|
||||||
|
@ -71,10 +77,10 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
array(
|
array(
|
||||||
'{% form_theme form with ["tpl1"] %}',
|
'{% form_theme form with ["tpl1"] %}',
|
||||||
new FormThemeNode(
|
new FormThemeNode(
|
||||||
new \Twig_Node_Expression_Name('form', 1),
|
new NameExpression('form', 1),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant(0, 1),
|
new ConstantExpression(0, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 1),
|
new ConstantExpression('tpl1', 1),
|
||||||
), 1),
|
), 1),
|
||||||
1,
|
1,
|
||||||
'form_theme'
|
'form_theme'
|
||||||
|
@ -83,12 +89,12 @@ class FormThemeTokenParserTest extends TestCase
|
||||||
array(
|
array(
|
||||||
'{% form_theme form with ["tpl1", "tpl2"] %}',
|
'{% form_theme form with ["tpl1", "tpl2"] %}',
|
||||||
new FormThemeNode(
|
new FormThemeNode(
|
||||||
new \Twig_Node_Expression_Name('form', 1),
|
new NameExpression('form', 1),
|
||||||
new \Twig_Node_Expression_Array(array(
|
new ArrayExpression(array(
|
||||||
new \Twig_Node_Expression_Constant(0, 1),
|
new ConstantExpression(0, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl1', 1),
|
new ConstantExpression('tpl1', 1),
|
||||||
new \Twig_Node_Expression_Constant(1, 1),
|
new ConstantExpression(1, 1),
|
||||||
new \Twig_Node_Expression_Constant('tpl2', 1),
|
new ConstantExpression('tpl2', 1),
|
||||||
), 1),
|
), 1),
|
||||||
1,
|
1,
|
||||||
'form_theme'
|
'form_theme'
|
||||||
|
|
|
@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||||
use Symfony\Bridge\Twig\Translation\TwigExtractor;
|
use Symfony\Bridge\Twig\Translation\TwigExtractor;
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\Error;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class TwigExtractorTest extends TestCase
|
class TwigExtractorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -23,8 +26,8 @@ class TwigExtractorTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testExtract($template, $messages)
|
public function testExtract($template, $messages)
|
||||||
{
|
{
|
||||||
$loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock();
|
||||||
$twig = new \Twig_Environment($loader, array(
|
$twig = new Environment($loader, array(
|
||||||
'strict_variables' => true,
|
'strict_variables' => true,
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
|
@ -73,19 +76,19 @@ class TwigExtractorTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error
|
* @expectedException \Twig\Error\Error
|
||||||
* @dataProvider resourcesWithSyntaxErrorsProvider
|
* @dataProvider resourcesWithSyntaxErrorsProvider
|
||||||
*/
|
*/
|
||||||
public function testExtractSyntaxError($resources)
|
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()));
|
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
|
||||||
|
|
||||||
$extractor = new TwigExtractor($twig);
|
$extractor = new TwigExtractor($twig);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$extractor->extract($resources, new MessageCatalogue('en'));
|
$extractor->extract($resources, new MessageCatalogue('en'));
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
if (method_exists($e, 'getSourceContext')) {
|
if (method_exists($e, 'getSourceContext')) {
|
||||||
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
|
$this->assertSame(dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', DIRECTORY_SEPARATOR), $e->getFile());
|
||||||
$this->assertSame(1, $e->getLine());
|
$this->assertSame(1, $e->getLine());
|
||||||
|
@ -114,8 +117,8 @@ class TwigExtractorTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testExtractWithFiles($resource)
|
public function testExtractWithFiles($resource)
|
||||||
{
|
{
|
||||||
$loader = new \Twig_Loader_Array(array());
|
$loader = new ArrayLoader(array());
|
||||||
$twig = new \Twig_Environment($loader, array(
|
$twig = new Environment($loader, array(
|
||||||
'strict_variables' => true,
|
'strict_variables' => true,
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'cache' => false,
|
'cache' => false,
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace Symfony\Bridge\Twig\Tests;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\Twig\TwigEngine;
|
use Symfony\Bridge\Twig\TwigEngine;
|
||||||
use Symfony\Component\Templating\TemplateReference;
|
use Symfony\Component\Templating\TemplateReference;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class TwigEngineTest extends TestCase
|
class TwigEngineTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -21,7 +23,7 @@ class TwigEngineTest extends TestCase
|
||||||
{
|
{
|
||||||
$engine = $this->getTwig();
|
$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()
|
public function testExistsWithNonExistentTemplates()
|
||||||
|
@ -57,7 +59,7 @@ class TwigEngineTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error_Syntax
|
* @expectedException \Twig\Error\SyntaxError
|
||||||
*/
|
*/
|
||||||
public function testRenderWithError()
|
public function testRenderWithError()
|
||||||
{
|
{
|
||||||
|
@ -68,7 +70,7 @@ class TwigEngineTest extends TestCase
|
||||||
|
|
||||||
protected function getTwig()
|
protected function getTwig()
|
||||||
{
|
{
|
||||||
$twig = new \Twig_Environment(new \Twig_Loader_Array(array(
|
$twig = new Environment(new ArrayLoader(array(
|
||||||
'index' => 'foo',
|
'index' => 'foo',
|
||||||
'error' => '{{ foo }',
|
'error' => '{{ foo }',
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\DumpNode;
|
use Symfony\Bridge\Twig\Node\DumpNode;
|
||||||
|
use Twig\Token;
|
||||||
|
use Twig\TokenParser\AbstractTokenParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token Parser for the 'dump' tag.
|
* Token Parser for the 'dump' tag.
|
||||||
|
@ -25,18 +27,18 @@ use Symfony\Bridge\Twig\Node\DumpNode;
|
||||||
*
|
*
|
||||||
* @author Julien Galenski <julien.galenski@gmail.com>
|
* @author Julien Galenski <julien.galenski@gmail.com>
|
||||||
*/
|
*/
|
||||||
class DumpTokenParser extends \Twig_TokenParser
|
class DumpTokenParser extends AbstractTokenParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function parse(\Twig_Token $token)
|
public function parse(Token $token)
|
||||||
{
|
{
|
||||||
$values = null;
|
$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();
|
$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());
|
return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,39 +12,43 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\FormThemeNode;
|
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.
|
* Token Parser for the 'form_theme' tag.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class FormThemeTokenParser extends \Twig_TokenParser
|
class FormThemeTokenParser extends AbstractTokenParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* 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();
|
$lineno = $token->getLine();
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$form = $this->parser->getExpressionParser()->parseExpression();
|
$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();
|
$this->parser->getStream()->next();
|
||||||
$resources = $this->parser->getExpressionParser()->parseExpression();
|
$resources = $this->parser->getExpressionParser()->parseExpression();
|
||||||
} else {
|
} else {
|
||||||
$resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
|
$resources = new ArrayExpression(array(), $stream->getCurrent()->getLine());
|
||||||
do {
|
do {
|
||||||
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
|
$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());
|
return new FormThemeNode($form, $resources, $lineno, $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,16 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\StopwatchNode;
|
use Symfony\Bridge\Twig\Node\StopwatchNode;
|
||||||
|
use Twig\Node\Expression\AssignNameExpression;
|
||||||
|
use Twig\Token;
|
||||||
|
use Twig\TokenParser\AbstractTokenParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token Parser for the stopwatch tag.
|
* Token Parser for the stopwatch tag.
|
||||||
*
|
*
|
||||||
* @author Wouter J <wouter@wouterj.nl>
|
* @author Wouter J <wouter@wouterj.nl>
|
||||||
*/
|
*/
|
||||||
class StopwatchTokenParser extends \Twig_TokenParser
|
class StopwatchTokenParser extends AbstractTokenParser
|
||||||
{
|
{
|
||||||
protected $stopwatchIsAvailable;
|
protected $stopwatchIsAvailable;
|
||||||
|
|
||||||
|
@ -27,7 +30,7 @@ class StopwatchTokenParser extends \Twig_TokenParser
|
||||||
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
|
$this->stopwatchIsAvailable = $stopwatchIsAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(\Twig_Token $token)
|
public function parse(Token $token)
|
||||||
{
|
{
|
||||||
$lineno = $token->getLine();
|
$lineno = $token->getLine();
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
@ -35,20 +38,20 @@ class StopwatchTokenParser extends \Twig_TokenParser
|
||||||
// {% stopwatch 'bar' %}
|
// {% stopwatch 'bar' %}
|
||||||
$name = $this->parser->getExpressionParser()->parseExpression();
|
$name = $this->parser->getExpressionParser()->parseExpression();
|
||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
// {% endstopwatch %}
|
// {% endstopwatch %}
|
||||||
$body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true);
|
$body = $this->parser->subparse(array($this, 'decideStopwatchEnd'), true);
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
if ($this->stopwatchIsAvailable) {
|
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;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decideStopwatchEnd(\Twig_Token $token)
|
public function decideStopwatchEnd(Token $token)
|
||||||
{
|
{
|
||||||
return $token->test('endstopwatch');
|
return $token->test('endstopwatch');
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\TransNode;
|
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.
|
* Token Parser for the 'transchoice' tag.
|
||||||
|
@ -23,18 +29,18 @@ class TransChoiceTokenParser extends TransTokenParser
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* 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();
|
$lineno = $token->getLine();
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$vars = new \Twig_Node_Expression_Array(array(), $lineno);
|
$vars = new ArrayExpression(array(), $lineno);
|
||||||
|
|
||||||
$count = $this->parser->getExpressionParser()->parseExpression();
|
$count = $this->parser->getExpressionParser()->parseExpression();
|
||||||
|
|
||||||
|
@ -59,15 +65,15 @@ class TransChoiceTokenParser extends TransTokenParser
|
||||||
$locale = $this->parser->getExpressionParser()->parseExpression();
|
$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);
|
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
|
||||||
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
|
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());
|
return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,26 +12,29 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
|
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.
|
* Token Parser for the 'trans_default_domain' tag.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TransDefaultDomainTokenParser extends \Twig_TokenParser
|
class TransDefaultDomainTokenParser extends AbstractTokenParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* 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();
|
$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());
|
return new TransDefaultDomainNode($expr, $token->getLine(), $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,32 +12,39 @@
|
||||||
namespace Symfony\Bridge\Twig\TokenParser;
|
namespace Symfony\Bridge\Twig\TokenParser;
|
||||||
|
|
||||||
use Symfony\Bridge\Twig\Node\TransNode;
|
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.
|
* Token Parser for the 'trans' tag.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class TransTokenParser extends \Twig_TokenParser
|
class TransTokenParser extends AbstractTokenParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses a token and returns a node.
|
* 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();
|
$lineno = $token->getLine();
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$vars = new \Twig_Node_Expression_Array(array(), $lineno);
|
$vars = new ArrayExpression(array(), $lineno);
|
||||||
$domain = null;
|
$domain = null;
|
||||||
$locale = null;
|
$locale = null;
|
||||||
if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
if (!$stream->test(Token::BLOCK_END_TYPE)) {
|
||||||
if ($stream->test('with')) {
|
if ($stream->test('with')) {
|
||||||
// {% trans with vars %}
|
// {% trans with vars %}
|
||||||
$stream->next();
|
$stream->next();
|
||||||
|
@ -54,20 +61,20 @@ class TransTokenParser extends \Twig_TokenParser
|
||||||
// {% trans into "fr" %}
|
// {% trans into "fr" %}
|
||||||
$stream->next();
|
$stream->next();
|
||||||
$locale = $this->parser->getExpressionParser()->parseExpression();
|
$locale = $this->parser->getExpressionParser()->parseExpression();
|
||||||
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
} elseif (!$stream->test(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());
|
throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {% trans %}message{% endtrans %}
|
// {% trans %}message{% endtrans %}
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(Token::BLOCK_END_TYPE);
|
||||||
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
|
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
|
||||||
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()->getName());
|
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());
|
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\AbstractFileExtractor;
|
||||||
use Symfony\Component\Translation\Extractor\ExtractorInterface;
|
use Symfony\Component\Translation\Extractor\ExtractorInterface;
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\Error;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwigExtractor extracts translation messages from a twig template.
|
* TwigExtractor extracts translation messages from a twig template.
|
||||||
|
@ -42,11 +45,11 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||||
/**
|
/**
|
||||||
* The twig environment.
|
* The twig environment.
|
||||||
*
|
*
|
||||||
* @var \Twig_Environment
|
* @var Environment
|
||||||
*/
|
*/
|
||||||
private $twig;
|
private $twig;
|
||||||
|
|
||||||
public function __construct(\Twig_Environment $twig)
|
public function __construct(Environment $twig)
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
}
|
}
|
||||||
|
@ -60,12 +63,12 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
try {
|
try {
|
||||||
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
if ($file instanceof \SplFileInfo) {
|
if ($file instanceof \SplFileInfo) {
|
||||||
$path = $file->getRealPath() ?: $file->getPathname();
|
$path = $file->getRealPath() ?: $file->getPathname();
|
||||||
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
|
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
|
||||||
if (method_exists($e, 'setSourceContext')) {
|
if (method_exists($e, 'setSourceContext')) {
|
||||||
$e->setSourceContext(new \Twig_Source('', $name, $path));
|
$e->setSourceContext(new Source('', $name, $path));
|
||||||
} else {
|
} else {
|
||||||
$e->setTemplateName($name);
|
$e->setTemplateName($name);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +92,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||||
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
||||||
$visitor->enable();
|
$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) {
|
foreach ($visitor->getMessages() as $message) {
|
||||||
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
|
$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\StreamingEngineInterface;
|
||||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||||
use Symfony\Component\Templating\TemplateReferenceInterface;
|
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.
|
* This engine knows how to render Twig templates.
|
||||||
|
@ -26,13 +31,7 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
protected $environment;
|
protected $environment;
|
||||||
protected $parser;
|
protected $parser;
|
||||||
|
|
||||||
/**
|
public function __construct(Environment $environment, TemplateNameParserInterface $parser)
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param \Twig_Environment $environment A \Twig_Environment instance
|
|
||||||
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
|
|
||||||
*/
|
|
||||||
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser)
|
|
||||||
{
|
{
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
@ -41,9 +40,9 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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())
|
public function render($name, array $parameters = array())
|
||||||
{
|
{
|
||||||
|
@ -53,9 +52,9 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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())
|
public function stream($name, array $parameters = array())
|
||||||
{
|
{
|
||||||
|
@ -65,25 +64,25 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* It also supports \Twig_Template as name parameter.
|
* It also supports Template as name parameter.
|
||||||
*/
|
*/
|
||||||
public function exists($name)
|
public function exists($name)
|
||||||
{
|
{
|
||||||
if ($name instanceof \Twig_Template) {
|
if ($name instanceof Template) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loader = $this->environment->getLoader();
|
$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);
|
return $loader->exists((string) $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// cast possible TemplateReferenceInterface to string because the
|
// 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();
|
$loader->getSourceContext((string) $name)->getCode();
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,11 +92,11 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* It also supports \Twig_Template as name parameter.
|
* It also supports Template as name parameter.
|
||||||
*/
|
*/
|
||||||
public function supports($name)
|
public function supports($name)
|
||||||
{
|
{
|
||||||
if ($name instanceof \Twig_Template) {
|
if ($name instanceof Template) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,22 +108,22 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
|
||||||
/**
|
/**
|
||||||
* Loads the given template.
|
* Loads the given template.
|
||||||
*
|
*
|
||||||
* @param string|TemplateReferenceInterface|\Twig_Template $name A template name or an instance of
|
* @param string|TemplateReferenceInterface|Template $name A template name or an instance of
|
||||||
* TemplateReferenceInterface or \Twig_Template
|
* TemplateReferenceInterface or Template
|
||||||
*
|
*
|
||||||
* @return \Twig_Template A \Twig_Template instance
|
* @return Template
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the template does not exist
|
* @throws \InvalidArgumentException if the template does not exist
|
||||||
*/
|
*/
|
||||||
protected function load($name)
|
protected function load($name)
|
||||||
{
|
{
|
||||||
if ($name instanceof \Twig_Template) {
|
if ($name instanceof Template) {
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->environment->loadTemplate((string) $name);
|
return $this->environment->loadTemplate((string) $name);
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
|
throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5.9",
|
"php": ">=5.5.9",
|
||||||
"twig/twig": "~1.28|~2.0"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fig/link-util": "^1.0",
|
"fig/link-util": "^1.0",
|
||||||
|
|
|
@ -25,6 +25,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
use Symfony\Component\Templating\EngineInterface;
|
use Symfony\Component\Templating\EngineInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides common features needed in controllers.
|
* Provides common features needed in controllers.
|
||||||
|
@ -59,7 +60,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
|
||||||
'session' => '?'.SessionInterface::class,
|
'session' => '?'.SessionInterface::class,
|
||||||
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
|
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
|
||||||
'templating' => '?'.EngineInterface::class,
|
'templating' => '?'.EngineInterface::class,
|
||||||
'twig' => '?'.\Twig_Environment::class,
|
'twig' => '?'.Environment::class,
|
||||||
'doctrine' => '?'.ManagerRegistry::class,
|
'doctrine' => '?'.ManagerRegistry::class,
|
||||||
'form.factory' => '?'.FormFactoryInterface::class,
|
'form.factory' => '?'.FormFactoryInterface::class,
|
||||||
'security.token_storage' => '?'.TokenStorageInterface::class,
|
'security.token_storage' => '?'.TokenStorageInterface::class,
|
||||||
|
|
|
@ -317,7 +317,7 @@ abstract class ControllerTraitTest extends TestCase
|
||||||
|
|
||||||
public function testRenderViewTwig()
|
public function testRenderViewTwig()
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$twig->expects($this->once())->method('render')->willReturn('bar');
|
$twig->expects($this->once())->method('render')->willReturn('bar');
|
||||||
|
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
@ -331,7 +331,7 @@ abstract class ControllerTraitTest extends TestCase
|
||||||
|
|
||||||
public function testRenderTwig()
|
public function testRenderTwig()
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$twig->expects($this->once())->method('render')->willReturn('bar');
|
$twig->expects($this->once())->method('render')->willReturn('bar');
|
||||||
|
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
@ -345,7 +345,7 @@ abstract class ControllerTraitTest extends TestCase
|
||||||
|
|
||||||
public function testStreamTwig()
|
public function testStreamTwig()
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
$container->set('twig', $twig);
|
$container->set('twig', $twig);
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TemplateControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testTwig()
|
public function testTwig()
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('\Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$twig->expects($this->once())->method('render')->willReturn('bar');
|
$twig->expects($this->once())->method('render')->willReturn('bar');
|
||||||
|
|
||||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
"symfony/web-link": "~3.3",
|
"symfony/web-link": "~3.3",
|
||||||
"doctrine/annotations": "~1.0",
|
"doctrine/annotations": "~1.0",
|
||||||
"phpdocumentor/reflection-docblock": "^3.0",
|
"phpdocumentor/reflection-docblock": "^3.0",
|
||||||
"twig/twig": "~1.26|~2.0",
|
"twig/twig": "~1.34|~2.4",
|
||||||
"sensio/framework-extra-bundle": "^3.0.2"
|
"sensio/framework-extra-bundle": "^3.0.2"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
"symfony/yaml": "~2.8|~3.0",
|
"symfony/yaml": "~2.8|~3.0",
|
||||||
"symfony/expression-language": "~2.8|~3.0",
|
"symfony/expression-language": "~2.8|~3.0",
|
||||||
"doctrine/doctrine-bundle": "~1.4",
|
"doctrine/doctrine-bundle": "~1.4",
|
||||||
"twig/twig": "~1.28|~2.0"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"symfony/var-dumper": "<3.3"
|
"symfony/var-dumper": "<3.3"
|
||||||
|
|
|
@ -17,6 +17,8 @@ use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
|
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface;
|
||||||
use Symfony\Component\Templating\TemplateReference;
|
use Symfony\Component\Templating\TemplateReference;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the Twig cache for all templates.
|
* Generates the Twig cache for all templates.
|
||||||
|
@ -77,7 +79,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$twig->loadTemplate($template);
|
$twig->loadTemplate($template);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
// problem during compilation, give up
|
// problem during compilation, give up
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +101,7 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface, ServiceSubscribe
|
||||||
public static function getSubscribedServices()
|
public static function getSubscribedServices()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'twig' => \Twig_Environment::class,
|
'twig' => Environment::class,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
|
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the Twig cache for all templates.
|
* Generates the Twig cache for all templates.
|
||||||
|
@ -23,7 +25,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface
|
||||||
private $twig;
|
private $twig;
|
||||||
private $iterator;
|
private $iterator;
|
||||||
|
|
||||||
public function __construct(\Twig_Environment $twig, \Traversable $iterator)
|
public function __construct(Environment $twig, \Traversable $iterator)
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
$this->iterator = $iterator;
|
$this->iterator = $iterator;
|
||||||
|
@ -37,7 +39,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface
|
||||||
foreach ($this->iterator as $template) {
|
foreach ($this->iterator as $template) {
|
||||||
try {
|
try {
|
||||||
$this->twig->loadTemplate($template);
|
$this->twig->loadTemplate($template);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
// problem during compilation, give up
|
// problem during compilation, give up
|
||||||
// might be a syntax error or a non-Twig template
|
// might be a syntax error or a non-Twig template
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,20 @@
|
||||||
|
|
||||||
namespace Symfony\Bundle\TwigBundle;
|
namespace Symfony\Bundle\TwigBundle;
|
||||||
|
|
||||||
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig_ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED);
|
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use the Twig\RuntimeLoader\ContainerRuntimeLoader class instead.', ContainerAwareRuntimeLoader::class), E_USER_DEPRECATED);
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Twig\RuntimeLoader\RuntimeLoaderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads Twig extension runtimes via the service container.
|
* Loads Twig extension runtimes via the service container.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*
|
*
|
||||||
* @deprecated since version 3.3, will be removed in 4.0. Use \Twig_ContainerRuntimeLoader instead.
|
* @deprecated since version 3.3, will be removed in 4.0. Use \Twig\Loader\ContainerRuntimeLoader instead.
|
||||||
*/
|
*/
|
||||||
class ContainerAwareRuntimeLoader implements \Twig_RuntimeLoaderInterface
|
class ContainerAwareRuntimeLoader implements RuntimeLoaderInterface
|
||||||
{
|
{
|
||||||
private $container;
|
private $container;
|
||||||
private $mapping;
|
private $mapping;
|
||||||
|
|
|
@ -15,6 +15,9 @@ use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Loader\ExistsLoaderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExceptionController renders error or exception pages for a given
|
* ExceptionController renders error or exception pages for a given
|
||||||
|
@ -32,7 +35,7 @@ class ExceptionController
|
||||||
*/
|
*/
|
||||||
protected $debug;
|
protected $debug;
|
||||||
|
|
||||||
public function __construct(\Twig_Environment $twig, $debug)
|
public function __construct(Environment $twig, $debug)
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
|
@ -129,7 +132,7 @@ class ExceptionController
|
||||||
$template = (string) $template;
|
$template = (string) $template;
|
||||||
|
|
||||||
$loader = $this->twig->getLoader();
|
$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);
|
return $loader->exists($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +140,7 @@ class ExceptionController
|
||||||
$loader->getSourceContext($template)->getCode();
|
$loader->getSourceContext($template)->getCode();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -123,7 +123,7 @@ class Configuration implements ConfigurationInterface
|
||||||
->variableNode('autoescape')->defaultValue('name')->end()
|
->variableNode('autoescape')->defaultValue('name')->end()
|
||||||
->scalarNode('autoescape_service')->defaultNull()->end()
|
->scalarNode('autoescape_service')->defaultNull()->end()
|
||||||
->scalarNode('autoescape_service_method')->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('cache')->defaultValue('%kernel.cache_dir%/twig')->end()
|
||||||
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
|
->scalarNode('charset')->defaultValue('%kernel.charset%')->end()
|
||||||
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
|
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
|
|
||||||
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Configurator;
|
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Configurator;
|
||||||
|
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
// BC/FC with namespaced Twig
|
||||||
|
class_exists('Twig\Environment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig environment configurator.
|
* Twig environment configurator.
|
||||||
*
|
*
|
||||||
|
@ -35,14 +40,14 @@ class EnvironmentConfigurator
|
||||||
$this->thousandsSeparator = $thousandsSeparator;
|
$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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
use Symfony\Component\WebLink\HttpHeaderSerializer;
|
use Symfony\Component\WebLink\HttpHeaderSerializer;
|
||||||
|
use Twig\Extension\ExtensionInterface;
|
||||||
|
use Twig\Loader\LoaderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwigExtension.
|
* TwigExtension.
|
||||||
|
@ -144,10 +146,10 @@ class TwigExtension extends Extension
|
||||||
|
|
||||||
$container->getDefinition('twig')->replaceArgument(1, $config);
|
$container->getDefinition('twig')->replaceArgument(1, $config);
|
||||||
|
|
||||||
$container->registerForAutoconfiguration(\Twig_ExtensionInterface::class)
|
$container->registerForAutoconfiguration(\Twig_ExtensionInterface::class)->addTag('twig.extension');
|
||||||
->addTag('twig.extension');
|
$container->registerForAutoconfiguration(\Twig_LoaderInterface::class)->addTag('twig.loader');
|
||||||
$container->registerForAutoconfiguration(\Twig_LoaderInterface::class)
|
$container->registerForAutoconfiguration(ExtensionInterface::class)->addTag('twig.extension');
|
||||||
->addTag('twig.loader');
|
$container->registerForAutoconfiguration(LoaderInterface::class)->addTag('twig.loader');
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 70000) {
|
if (PHP_VERSION_ID < 70000) {
|
||||||
$this->addClassesToCompile(array(
|
$this->addClassesToCompile(array(
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace Symfony\Bundle\TwigBundle\Loader;
|
||||||
use Symfony\Component\Config\FileLocatorInterface;
|
use Symfony\Component\Config\FileLocatorInterface;
|
||||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||||
use Symfony\Component\Templating\TemplateReferenceInterface;
|
use Symfony\Component\Templating\TemplateReferenceInterface;
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Loader\FilesystemLoader as BaseFilesystemLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FilesystemLoader extends the default Twig filesystem loader
|
* FilesystemLoader extends the default Twig filesystem loader
|
||||||
|
@ -21,7 +23,7 @@ use Symfony\Component\Templating\TemplateReferenceInterface;
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class FilesystemLoader extends \Twig_Loader_Filesystem
|
class FilesystemLoader extends BaseFilesystemLoader
|
||||||
{
|
{
|
||||||
protected $locator;
|
protected $locator;
|
||||||
protected $parser;
|
protected $parser;
|
||||||
|
@ -59,11 +61,11 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
|
||||||
* Otherwise the template is located using the locator from the twig library.
|
* Otherwise the template is located using the locator from the twig library.
|
||||||
*
|
*
|
||||||
* @param string|TemplateReferenceInterface $template The template
|
* @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
|
* @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)
|
protected function findTemplate($template, $throw = true)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +79,7 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
|
||||||
$previous = null;
|
$previous = null;
|
||||||
try {
|
try {
|
||||||
$file = parent::findTemplate($logicalName);
|
$file = parent::findTemplate($logicalName);
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
$twigLoaderException = $e;
|
$twigLoaderException = $e;
|
||||||
|
|
||||||
// for BC
|
// for BC
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<services>
|
<services>
|
||||||
<defaults public="false" />
|
<defaults public="false" />
|
||||||
|
|
||||||
<service id="twig" class="Twig_Environment" public="true">
|
<service id="twig" class="Twig\Environment" public="true">
|
||||||
<argument type="service" id="twig.loader" />
|
<argument type="service" id="twig.loader" />
|
||||||
<argument /> <!-- Twig options -->
|
<argument /> <!-- Twig options -->
|
||||||
<call method="addGlobal">
|
<call method="addGlobal">
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
<configurator service="twig.configurator.environment" method="configure" />
|
<configurator service="twig.configurator.environment" method="configure" />
|
||||||
</service>
|
</service>
|
||||||
<service id="Twig_Environment" alias="twig" />
|
<service id="Twig_Environment" alias="twig" />
|
||||||
|
<service id="Twig\Environment" alias="twig" />
|
||||||
|
|
||||||
<service id="twig.app_variable" class="Symfony\Bridge\Twig\AppVariable">
|
<service id="twig.app_variable" class="Symfony\Bridge\Twig\AppVariable">
|
||||||
<call method="setEnvironment"><argument>%kernel.environment%</argument></call>
|
<call method="setEnvironment"><argument>%kernel.environment%</argument></call>
|
||||||
|
@ -48,20 +49,20 @@
|
||||||
<argument type="service" id="twig.template_iterator" />
|
<argument type="service" id="twig.template_iterator" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem">
|
<service id="twig.loader.native_filesystem" class="Twig\Loader\FilesystemLoader">
|
||||||
<argument type="collection" /> <!-- paths -->
|
<argument type="collection" /> <!-- paths -->
|
||||||
<argument>%kernel.project_dir%</argument>
|
<argument>%kernel.project_dir%</argument>
|
||||||
<tag name="twig.loader"/>
|
<tag name="twig.loader"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.loader.chain" class="Twig_Loader_Chain" />
|
<service id="twig.loader.chain" class="Twig\Loader\ChainLoader" />
|
||||||
|
|
||||||
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension">
|
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension">
|
||||||
<argument type="service" id="twig.profile" />
|
<argument type="service" id="twig.profile" />
|
||||||
<argument type="service" id="debug.stopwatch" on-invalid="null" />
|
<argument type="service" id="debug.stopwatch" on-invalid="null" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.profile" class="Twig_Profiler_Profile" public="true" />
|
<service id="twig.profile" class="Twig\Profiler\Profile" public="true" />
|
||||||
|
|
||||||
<service id="data_collector.twig" class="Symfony\Bridge\Twig\DataCollector\TwigDataCollector">
|
<service id="data_collector.twig" class="Symfony\Bridge\Twig\DataCollector\TwigDataCollector">
|
||||||
<tag name="data_collector" template="@WebProfiler/Collector/twig.html.twig" id="twig" priority="257" />
|
<tag name="data_collector" template="@WebProfiler/Collector/twig.html.twig" id="twig" priority="257" />
|
||||||
|
@ -108,7 +109,7 @@
|
||||||
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.debug" class="Twig_Extension_Debug" />
|
<service id="twig.extension.debug" class="Twig\Extension\DebugExtension" />
|
||||||
|
|
||||||
<service id="twig.translation.extractor" class="Symfony\Bridge\Twig\Translation\TwigExtractor" public="true">
|
<service id="twig.translation.extractor" class="Symfony\Bridge\Twig\Translation\TwigExtractor" public="true">
|
||||||
<argument type="service" id="twig" />
|
<argument type="service" id="twig" />
|
||||||
|
@ -145,7 +146,7 @@
|
||||||
<argument /> <!-- thousands separator, set in TwigExtension -->
|
<argument /> <!-- thousands separator, set in TwigExtension -->
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.runtime_loader" class="Twig_ContainerRuntimeLoader">
|
<service id="twig.runtime_loader" class="Twig\RuntimeLoader\ContainerRuntimeLoader">
|
||||||
<argument /> <!-- runtime locator -->
|
<argument /> <!-- runtime locator -->
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
|
@ -15,13 +15,15 @@ use Symfony\Bundle\TwigBundle\Tests\TestCase;
|
||||||
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
|
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
|
|
||||||
class ExceptionControllerTest extends TestCase
|
class ExceptionControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testShowActionCanBeForcedToShowErrorPage()
|
public function testShowActionCanBeForcedToShowErrorPage()
|
||||||
{
|
{
|
||||||
$twig = new \Twig_Environment(
|
$twig = new Environment(
|
||||||
new \Twig_Loader_Array(array(
|
new ArrayLoader(array(
|
||||||
'@Twig/Exception/error404.html.twig' => 'ok',
|
'@Twig/Exception/error404.html.twig' => 'ok',
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
@ -40,8 +42,8 @@ class ExceptionControllerTest extends TestCase
|
||||||
|
|
||||||
public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
|
public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
|
||||||
{
|
{
|
||||||
$twig = new \Twig_Environment(
|
$twig = new Environment(
|
||||||
new \Twig_Loader_Array(array(
|
new ArrayLoader(array(
|
||||||
'@Twig/Exception/error.html.twig' => 'html',
|
'@Twig/Exception/error.html.twig' => 'html',
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ExtensionPassTest extends TestCase
|
||||||
$container->register('twig.extension.debug.stopwatch');
|
$container->register('twig.extension.debug.stopwatch');
|
||||||
$container->register('twig.extension.expression');
|
$container->register('twig.extension.expression');
|
||||||
|
|
||||||
$nativeTwigLoader = new Definition('\Twig_Loader_Filesystem');
|
$nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader');
|
||||||
$nativeTwigLoader->addMethodCall('addPath', array());
|
$nativeTwigLoader->addMethodCall('addPath', array());
|
||||||
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);
|
$container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class TwigExtensionTest extends TestCase
|
||||||
$container->loadFromExtension('twig', array());
|
$container->loadFromExtension('twig', array());
|
||||||
$this->compileContainer($container);
|
$this->compileContainer($container);
|
||||||
|
|
||||||
$this->assertEquals('Twig_Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
|
$this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
|
||||||
|
|
||||||
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');
|
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class TwigExtensionTest extends TestCase
|
||||||
$this->loadFromFile($container, 'full', $format);
|
$this->loadFromFile($container, 'full', $format);
|
||||||
$this->compileContainer($container);
|
$this->compileContainer($container);
|
||||||
|
|
||||||
$this->assertEquals('Twig_Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
|
$this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file');
|
||||||
|
|
||||||
// Form resources
|
// Form resources
|
||||||
$resources = $container->getParameter('twig.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()
|
public function testTwigErrorIfLocatorThrowsInvalid()
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,7 @@ class FilesystemLoaderTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error_Loader
|
* @expectedException \Twig\Error\LoaderError
|
||||||
*/
|
*/
|
||||||
public function testTwigErrorIfLocatorReturnsFalse()
|
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\)/
|
* @expectedExceptionMessageRegExp /Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/
|
||||||
*/
|
*/
|
||||||
public function testTwigErrorIfTemplateDoesNotExist()
|
public function testTwigErrorIfTemplateDoesNotExist()
|
||||||
|
|
|
@ -17,6 +17,8 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
||||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Config\FileLocatorInterface;
|
use Symfony\Component\Config\FileLocatorInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This engine renders Twig templates.
|
* This engine renders Twig templates.
|
||||||
|
@ -27,14 +29,7 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||||
{
|
{
|
||||||
protected $locator;
|
protected $locator;
|
||||||
|
|
||||||
/**
|
public function __construct(Environment $environment, TemplateNameParserInterface $parser, FileLocatorInterface $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)
|
|
||||||
{
|
{
|
||||||
parent::__construct($environment, $parser);
|
parent::__construct($environment, $parser);
|
||||||
|
|
||||||
|
@ -48,7 +43,7 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return parent::render($name, $parameters);
|
return parent::render($name, $parameters);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (Error $e) {
|
||||||
if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) {
|
if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) {
|
||||||
try {
|
try {
|
||||||
// try to get the real name of the template where the error occurred
|
// try to get the real name of the template where the error occurred
|
||||||
|
@ -66,7 +61,7 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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)
|
public function renderResponse($view, array $parameters = array(), Response $response = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"symfony/twig-bridge": "^3.3",
|
"symfony/twig-bridge": "^3.3",
|
||||||
"symfony/http-foundation": "~2.8|~3.0",
|
"symfony/http-foundation": "~2.8|~3.0",
|
||||||
"symfony/http-kernel": "^3.3",
|
"symfony/http-kernel": "^3.3",
|
||||||
"twig/twig": "^1.32|^2.2"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/asset": "~2.8|~3.0",
|
"symfony/asset": "~2.8|~3.0",
|
||||||
|
|
|
@ -15,6 +15,9 @@ use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||||
use Symfony\Component\Debug\ExceptionHandler;
|
use Symfony\Component\Debug\ExceptionHandler;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Loader\ExistsLoaderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExceptionController.
|
* ExceptionController.
|
||||||
|
@ -27,7 +30,7 @@ class ExceptionController
|
||||||
protected $debug;
|
protected $debug;
|
||||||
protected $profiler;
|
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->profiler = $profiler;
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
|
@ -112,7 +115,7 @@ class ExceptionController
|
||||||
protected function templateExists($template)
|
protected function templateExists($template)
|
||||||
{
|
{
|
||||||
$loader = $this->twig->getLoader();
|
$loader = $this->twig->getLoader();
|
||||||
if ($loader instanceof \Twig_ExistsLoaderInterface) {
|
if ($loader instanceof ExistsLoaderInterface) {
|
||||||
return $loader->exists($template);
|
return $loader->exists($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +123,7 @@ class ExceptionController
|
||||||
$loader->getSource($template);
|
$loader->getSource($template);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProfilerController.
|
* ProfilerController.
|
||||||
|
@ -42,13 +43,13 @@ class ProfilerController
|
||||||
*
|
*
|
||||||
* @param UrlGeneratorInterface $generator The URL Generator
|
* @param UrlGeneratorInterface $generator The URL Generator
|
||||||
* @param Profiler $profiler The profiler
|
* @param Profiler $profiler The profiler
|
||||||
* @param \Twig_Environment $twig The twig environment
|
* @param Environment $twig The twig environment
|
||||||
* @param array $templates The templates
|
* @param array $templates The templates
|
||||||
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
|
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
|
||||||
* @param ContentSecurityPolicyHandler $cspHandler The Content-Security-Policy handler
|
* @param ContentSecurityPolicyHandler $cspHandler The Content-Security-Policy handler
|
||||||
* @param string $baseDir The project root directory
|
* @param string $baseDir The project root directory
|
||||||
*/
|
*/
|
||||||
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
|
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
|
||||||
{
|
{
|
||||||
$this->generator = $generator;
|
$this->generator = $generator;
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Symfony\Component\Routing\RouterInterface;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||||
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RouterController.
|
* RouterController.
|
||||||
|
@ -33,7 +34,7 @@ class RouterController
|
||||||
private $matcher;
|
private $matcher;
|
||||||
private $routes;
|
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->profiler = $profiler;
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
|
|
|
@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebDebugToolbarListener injects the Web Debug Toolbar.
|
* WebDebugToolbarListener injects the Web Debug Toolbar.
|
||||||
|
@ -43,7 +44,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|
||||||
protected $excludedAjaxPaths;
|
protected $excludedAjaxPaths;
|
||||||
private $cspHandler;
|
private $cspHandler;
|
||||||
|
|
||||||
public function __construct(\Twig_Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt', ContentSecurityPolicyHandler $cspHandler = null)
|
public function __construct(Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt', ContentSecurityPolicyHandler $cspHandler = null)
|
||||||
{
|
{
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
|
|
@ -14,6 +14,11 @@ namespace Symfony\Bundle\WebProfilerBundle\Profiler;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
||||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
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.
|
* Profiler Templates Manager.
|
||||||
|
@ -27,14 +32,7 @@ class TemplateManager
|
||||||
protected $templates;
|
protected $templates;
|
||||||
protected $profiler;
|
protected $profiler;
|
||||||
|
|
||||||
/**
|
public function __construct(Profiler $profiler, Environment $twig, array $templates)
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param Profiler $profiler
|
|
||||||
* @param \Twig_Environment $twig
|
|
||||||
* @param array $templates
|
|
||||||
*/
|
|
||||||
public function __construct(Profiler $profiler, \Twig_Environment $twig, array $templates)
|
|
||||||
{
|
{
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
$this->twig = $twig;
|
$this->twig = $twig;
|
||||||
|
@ -67,7 +65,7 @@ class TemplateManager
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
*
|
*
|
||||||
* @return \Twig_Template[]
|
* @return Template[]
|
||||||
*
|
*
|
||||||
* @deprecated not used anymore internally
|
* @deprecated not used anymore internally
|
||||||
*/
|
*/
|
||||||
|
@ -124,19 +122,19 @@ class TemplateManager
|
||||||
protected function templateExists($template)
|
protected function templateExists($template)
|
||||||
{
|
{
|
||||||
$loader = $this->twig->getLoader();
|
$loader = $this->twig->getLoader();
|
||||||
if ($loader instanceof \Twig_ExistsLoaderInterface) {
|
if ($loader instanceof ExistsLoaderInterface) {
|
||||||
return $loader->exists($template);
|
return $loader->exists($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($loader instanceof \Twig_SourceContextLoaderInterface) {
|
if ($loader instanceof SourceContextLoaderInterface) {
|
||||||
$loader->getSourceContext($template);
|
$loader->getSourceContext($template);
|
||||||
} else {
|
} else {
|
||||||
$loader->getSource($template);
|
$loader->getSource($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ProfilerControllerTest extends TestCase
|
||||||
public function testEmptyToken($token)
|
public function testEmptyToken($token)
|
||||||
{
|
{
|
||||||
$urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock();
|
$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
|
$profiler = $this
|
||||||
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -51,7 +51,7 @@ class ProfilerControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testReturns404onTokenNotFound($withCsp)
|
public function testReturns404onTokenNotFound($withCsp)
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$profiler = $this
|
$profiler = $this
|
||||||
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -81,7 +81,7 @@ class ProfilerControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSearchResult($withCsp)
|
public function testSearchResult($withCsp)
|
||||||
{
|
{
|
||||||
$twig = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$profiler = $this
|
$profiler = $this
|
||||||
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
|
|
@ -52,9 +52,9 @@ class WebProfilerExtensionTest extends TestCase
|
||||||
|
|
||||||
$this->container = new ContainerBuilder();
|
$this->container = new ContainerBuilder();
|
||||||
$this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'));
|
$this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'));
|
||||||
$this->container->register('twig', 'Twig_Environment');
|
$this->container->register('twig', 'Twig\Environment');
|
||||||
$this->container->register('twig_loader', 'Twig_Loader_Array')->addArgument(array());
|
$this->container->register('twig_loader', 'Twig\Loader\ArrayLoader')->addArgument(array());
|
||||||
$this->container->register('twig', 'Twig_Environment')->addArgument(new Reference('twig_loader'));
|
$this->container->register('twig', 'Twig\Environment')->addArgument(new Reference('twig_loader'));
|
||||||
$this->container->setParameter('kernel.bundles', array());
|
$this->container->setParameter('kernel.bundles', array());
|
||||||
$this->container->setParameter('kernel.cache_dir', __DIR__);
|
$this->container->setParameter('kernel.cache_dir', __DIR__);
|
||||||
$this->container->setParameter('kernel.debug', false);
|
$this->container->setParameter('kernel.debug', false);
|
||||||
|
|
|
@ -291,7 +291,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
||||||
|
|
||||||
protected function getTwigMock($render = 'WDT')
|
protected function getTwigMock($render = 'WDT')
|
||||||
{
|
{
|
||||||
$templating = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
$templating = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
$templating->expects($this->any())
|
$templating->expects($this->any())
|
||||||
->method('render')
|
->method('render')
|
||||||
->will($this->returnValue($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\Tests\TestCase;
|
||||||
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
|
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for TemplateManager class.
|
* Test for TemplateManager class.
|
||||||
|
@ -22,7 +23,7 @@ use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
|
||||||
class TemplateManagerTest extends TestCase
|
class TemplateManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Twig_Environment
|
* @var Environment
|
||||||
*/
|
*/
|
||||||
protected $twigEnvironment;
|
protected $twigEnvironment;
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ class TemplateManagerTest extends TestCase
|
||||||
'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'),
|
'data_collector.foo' => array('foo', 'FooBundle:Collector:foo'),
|
||||||
'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'),
|
'data_collector.bar' => array('bar', 'FooBundle:Collector:bar'),
|
||||||
'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'),
|
'data_collector.baz' => array('baz', 'FooBundle:Collector:baz'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
|
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
|
||||||
}
|
}
|
||||||
|
@ -129,16 +130,16 @@ class TemplateManagerTest extends TestCase
|
||||||
|
|
||||||
protected function mockTwigEnvironment()
|
protected function mockTwigEnvironment()
|
||||||
{
|
{
|
||||||
$this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
|
$this->twigEnvironment = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$this->twigEnvironment->expects($this->any())
|
$this->twigEnvironment->expects($this->any())
|
||||||
->method('loadTemplate')
|
->method('loadTemplate')
|
||||||
->will($this->returnValue('loadedTemplate'));
|
->will($this->returnValue('loadedTemplate'));
|
||||||
|
|
||||||
if (interface_exists('\Twig_SourceContextLoaderInterface')) {
|
if (interface_exists('Twig\Loader\SourceContextLoaderInterface')) {
|
||||||
$loader = $this->getMockBuilder('\Twig_SourceContextLoaderInterface')->getMock();
|
$loader = $this->getMockBuilder('Twig\Loader\SourceContextLoaderInterface')->getMock();
|
||||||
} else {
|
} 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));
|
$this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader));
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,17 @@ namespace Symfony\Bundle\WebProfilerBundle\Twig;
|
||||||
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
|
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
|
||||||
use Symfony\Component\VarDumper\Cloner\Data;
|
use Symfony\Component\VarDumper\Cloner\Data;
|
||||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Extension\ProfilerExtension;
|
||||||
|
use Twig\Profiler\Profile;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig extension for the profiler.
|
* Twig extension for the profiler.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class WebProfilerExtension extends \Twig_Extension_Profiler
|
class WebProfilerExtension extends ProfilerExtension
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ValueExporter
|
* @var ValueExporter
|
||||||
|
@ -48,12 +52,12 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
|
||||||
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
|
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enter(\Twig_Profiler_Profile $profile)
|
public function enter(Profile $profile)
|
||||||
{
|
{
|
||||||
++$this->stackLevel;
|
++$this->stackLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(\Twig_Profiler_Profile $profile)
|
public function leave(Profile $profile)
|
||||||
{
|
{
|
||||||
if (0 === --$this->stackLevel) {
|
if (0 === --$this->stackLevel) {
|
||||||
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
|
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
|
||||||
|
@ -65,17 +69,17 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
|
||||||
*/
|
*/
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
$profilerDump = function (\Twig_Environment $env, $value, $maxDepth = 0) {
|
$profilerDump = function (Environment $env, $value, $maxDepth = 0) {
|
||||||
return $value instanceof Data ? $this->dumpData($env, $value, $maxDepth) : twig_escape_filter($env, $this->dumpValue($value));
|
return $value instanceof Data ? $this->dumpData($env, $value, $maxDepth) : twig_escape_filter($env, $this->dumpValue($value));
|
||||||
};
|
};
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
new \Twig_SimpleFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)),
|
new TwigFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)),
|
||||||
new \Twig_SimpleFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)),
|
new TwigFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dumpData(\Twig_Environment $env, Data $data, $maxDepth = 0)
|
public function dumpData(Environment $env, Data $data, $maxDepth = 0)
|
||||||
{
|
{
|
||||||
$this->dumper->setCharset($env->getCharset());
|
$this->dumper->setCharset($env->getCharset());
|
||||||
$this->dumper->dump($data, null, array(
|
$this->dumper->dump($data, null, array(
|
||||||
|
@ -89,7 +93,7 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
|
||||||
return str_replace("\n</pre", '</pre', rtrim($dump));
|
return str_replace("\n</pre", '</pre', rtrim($dump));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dumpLog(\Twig_Environment $env, $message, Data $context = null)
|
public function dumpLog(Environment $env, $message, Data $context = null)
|
||||||
{
|
{
|
||||||
$message = twig_escape_filter($env, $message);
|
$message = twig_escape_filter($env, $message);
|
||||||
$message = preg_replace('/"(.*?)"/', '"<b>$1</b>"', $message);
|
$message = preg_replace('/"(.*?)"/', '"<b>$1</b>"', $message);
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
"symfony/polyfill-php70": "~1.0",
|
"symfony/polyfill-php70": "~1.0",
|
||||||
"symfony/routing": "~2.8|~3.0",
|
"symfony/routing": "~2.8|~3.0",
|
||||||
"symfony/twig-bridge": "~2.8|~3.0",
|
"symfony/twig-bridge": "~2.8|~3.0",
|
||||||
"twig/twig": "~1.28|~2.0",
|
"symfony/var-dumper": "~3.3",
|
||||||
"symfony/var-dumper": "~3.3"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/config": "~2.8|~3.0",
|
"symfony/config": "~2.8|~3.0",
|
||||||
|
|
|
@ -116,7 +116,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
||||||
public function hasListeners($eventName = null)
|
public function hasListeners($eventName = null)
|
||||||
{
|
{
|
||||||
if (null === $eventName) {
|
if (null === $eventName) {
|
||||||
return count($this->listenerIds) || count($this->listeners) || parent::hasListeners();
|
return $this->listenerIds || $this->listeners || parent::hasListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->listenerIds[$eventName])) {
|
if (isset($this->listenerIds[$eventName])) {
|
||||||
|
|
|
@ -56,6 +56,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
||||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
||||||
|
$this->assertTrue($this->dispatcher->hasListeners());
|
||||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||||
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
|
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
|
||||||
|
|
|
@ -20,6 +20,7 @@ use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||||
|
use Twig\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
@ -91,7 +92,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||||
$line = $trace[$i]['line'];
|
$line = $trace[$i]['line'];
|
||||||
|
|
||||||
break;
|
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'];
|
$template = $trace[$i]['object'];
|
||||||
$name = $template->getTemplateName();
|
$name = $template->getTemplateName();
|
||||||
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
|
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue