removed obsolete Error features

This commit is contained in:
Fabien Potencier
2019-04-23 17:05:32 +02:00
parent 8613aad80c
commit c4178fd235
6 changed files with 16 additions and 64 deletions
+6 -9
View File
@@ -56,20 +56,17 @@ class Error extends \Exception
* *
* By default, automatic guessing is enabled. * By default, automatic guessing is enabled.
* *
* @param string $message The error message * @param string $message The error message
* @param int $lineno The template line where the error occurred * @param int $lineno The template line where the error occurred
* @param Source|string|null $source The source context where the error occurred * @param Source|null $source The source context where the error occurred
* @param \Exception $previous The previous exception * @param \Exception $previous The previous exception
*/ */
public function __construct(string $message, int $lineno = -1, $source = null, \Exception $previous = null) public function __construct(string $message, int $lineno = -1, Source $source = null, \Exception $previous = null)
{ {
parent::__construct('', 0, $previous); parent::__construct('', 0, $previous);
if (null === $source) { if (null === $source) {
$name = null; $name = null;
} elseif (!$source instanceof Source && !$source instanceof \Twig_Source) {
@trigger_error(sprintf('Passing a string as a source to %s is deprecated since Twig 2.6.1; pass a Twig\Source instance instead.', __CLASS__), E_USER_DEPRECATED);
$name = $source;
} else { } else {
$name = $source->getName(); $name = $source->getName();
$this->sourceCode = $source->getCode(); $this->sourceCode = $source->getCode();
@@ -204,7 +201,7 @@ class Error extends \Exception
$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) { foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { if (isset($trace['object']) && $trace['object'] instanceof Template) {
$currentClass = \get_class($trace['object']); $currentClass = \get_class($trace['object']);
$isEmbedContainer = 0 === strpos($templateClass, $currentClass); $isEmbedContainer = 0 === strpos($templateClass, $currentClass);
if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) { if (null === $this->name || ($this->name == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
+2 -11
View File
@@ -22,18 +22,9 @@ class SecurityNotAllowedFilterError extends SecurityError
{ {
private $filterName; private $filterName;
public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) public function __construct(string $message, string $functionName)
{ {
if (-1 !== $lineno) { parent::__construct($message);
@trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $filename) {
@trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $previous) {
@trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
parent::__construct($message, $lineno, $filename, $previous);
$this->filterName = $functionName; $this->filterName = $functionName;
} }
@@ -22,18 +22,9 @@ class SecurityNotAllowedFunctionError extends SecurityError
{ {
private $functionName; private $functionName;
public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) public function __construct(string $message, string $functionName)
{ {
if (-1 !== $lineno) { parent::__construct($message);
@trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $filename) {
@trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $previous) {
@trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
parent::__construct($message, $lineno, $filename, $previous);
$this->functionName = $functionName; $this->functionName = $functionName;
} }
+2 -11
View File
@@ -23,18 +23,9 @@ class SecurityNotAllowedMethodError extends SecurityError
private $className; private $className;
private $methodName; private $methodName;
public function __construct(string $message, string $className, string $methodName, int $lineno = -1, string $filename = null, \Exception $previous = null) public function __construct(string $message, string $className, string $methodName)
{ {
if (-1 !== $lineno) { parent::__construct($message);
@trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $filename) {
@trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $previous) {
@trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
parent::__construct($message, $lineno, $filename, $previous);
$this->className = $className; $this->className = $className;
$this->methodName = $methodName; $this->methodName = $methodName;
} }
@@ -23,18 +23,9 @@ class SecurityNotAllowedPropertyError extends SecurityError
private $className; private $className;
private $propertyName; private $propertyName;
public function __construct(string $message, string $className, string $propertyName, int $lineno = -1, string $filename = null, \Exception $previous = null) public function __construct(string $message, string $className, string $propertyName)
{ {
if (-1 !== $lineno) { parent::__construct($message);
@trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $filename) {
@trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $previous) {
@trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
parent::__construct($message, $lineno, $filename, $previous);
$this->className = $className; $this->className = $className;
$this->propertyName = $propertyName; $this->propertyName = $propertyName;
} }
+2 -11
View File
@@ -22,18 +22,9 @@ class SecurityNotAllowedTagError extends SecurityError
{ {
private $tagName; private $tagName;
public function __construct(string $message, string $tagName, int $lineno = -1, string $filename = null, \Exception $previous = null) public function __construct(string $message, string $tagName)
{ {
if (-1 !== $lineno) { parent::__construct($message);
@trigger_error(sprintf('Passing $lineno as a 3th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $filename) {
@trigger_error(sprintf('Passing $filename as a 4th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
if (null !== $previous) {
@trigger_error(sprintf('Passing $previous as a 5th argument of the %s constructor is deprecated since Twig 2.8.1.', __CLASS__), E_USER_DEPRECATED);
}
parent::__construct($message, $lineno, $filename, $previous);
$this->tagName = $tagName; $this->tagName = $tagName;
} }