fixed class usage

This commit is contained in:
Fabien Potencier
2019-03-04 18:18:04 +01:00
parent fb6d12f721
commit 0bc263247c
15 changed files with 56 additions and 40 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ class Twig_Cache_Filesystem implements CacheInterface
/** /**
* @param string $directory The root cache directory * @param string $directory The root cache directory
* @param int $options A set of options * @param int $options A set of options
*/ */
public function __construct($directory, $options = 0) public function __construct($directory, $options = 0)
{ {
+1 -1
View File
@@ -812,7 +812,7 @@ class Twig_Environment
public function setLoader(LoaderInterface $loader) public function setLoader(LoaderInterface $loader)
{ {
if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) {
@trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED);
} }
$this->loader = $loader; $this->loader = $loader;
+9 -6
View File
@@ -210,9 +210,12 @@ class Twig_ExpressionParser
$class = $this->unaryOperators[$token->getValue()]['class']; $class = $this->unaryOperators[$token->getValue()]['class'];
$ref = new \ReflectionClass($class); $ref = new \ReflectionClass($class);
$negClass = 'Twig_Node_Expression_Unary_Neg'; $negClass = 'Twig\Node\Expression\Unary\NegUnary';
$posClass = 'Twig_Node_Expression_Unary_Pos'; $posClass = 'Twig\Node\Expression\Unary\PosUnary';
if (!(\in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { if (!(\in_array($ref->getName(), [$negClass, $posClass, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos'])
|| $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass)
|| $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos'))
) {
throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
} }
@@ -683,7 +686,7 @@ class Twig_ExpressionParser
return $test->getNodeClass(); return $test->getNodeClass();
} }
return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig_Node_Expression_Test'; return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig\Node\Expression\TestExpression';
} }
protected function getFunctionNodeClass($name, $line) protected function getFunctionNodeClass($name, $line)
@@ -713,7 +716,7 @@ class Twig_ExpressionParser
return $function->getNodeClass(); return $function->getNodeClass();
} }
return $function instanceof Twig_Function_Node ? $function->getClass() : 'Twig_Node_Expression_Function'; return $function instanceof Twig_Function_Node ? $function->getClass() : 'Twig\Node_Expression_Function';
} }
protected function getFilterNodeClass($name, $line) protected function getFilterNodeClass($name, $line)
@@ -743,7 +746,7 @@ class Twig_ExpressionParser
return $filter->getNodeClass(); return $filter->getNodeClass();
} }
return $filter instanceof Twig_Filter_Node ? $filter->getClass() : 'Twig_Node_Expression_Filter'; return $filter instanceof Twig_Filter_Node ? $filter->getClass() : 'Twig\Node\Expression\FilterExpression';
} }
// checks that the node only contains "constant" elements // checks that the node only contains "constant" elements
+17 -16
View File
@@ -17,6 +17,7 @@ use Twig\Extension\AbstractExtension;
use Twig\Loader\SourceContextLoaderInterface; use Twig\Loader\SourceContextLoaderInterface;
use Twig\Markup; use Twig\Markup;
use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Node;
use Twig\TokenParser\BlockTokenParser; use Twig\TokenParser\BlockTokenParser;
use Twig\TokenParser\DeprecatedTokenParser; use Twig\TokenParser\DeprecatedTokenParser;
use Twig\TokenParser\DoTokenParser; use Twig\TokenParser\DoTokenParser;
@@ -305,14 +306,14 @@ class Twig_Extension_Core extends AbstractExtension
/** /**
* Cycles over a value. * Cycles over a value.
* *
* @param ArrayAccess|array $values * @param \ArrayAccess|array $values
* @param int $position The cycle position * @param int $position The cycle position
* *
* @return string The next value in the cycle * @return string The next value in the cycle
*/ */
function twig_cycle($values, $position) function twig_cycle($values, $position)
{ {
if (!\is_array($values) && !$values instanceof ArrayAccess) { if (!\is_array($values) && !$values instanceof \ArrayAccess) {
return $values; return $values;
} }
@@ -331,7 +332,7 @@ function twig_cycle($values, $position)
* *
* @return mixed A random value from the given sequence * @return mixed A random value from the given sequence
*/ */
function twig_random(Twig_Environment $env, $values = null) function twig_random(Environment $env, $values = null)
{ {
if (null === $values) { if (null === $values) {
return mt_rand(); return mt_rand();
@@ -388,7 +389,7 @@ function twig_random(Twig_Environment $env, $values = null)
* *
* @return string The formatted date * @return string The formatted date
*/ */
function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) function twig_date_format_filter(Environment $env, $date, $format = null, $timezone = null)
{ {
if (null === $format) { if (null === $format) {
$formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat(); $formats = $env->getExtension('\Twig\Extension\CoreExtension')->getDateFormat();
@@ -412,7 +413,7 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
* *
* @return \DateTime A new date object * @return \DateTime A new date object
*/ */
function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) function twig_date_modify_filter(Environment $env, $date, $modifier)
{ {
$date = twig_date_converter($env, $date, false); $date = twig_date_converter($env, $date, false);
$resultDate = $date->modify($modifier); $resultDate = $date->modify($modifier);
@@ -435,7 +436,7 @@ function twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
* *
* @return \DateTime A \DateTime instance * @return \DateTime A \DateTime instance
*/ */
function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) function twig_date_converter(Environment $env, $date = null, $timezone = null)
{ {
// determine the timezone // determine the timezone
if (false !== $timezone) { if (false !== $timezone) {
@@ -538,7 +539,7 @@ function twig_round($value, $precision = 0, $method = 'common')
* *
* @return string The formatted number * @return string The formatted number
*/ */
function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null) function twig_number_format_filter(Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
{ {
$defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat(); $defaults = $env->getExtension('\Twig\Extension\CoreExtension')->getNumberFormat();
if (null === $decimal) { if (null === $decimal) {
@@ -643,7 +644,7 @@ function twig_array_merge($arr1, $arr2)
* *
* @return mixed The sliced variable * @return mixed The sliced variable
*/ */
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) function twig_slice(Environment $env, $item, $start, $length = null, $preserveKeys = false)
{ {
if ($item instanceof \Traversable) { if ($item instanceof \Traversable) {
while ($item instanceof \IteratorAggregate) { while ($item instanceof \IteratorAggregate) {
@@ -681,7 +682,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese
* *
* @return mixed The first element of the item * @return mixed The first element of the item
*/ */
function twig_first(Twig_Environment $env, $item) function twig_first(Environment $env, $item)
{ {
$elements = twig_slice($env, $item, 0, 1, false); $elements = twig_slice($env, $item, 0, 1, false);
@@ -695,7 +696,7 @@ function twig_first(Twig_Environment $env, $item)
* *
* @return mixed The last element of the item * @return mixed The last element of the item
*/ */
function twig_last(Twig_Environment $env, $item) function twig_last(Environment $env, $item)
{ {
$elements = twig_slice($env, $item, -1, 1, false); $elements = twig_slice($env, $item, -1, 1, false);
@@ -767,7 +768,7 @@ function twig_join_filter($value, $glue = '', $and = null)
* *
* @return array The split string as an array * @return array The split string as an array
*/ */
function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = null) function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{ {
if (!empty($delimiter)) { if (!empty($delimiter)) {
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
@@ -863,7 +864,7 @@ function twig_get_array_keys_filter($array)
* *
* @return mixed The reversed input * @return mixed The reversed input
*/ */
function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false) function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
{ {
if ($item instanceof \Traversable) { if ($item instanceof \Traversable) {
return array_reverse(iterator_to_array($item), $preserveKeys); return array_reverse(iterator_to_array($item), $preserveKeys);
@@ -979,7 +980,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both')
* *
* @return string * @return string
*/ */
function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false)
{ {
if ($autoescape && $string instanceof Markup) { if ($autoescape && $string instanceof Markup) {
return $string; return $string;
@@ -1117,7 +1118,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
/** /**
* @internal * @internal
*/ */
function twig_escape_filter_is_safe(Twig_Node $filterArgs) function twig_escape_filter_is_safe(Node $filterArgs)
{ {
foreach ($filterArgs as $arg) { foreach ($filterArgs as $arg) {
if ($arg instanceof ConstantExpression) { if ($arg instanceof ConstantExpression) {
@@ -1493,7 +1494,7 @@ function twig_test_iterable($value)
* *
* @return string The rendered template * @return string The rendered template
*/ */
function twig_include(Twig_Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) function twig_include(Environment $env, $context, $template, $variables = [], $withContext = true, $ignoreMissing = false, $sandboxed = false)
{ {
$alreadySandboxed = false; $alreadySandboxed = false;
$sandbox = null; $sandbox = null;
@@ -1548,7 +1549,7 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = [
* *
* @return string The template source * @return string The template source
*/ */
function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) function twig_source(Environment $env, $name, $ignoreMissing = false)
{ {
$loader = $env->getLoader(); $loader = $env->getLoader();
try { try {
+2 -1
View File
@@ -9,6 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Twig\Environment;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\Template; use Twig\Template;
use Twig\TwigFunction; use Twig\TwigFunction;
@@ -41,7 +42,7 @@ class Twig_Extension_Debug extends AbstractExtension
} }
} }
function twig_var_dump(Twig_Environment $env, $context) function twig_var_dump(Environment $env, $context)
{ {
if (!$env->isDebug()) { if (!$env->isDebug()) {
return; return;
+2 -1
View File
@@ -9,6 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Twig\Environment;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\Template; use Twig\Template;
use Twig\TwigFunction; use Twig\TwigFunction;
@@ -40,7 +41,7 @@ class Twig_Extension_StringLoader extends AbstractExtension
* *
* @return Template * @return Template
*/ */
function twig_template_from_string(Twig_Environment $env, $template) function twig_template_from_string(Environment $env, $template)
{ {
return $env->createTemplate((string) $template); return $env->createTemplate((string) $template);
} }
+3 -1
View File
@@ -10,7 +10,9 @@
*/ */
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Source; use Twig\Source;
/** /**
@@ -27,7 +29,7 @@ use Twig\Source;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class Twig_Loader_Array implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface class Twig_Loader_Array implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
{ {
protected $templates = []; protected $templates = [];
+1 -1
View File
@@ -22,7 +22,7 @@ use Twig\Source;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class Twig_Loader_Chain implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface class Twig_Loader_Chain implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
{ {
private $hasSourceCache = []; private $hasSourceCache = [];
protected $loaders = []; protected $loaders = [];
+3 -1
View File
@@ -10,7 +10,9 @@
*/ */
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Source; use Twig\Source;
/** /**
@@ -18,7 +20,7 @@ use Twig\Source;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class Twig_Loader_Filesystem implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface class Twig_Loader_Filesystem implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
{ {
/** Identifier of the main namespace. */ /** Identifier of the main namespace. */
const MAIN_NAMESPACE = '__main__'; const MAIN_NAMESPACE = '__main__';
+3 -1
View File
@@ -10,6 +10,8 @@
*/ */
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Source; use Twig\Source;
@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', E_USER_DEPRECATED); @trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', E_USER_DEPRECATED);
@@ -30,7 +32,7 @@ use Twig\Source;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class Twig_Loader_String implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface class Twig_Loader_String implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
{ {
public function getSource($name) public function getSource($name)
{ {
+1 -1
View File
@@ -27,7 +27,7 @@ interface Twig_LoaderInterface
* *
* @throws LoaderError When $name is not found * @throws LoaderError When $name is not found
* *
* @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface * @deprecated since 1.27 (to be removed in 2.0), implement Twig\Loader\SourceContextLoaderInterface
*/ */
public function getSource($name); public function getSource($name);
+2 -2
View File
@@ -517,7 +517,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;
if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object))) if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object)))
|| ($object instanceof ArrayAccess && isset($object[$arrayItem])) || ($object instanceof \ArrayAccess && isset($object[$arrayItem]))
) { ) {
if ($isDefinedTest) { if ($isDefinedTest) {
return true; return true;
@@ -535,7 +535,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
return; return;
} }
if ($object instanceof ArrayAccess) { if ($object instanceof \ArrayAccess) {
$message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object));
} elseif (\is_object($object)) { } elseif (\is_object($object)) {
$message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object)); $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
+2 -1
View File
@@ -16,6 +16,7 @@ use Twig\Extension\GlobalsInterface;
use Twig\Extension\InitRuntimeInterface; use Twig\Extension\InitRuntimeInterface;
use Twig\Loader\ArrayLoader; use Twig\Loader\ArrayLoader;
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\NodeVisitor\NodeVisitorInterface; use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\Source; use Twig\Source;
use Twig\Token; use Twig\Token;
@@ -698,6 +699,6 @@ class Twig_Tests_EnvironmentTest_Runtime
} }
// to be removed in 2.0 // to be removed in 2.0
interface Twig_EnvironmentTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface interface Twig_EnvironmentTestLoaderInterface extends LoaderInterface, SourceContextLoaderInterface
{ {
} }
+4 -2
View File
@@ -11,8 +11,10 @@
use Twig\Loader\ArrayLoader; use Twig\Loader\ArrayLoader;
use Twig\Loader\ChainLoader; use Twig\Loader\ChainLoader;
use Twig\Loader\ExistsLoaderInterface;
use Twig\Loader\FilesystemLoader; use Twig\Loader\FilesystemLoader;
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Source; use Twig\Source;
class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase
@@ -121,10 +123,10 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase
} }
} }
interface Twig_ChainTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface interface Twig_ChainTestLoaderInterface extends LoaderInterface, SourceContextLoaderInterface
{ {
} }
interface Twig_ChainTestLoaderWithExistsInterface extends LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface interface Twig_ChainTestLoaderWithExistsInterface extends LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
{ {
} }
+5 -4
View File
@@ -14,6 +14,7 @@ use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension; use Twig\Extension\SandboxExtension;
use Twig\Loader\ArrayLoader; use Twig\Loader\ArrayLoader;
use Twig\Loader\LoaderInterface; use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
use Twig\Node\Expression\GetAttrExpression; use Twig\Node\Expression\GetAttrExpression;
use Twig\NodeVisitor\NodeVisitorInterface; use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\Sandbox\SecurityError; use Twig\Sandbox\SecurityError;
@@ -523,7 +524,7 @@ class Twig_TemplateTest extends Template
} }
} }
class Twig_TemplateArrayAccessObject implements ArrayAccess class Twig_TemplateArrayAccessObject implements \ArrayAccess
{ {
protected $protected = 'protected'; protected $protected = 'protected';
@@ -611,7 +612,7 @@ class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject
} }
} }
class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements ArrayAccess class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements \ArrayAccess
{ {
private $data = [ private $data = [
'defined' => 'defined', 'defined' => 'defined',
@@ -739,7 +740,7 @@ class Twig_TemplateMethodAndPropObject
} }
} }
class Twig_TemplateArrayAccess implements ArrayAccess class Twig_TemplateArrayAccess implements \ArrayAccess
{ {
public $vars = [ public $vars = [
'foo' => 'bar', 'foo' => 'bar',
@@ -806,6 +807,6 @@ class CExtDisablingNodeVisitor implements NodeVisitorInterface
} }
// to be removed in 2.0 // to be removed in 2.0
interface Twig_TemplateTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface interface Twig_TemplateTestLoaderInterface extends LoaderInterface, SourceContextLoaderInterface
{ {
} }