mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-17 19:23:27 +02:00
Update Twig from 1.35.0 to 1.42.4 (PHP 5.5 is now required!)
This fixes some errors on PHP 7.4 and contains even more fixes Also bumped PHP version to 5.5 as Twig requires it.
This commit is contained in:
@@ -10,31 +10,38 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig;
|
||||
|
||||
use Twig\Error\Error;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
|
||||
/**
|
||||
* Default base class for compiled templates.
|
||||
*
|
||||
* This class is an implementation detail of how template compilation currently
|
||||
* works, which might change. It should never be used directly. Use $twig->load()
|
||||
* instead, which returns an instance of Twig_TemplateWrapper.
|
||||
* instead, which returns an instance of \Twig\TemplateWrapper.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract class Twig_Template implements Twig_TemplateInterface
|
||||
abstract class Template implements \Twig_TemplateInterface
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected static $cache = array();
|
||||
protected static $cache = [];
|
||||
|
||||
protected $parent;
|
||||
protected $parents = array();
|
||||
protected $parents = [];
|
||||
protected $env;
|
||||
protected $blocks = array();
|
||||
protected $traits = array();
|
||||
protected $blocks = [];
|
||||
protected $traits = [];
|
||||
protected $sandbox;
|
||||
|
||||
public function __construct(Twig_Environment $env)
|
||||
public function __construct(Environment $env)
|
||||
{
|
||||
$this->env = $env;
|
||||
}
|
||||
@@ -58,12 +65,10 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* Returns debug information about the template.
|
||||
*
|
||||
* @return array Debug information
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getDebugInfo()
|
||||
{
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,11 +88,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
/**
|
||||
* Returns information about the original template source code.
|
||||
*
|
||||
* @return Twig_Source
|
||||
* @return Source
|
||||
*/
|
||||
public function getSourceContext()
|
||||
{
|
||||
return new Twig_Source('', $this->getTemplateName());
|
||||
return new Source('', $this->getTemplateName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +113,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
*
|
||||
* @param array $context
|
||||
*
|
||||
* @return Twig_TemplateInterface|false The parent template or false if there is no parent
|
||||
* @return \Twig_TemplateInterface|TemplateWrapper|false The parent template or false if there is no parent
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -125,14 +130,14 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($parent instanceof self) {
|
||||
return $this->parents[$parent->getTemplateName()] = $parent;
|
||||
if ($parent instanceof self || $parent instanceof TemplateWrapper) {
|
||||
return $this->parents[$parent->getSourceContext()->getName()] = $parent;
|
||||
}
|
||||
|
||||
if (!isset($this->parents[$parent])) {
|
||||
$this->parents[$parent] = $this->loadTemplate($parent);
|
||||
}
|
||||
} catch (Twig_Error_Loader $e) {
|
||||
} catch (LoaderError $e) {
|
||||
$e->setSourceContext(null);
|
||||
$e->guess();
|
||||
|
||||
@@ -161,10 +166,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param string $name The block name to display from the parent
|
||||
* @param array $context The context
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function displayParentBlock($name, array $context, array $blocks = array())
|
||||
public function displayParentBlock($name, array $context, array $blocks = [])
|
||||
{
|
||||
$name = (string) $name;
|
||||
|
||||
@@ -173,7 +176,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
} elseif (false !== $parent = $this->getParent($context)) {
|
||||
$parent->displayBlock($name, $context, $blocks, false);
|
||||
} else {
|
||||
throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
|
||||
throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,10 +190,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $context The context
|
||||
* @param array $blocks The current set of blocks
|
||||
* @param bool $useBlocks Whether to use the current set of blocks
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true)
|
||||
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true)
|
||||
{
|
||||
$name = (string) $name;
|
||||
|
||||
@@ -207,27 +208,29 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
|
||||
// avoid RCEs when sandbox is enabled
|
||||
if (null !== $template && !$template instanceof self) {
|
||||
throw new LogicException('A block must be a method on a Twig_Template instance.');
|
||||
throw new \LogicException('A block must be a method on a \Twig\Template instance.');
|
||||
}
|
||||
|
||||
if (null !== $template) {
|
||||
try {
|
||||
$template->$block($context, $blocks);
|
||||
} catch (Twig_Error $e) {
|
||||
} catch (Error $e) {
|
||||
if (!$e->getSourceContext()) {
|
||||
$e->setSourceContext($template->getSourceContext());
|
||||
}
|
||||
|
||||
// this is mostly useful for Twig_Error_Loader exceptions
|
||||
// see Twig_Error_Loader
|
||||
if (false === $e->getTemplateLine()) {
|
||||
$e->setTemplateLine(-1);
|
||||
// this is mostly useful for \Twig\Error\LoaderError exceptions
|
||||
// see \Twig\Error\LoaderError
|
||||
if (-1 === $e->getTemplateLine()) {
|
||||
$e->guess();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
} catch (Exception $e) {
|
||||
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
|
||||
} catch (\Exception $e) {
|
||||
$e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
|
||||
$e->guess();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
} elseif (false !== $parent = $this->getParent($context)) {
|
||||
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
|
||||
@@ -247,12 +250,14 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return string The rendered block
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function renderParentBlock($name, array $context, array $blocks = array())
|
||||
public function renderParentBlock($name, array $context, array $blocks = [])
|
||||
{
|
||||
ob_start();
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
$this->displayParentBlock($name, $context, $blocks);
|
||||
|
||||
return ob_get_clean();
|
||||
@@ -270,12 +275,14 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param bool $useBlocks Whether to use the current set of blocks
|
||||
*
|
||||
* @return string The rendered block
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function renderBlock($name, array $context, array $blocks = array(), $useBlocks = true)
|
||||
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
|
||||
{
|
||||
ob_start();
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
$this->displayBlock($name, $context, $blocks, $useBlocks);
|
||||
|
||||
return ob_get_clean();
|
||||
@@ -292,10 +299,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return bool true if the block exists, false otherwise
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function hasBlock($name, array $context = null, array $blocks = array())
|
||||
public function hasBlock($name, array $context = null, array $blocks = [])
|
||||
{
|
||||
if (null === $context) {
|
||||
@trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
|
||||
@@ -328,10 +333,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return array An array of block names
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getBlockNames(array $context = null, array $blocks = array())
|
||||
public function getBlockNames(array $context = null, array $blocks = [])
|
||||
{
|
||||
if (null === $context) {
|
||||
@trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
|
||||
@@ -348,28 +351,36 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return array_unique($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Template|TemplateWrapper
|
||||
*/
|
||||
protected function loadTemplate($template, $templateName = null, $line = null, $index = null)
|
||||
{
|
||||
try {
|
||||
if (is_array($template)) {
|
||||
if (\is_array($template)) {
|
||||
return $this->env->resolveTemplate($template);
|
||||
}
|
||||
|
||||
if ($template instanceof self) {
|
||||
if ($template instanceof self || $template instanceof TemplateWrapper) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ($template instanceof Twig_TemplateWrapper) {
|
||||
return $template;
|
||||
if ($template === $this->getTemplateName()) {
|
||||
$class = \get_class($this);
|
||||
if (false !== $pos = strrpos($class, '___', -1)) {
|
||||
$class = substr($class, 0, $pos);
|
||||
}
|
||||
|
||||
return $this->env->loadClass($class, $template, $index);
|
||||
}
|
||||
|
||||
return $this->env->loadTemplate($template, $index);
|
||||
} catch (Twig_Error $e) {
|
||||
} catch (Error $e) {
|
||||
if (!$e->getSourceContext()) {
|
||||
$e->setSourceContext($templateName ? new Twig_Source('', $templateName) : $this->getSourceContext());
|
||||
$e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext());
|
||||
}
|
||||
|
||||
if ($e->getTemplateLine()) {
|
||||
if ($e->getTemplateLine() > 0) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -383,6 +394,16 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @return Template
|
||||
*/
|
||||
protected function unwrap()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all blocks.
|
||||
*
|
||||
@@ -390,15 +411,13 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* directly.
|
||||
*
|
||||
* @return array An array of blocks
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getBlocks()
|
||||
{
|
||||
return $this->blocks;
|
||||
}
|
||||
|
||||
public function display(array $context, array $blocks = array())
|
||||
public function display(array $context, array $blocks = [])
|
||||
{
|
||||
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
|
||||
}
|
||||
@@ -406,16 +425,20 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
public function render(array $context)
|
||||
{
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
try {
|
||||
$this->display($context);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
@@ -426,25 +449,27 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function displayWithErrorHandling(array $context, array $blocks = array())
|
||||
protected function displayWithErrorHandling(array $context, array $blocks = [])
|
||||
{
|
||||
try {
|
||||
$this->doDisplay($context, $blocks);
|
||||
} catch (Twig_Error $e) {
|
||||
} catch (Error $e) {
|
||||
if (!$e->getSourceContext()) {
|
||||
$e->setSourceContext($this->getSourceContext());
|
||||
}
|
||||
|
||||
// this is mostly useful for Twig_Error_Loader exceptions
|
||||
// see Twig_Error_Loader
|
||||
if (false === $e->getTemplateLine()) {
|
||||
$e->setTemplateLine(-1);
|
||||
// this is mostly useful for \Twig\Error\LoaderError exceptions
|
||||
// see \Twig\Error\LoaderError
|
||||
if (-1 === $e->getTemplateLine()) {
|
||||
$e->guess();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
} catch (Exception $e) {
|
||||
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
|
||||
} catch (\Exception $e) {
|
||||
$e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
|
||||
$e->guess();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,7 +479,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $context An array of parameters to pass to the template
|
||||
* @param array $blocks An array of blocks to pass to the template
|
||||
*/
|
||||
abstract protected function doDisplay(array $context, array $blocks = array());
|
||||
abstract protected function doDisplay(array $context, array $blocks = []);
|
||||
|
||||
/**
|
||||
* Returns a variable from the context.
|
||||
@@ -473,18 +498,18 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
*
|
||||
* @return mixed The content of the context variable
|
||||
*
|
||||
* @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
|
||||
* @throws RuntimeError if the variable does not exist and Twig is running in strict mode
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final protected function getContext($context, $item, $ignoreStrictCheck = false)
|
||||
{
|
||||
if (!array_key_exists($item, $context)) {
|
||||
if (!\array_key_exists($item, $context)) {
|
||||
if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
|
||||
throw new RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext());
|
||||
}
|
||||
|
||||
return $context[$item];
|
||||
@@ -496,24 +521,24 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param mixed $object The object or array from where to get the item
|
||||
* @param mixed $item The item to get from the array or object
|
||||
* @param array $arguments An array of arguments to pass if the item is an object method
|
||||
* @param string $type The type of attribute (@see Twig_Template constants)
|
||||
* @param string $type The type of attribute (@see \Twig\Template constants)
|
||||
* @param bool $isDefinedTest Whether this is only a defined check
|
||||
* @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not
|
||||
*
|
||||
* @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
|
||||
*
|
||||
* @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
|
||||
* @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
protected function getAttribute($object, $item, array $arguments = array(), $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
||||
protected function getAttribute($object, $item, array $arguments = [], $type = self::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
||||
{
|
||||
// array
|
||||
if (self::METHOD_CALL !== $type) {
|
||||
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
||||
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;
|
||||
|
||||
if ((is_array($object) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object)))
|
||||
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
|
||||
if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object)))
|
||||
|| ($object instanceof \ArrayAccess && isset($object[$arrayItem]))
|
||||
) {
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
@@ -522,7 +547,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return $object[$arrayItem];
|
||||
}
|
||||
|
||||
if (self::ARRAY_CALL === $type || !is_object($object)) {
|
||||
if (self::ARRAY_CALL === $type || !\is_object($object)) {
|
||||
if ($isDefinedTest) {
|
||||
return false;
|
||||
}
|
||||
@@ -531,11 +556,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if ($object instanceof ArrayAccess) {
|
||||
$message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($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));
|
||||
} elseif (is_array($object)) {
|
||||
if ($object instanceof \ArrayAccess) {
|
||||
$message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($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));
|
||||
} elseif (\is_array($object)) {
|
||||
if (empty($object)) {
|
||||
$message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem);
|
||||
} else {
|
||||
@@ -545,19 +570,19 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
if (null === $object) {
|
||||
$message = sprintf('Impossible to access a key ("%s") on a null variable.', $item);
|
||||
} else {
|
||||
$message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
|
||||
$message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
|
||||
}
|
||||
} elseif (null === $object) {
|
||||
$message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item);
|
||||
} else {
|
||||
$message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
|
||||
$message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
|
||||
throw new RuntimeError($message, -1, $this->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_object($object)) {
|
||||
if (!\is_object($object)) {
|
||||
if ($isDefinedTest) {
|
||||
return false;
|
||||
}
|
||||
@@ -568,38 +593,40 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
|
||||
if (null === $object) {
|
||||
$message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item);
|
||||
} elseif (\is_array($object)) {
|
||||
$message = sprintf('Impossible to invoke a method ("%s") on an array.', $item);
|
||||
} else {
|
||||
$message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object);
|
||||
$message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object);
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime($message, -1, $this->getSourceContext());
|
||||
throw new RuntimeError($message, -1, $this->getSourceContext());
|
||||
}
|
||||
|
||||
// object property
|
||||
if (self::METHOD_CALL !== $type && !$object instanceof self) { // Twig_Template does not have public properties, and we don't want to allow access to internal ones
|
||||
if (isset($object->$item) || array_key_exists((string) $item, $object)) {
|
||||
if (self::METHOD_CALL !== $type && !$object instanceof self) { // \Twig\Template does not have public properties, and we don't want to allow access to internal ones
|
||||
if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) {
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
|
||||
$this->env->getExtension('Twig_Extension_Sandbox')->checkPropertyAllowed($object, $item);
|
||||
if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
|
||||
$this->env->getExtension('\Twig\Extension\SandboxExtension')->checkPropertyAllowed($object, $item);
|
||||
}
|
||||
|
||||
return $object->$item;
|
||||
}
|
||||
}
|
||||
|
||||
$class = get_class($object);
|
||||
$class = \get_class($object);
|
||||
|
||||
// object method
|
||||
if (!isset(self::$cache[$class])) {
|
||||
// get_class_methods returns all methods accessible in the scope, but we only want public ones to be accessible in templates
|
||||
if ($object instanceof self) {
|
||||
$ref = new ReflectionClass($class);
|
||||
$methods = array();
|
||||
$ref = new \ReflectionClass($class);
|
||||
$methods = [];
|
||||
|
||||
foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) {
|
||||
foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) {
|
||||
// Accessing the environment from templates is forbidden to prevent untrusted changes to the environment
|
||||
if ('getenvironment' !== strtolower($refMethod->name)) {
|
||||
$methods[] = $refMethod->name;
|
||||
@@ -611,7 +638,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
// sort values to have consistent behavior, so that "get" methods win precedence over "is" methods
|
||||
sort($methods);
|
||||
|
||||
$cache = array();
|
||||
$cache = [];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$cache[$method] = $method;
|
||||
@@ -657,15 +684,15 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
|
||||
throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
|
||||
}
|
||||
|
||||
if ($isDefinedTest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->env->hasExtension('Twig_Extension_Sandbox')) {
|
||||
$this->env->getExtension('Twig_Extension_Sandbox')->checkMethodAllowed($object, $method);
|
||||
if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
|
||||
$this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method);
|
||||
}
|
||||
|
||||
// Some objects throw exceptions when they have __call, and the method we try
|
||||
@@ -674,9 +701,9 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
if (!$arguments) {
|
||||
$ret = $object->$method();
|
||||
} else {
|
||||
$ret = call_user_func_array(array($object, $method), $arguments);
|
||||
$ret = \call_user_func_array([$object, $method], $arguments);
|
||||
}
|
||||
} catch (BadMethodCallException $e) {
|
||||
} catch (\BadMethodCallException $e) {
|
||||
if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
|
||||
return;
|
||||
}
|
||||
@@ -684,7 +711,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
}
|
||||
|
||||
// @deprecated in 1.28
|
||||
if ($object instanceof Twig_TemplateInterface) {
|
||||
if ($object instanceof \Twig_TemplateInterface) {
|
||||
$self = $object->getTemplateName() === $this->getTemplateName();
|
||||
$message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName());
|
||||
if ('renderBlock' === $method || 'displayBlock' === $method) {
|
||||
@@ -696,11 +723,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
}
|
||||
@trigger_error($message, E_USER_DEPRECATED);
|
||||
|
||||
return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset());
|
||||
return '' === $ret ? '' : new Markup($ret, $this->env->getCharset());
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Template', 'Twig\Template', false);
|
||||
class_alias('Twig\Template', 'Twig_Template');
|
||||
|
Reference in New Issue
Block a user