From 5312086b2d02b7cbb49d2ea05b18417d7c267ddd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2019 18:11:16 +0200 Subject: [PATCH] deprecated passing a 4th and 5th arguments to the Sandbox exception classes --- CHANGELOG | 1 + src/Sandbox/SecurityNotAllowedFilterError.php | 8 ++++++++ src/Sandbox/SecurityNotAllowedFunctionError.php | 8 ++++++++ src/Sandbox/SecurityNotAllowedMethodError.php | 8 ++++++++ src/Sandbox/SecurityNotAllowedPropertyError.php | 8 ++++++++ src/Sandbox/SecurityNotAllowedTagError.php | 8 ++++++++ 6 files changed, 41 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 14d289760..a5752c590 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 2.8.1 (2019-XX-XX) + * deprecated passing a 4th and 5th arguments to the Sandbox exception classes * deprecated Node::setTemplateName() in favor of Node::setSourceContext() * 2.8.0 (2019-04-16) diff --git a/src/Sandbox/SecurityNotAllowedFilterError.php b/src/Sandbox/SecurityNotAllowedFilterError.php index 428e702dd..cfebec632 100644 --- a/src/Sandbox/SecurityNotAllowedFilterError.php +++ b/src/Sandbox/SecurityNotAllowedFilterError.php @@ -15,6 +15,8 @@ namespace Twig\Sandbox; * Exception thrown when a not allowed filter is used in a template. * * @author Martin Hasoň + * + * @final */ class SecurityNotAllowedFilterError extends SecurityError { @@ -22,6 +24,12 @@ class SecurityNotAllowedFilterError extends SecurityError public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) { + 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; } diff --git a/src/Sandbox/SecurityNotAllowedFunctionError.php b/src/Sandbox/SecurityNotAllowedFunctionError.php index 0d0d711b0..0b533ce85 100644 --- a/src/Sandbox/SecurityNotAllowedFunctionError.php +++ b/src/Sandbox/SecurityNotAllowedFunctionError.php @@ -15,6 +15,8 @@ namespace Twig\Sandbox; * Exception thrown when a not allowed function is used in a template. * * @author Martin Hasoň + * + * @final */ class SecurityNotAllowedFunctionError extends SecurityError { @@ -22,6 +24,12 @@ class SecurityNotAllowedFunctionError extends SecurityError public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null) { + 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; } diff --git a/src/Sandbox/SecurityNotAllowedMethodError.php b/src/Sandbox/SecurityNotAllowedMethodError.php index d63e1a293..a5197fca1 100644 --- a/src/Sandbox/SecurityNotAllowedMethodError.php +++ b/src/Sandbox/SecurityNotAllowedMethodError.php @@ -15,6 +15,8 @@ namespace Twig\Sandbox; * Exception thrown when a not allowed class method is used in a template. * * @author Kit Burton-Senior + * + * @final */ class SecurityNotAllowedMethodError extends SecurityError { @@ -23,6 +25,12 @@ class SecurityNotAllowedMethodError extends SecurityError public function __construct(string $message, string $className, string $methodName, int $lineno = -1, string $filename = null, \Exception $previous = null) { + 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->methodName = $methodName; diff --git a/src/Sandbox/SecurityNotAllowedPropertyError.php b/src/Sandbox/SecurityNotAllowedPropertyError.php index 532b625bd..d91f4f683 100644 --- a/src/Sandbox/SecurityNotAllowedPropertyError.php +++ b/src/Sandbox/SecurityNotAllowedPropertyError.php @@ -15,6 +15,8 @@ namespace Twig\Sandbox; * Exception thrown when a not allowed class property is used in a template. * * @author Kit Burton-Senior + * + * @final */ class SecurityNotAllowedPropertyError extends SecurityError { @@ -23,6 +25,12 @@ class SecurityNotAllowedPropertyError extends SecurityError public function __construct(string $message, string $className, string $propertyName, int $lineno = -1, string $filename = null, \Exception $previous = null) { + 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->propertyName = $propertyName; diff --git a/src/Sandbox/SecurityNotAllowedTagError.php b/src/Sandbox/SecurityNotAllowedTagError.php index 806221750..10a81728c 100644 --- a/src/Sandbox/SecurityNotAllowedTagError.php +++ b/src/Sandbox/SecurityNotAllowedTagError.php @@ -15,6 +15,8 @@ namespace Twig\Sandbox; * Exception thrown when a not allowed tag is used in a template. * * @author Martin Hasoň + * + * @final */ class SecurityNotAllowedTagError extends SecurityError { @@ -22,6 +24,12 @@ class SecurityNotAllowedTagError extends SecurityError public function __construct(string $message, string $tagName, int $lineno = -1, string $filename = null, \Exception $previous = null) { + 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; }