This commit is contained in:
Fabien Potencier
2021-05-12 09:47:40 +02:00
parent 13e360972a
commit fcbaa669ab
11 changed files with 41 additions and 38 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ class CacheNode extends Node
if ($this->hasNode('tags')) {
$compiler
->write("\$item->tag(")
->write('$item->tag(')
->subcompile($this->getNode('tags'))
->raw(");\n")
;
+2 -1
View File
@@ -78,7 +78,8 @@ class FunctionalTest extends TestCase
$this->cache = $cache;
}
public function load($class) {
public function load($class)
{
if (CacheRuntime::class === $class) {
return new CacheRuntime($this->cache);
}
+3 -2
View File
@@ -29,8 +29,9 @@ class IntegrationTest extends IntegrationTestCase
protected function getRuntimeLoaders()
{
return [
new class implements RuntimeLoaderInterface {
public function load($class) {
new class() implements RuntimeLoaderInterface {
public function load($class)
{
if (CacheRuntime::class === $class) {
return new CacheRuntime(new ArrayAdapter());
}
@@ -34,14 +34,14 @@ class CacheTokenParser extends AbstractTokenParser
switch ($k) {
case 'ttl':
if (1 !== count($args)) {
throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
if (1 !== \count($args)) {
throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$ttl = $args->getNode(0);
break;
case 'tags':
if (1 !== count($args)) {
throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
if (1 !== \count($args)) {
throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$tags = $args->getNode(0);
break;
@@ -19,7 +19,7 @@ use Twig\Extra\Cache\CacheExtension;
use Twig\Extra\Cache\CacheRuntime;
return static function (ContainerConfigurator $container) {
$service = function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service') ? 'Symfony\Component\DependencyInjection\Loader\Configurator\service' : 'Symfony\Component\DependencyInjection\Loader\Configurator\ref';
$service = \function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service') ? 'Symfony\Component\DependencyInjection\Loader\Configurator\service' : 'Symfony\Component\DependencyInjection\Loader\Configurator\ref';
$container->services()
->set('twig.extension.cache', CacheExtension::class)
->tag('twig.extension')
@@ -32,7 +32,7 @@ return static function (ContainerConfigurator $container) {
->set('twig.cache', TagAwareAdapter::class)
->args([
$service('.twig.cache.inner')
$service('.twig.cache.inner'),
])
->set('.twig.cache.inner')
+9 -9
View File
@@ -38,12 +38,12 @@ use Twig\TokenParser\TokenParserInterface;
*/
class Environment
{
const VERSION = '3.3.1-DEV';
const VERSION_ID = 30301;
const MAJOR_VERSION = 3;
const MINOR_VERSION = 3;
const RELEASE_VERSION = 1;
const EXTRA_VERSION = 'DEV';
public const VERSION = '3.3.1-DEV';
public const VERSION_ID = 30301;
public const MAJOR_VERSION = 3;
public const MINOR_VERSION = 3;
public const RELEASE_VERSION = 1;
public const EXTRA_VERSION = 'DEV';
private $charset;
private $loader;
@@ -235,7 +235,7 @@ class Environment
} elseif ($cache instanceof CacheInterface) {
$this->originalCache = $this->cache = $cache;
} else {
throw new \LogicException(sprintf('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'));
throw new \LogicException('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.');
}
}
@@ -804,8 +804,8 @@ class Environment
{
$this->optionsHash = implode(':', [
$this->extensionSet->getSignature(),
PHP_MAJOR_VERSION,
PHP_MINOR_VERSION,
\PHP_MAJOR_VERSION,
\PHP_MINOR_VERSION,
self::VERSION,
(int) $this->debug,
(int) $this->strictVariables,
+1 -1
View File
@@ -168,7 +168,7 @@ class Error extends \Exception
$template = null;
$templateClass = null;
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT);
foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Template) {
$currentClass = \get_class($trace['object']);
+3 -2
View File
@@ -484,6 +484,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null)
if (null === $date) {
$date = 'now';
}
return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension(CoreExtension::class)->getTimezone());
}
@@ -582,7 +583,7 @@ function twig_number_format_filter(Environment $env, $number, $decimal = null, $
function twig_urlencode_filter($url)
{
if (\is_array($url)) {
return http_build_query($url, '', '&', PHP_QUERY_RFC3986);
return http_build_query($url, '', '&', \PHP_QUERY_RFC3986);
}
return rawurlencode($url);
@@ -1108,7 +1109,7 @@ function twig_lower_filter(Environment $env, $string)
function twig_title_string_filter(Environment $env, $string)
{
if (null !== $charset = $env->getCharset()) {
return mb_convert_case($string, MB_CASE_TITLE, $charset);
return mb_convert_case($string, \MB_CASE_TITLE, $charset);
}
return ucwords(strtolower($string));
+4 -4
View File
@@ -39,10 +39,10 @@ use Twig\Node\PrintNode;
*/
final class OptimizerNodeVisitor implements NodeVisitorInterface
{
const OPTIMIZE_ALL = -1;
const OPTIMIZE_NONE = 0;
const OPTIMIZE_FOR = 2;
const OPTIMIZE_RAW_FILTER = 4;
public const OPTIMIZE_ALL = -1;
public const OPTIMIZE_NONE = 0;
public const OPTIMIZE_FOR = 2;
public const OPTIMIZE_RAW_FILTER = 4;
private $loops = [];
private $loopsTargets = [];
+4 -4
View File
@@ -16,10 +16,10 @@ namespace Twig\Profiler;
*/
final class Profile implements \IteratorAggregate, \Serializable
{
const ROOT = 'ROOT';
const BLOCK = 'block';
const TEMPLATE = 'template';
const MACRO = 'macro';
public const ROOT = 'ROOT';
public const BLOCK = 'block';
public const TEMPLATE = 'template';
public const MACRO = 'macro';
private $template;
private $name;
+8 -8
View File
@@ -263,10 +263,10 @@ class CoreTest extends TestCase
public function testCompareNAN()
{
$this->assertSame(1, twig_compare(NAN, 'NAN'));
$this->assertSame(1, twig_compare('NAN', NAN));
$this->assertSame(1, twig_compare(NAN, 'foo'));
$this->assertSame(1, twig_compare('foo', NAN));
$this->assertSame(1, twig_compare(\NAN, 'NAN'));
$this->assertSame(1, twig_compare('NAN', \NAN));
$this->assertSame(1, twig_compare(\NAN, 'foo'));
$this->assertSame(1, twig_compare('foo', \NAN));
}
public function provideCompareCases()
@@ -312,10 +312,10 @@ class CoreTest extends TestCase
[-1, 42.0, 'abc42.0'],
[-1, 0.0, 'abc42.0'],
[0, INF, 'INF'],
[0, -INF, '-INF'],
[0, INF, '1e1000'],
[0, -INF, '-1e1000'],
[0, \INF, 'INF'],
[0, -\INF, '-INF'],
[0, \INF, '1e1000'],
[0, -\INF, '-1e1000'],
[-1, 10, 20],
[-1, '10', 20],