From d2c864da50b57e1fdd4146efe3d795b1d7f113ba Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Aug 2013 18:29:45 +0200 Subject: [PATCH] removed deprecated Twig_Function_* classes --- lib/Twig/Function.php | 41 ++++++++++------ lib/Twig/Function/Function.php | 38 --------------- lib/Twig/Function/Method.php | 40 --------------- lib/Twig/Function/Node.php | 39 --------------- lib/Twig/FunctionCallableInterface.php | 23 --------- lib/Twig/FunctionInterface.php | 39 --------------- lib/Twig/SimpleFunction.php | 67 +------------------------- 7 files changed, 28 insertions(+), 259 deletions(-) delete mode 100644 lib/Twig/Function/Function.php delete mode 100644 lib/Twig/Function/Method.php delete mode 100644 lib/Twig/Function/Node.php delete mode 100644 lib/Twig/FunctionCallableInterface.php delete mode 100644 lib/Twig/FunctionInterface.php diff --git a/lib/Twig/Function.php b/lib/Twig/Function.php index b5ffb2b04..333a23bde 100644 --- a/lib/Twig/Function.php +++ b/lib/Twig/Function.php @@ -3,7 +3,7 @@ /* * This file is part of Twig. * - * (c) 2010 Fabien Potencier + * (c) 2010-2012 Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,25 +12,43 @@ /** * Represents a template function. * - * Use Twig_SimpleFunction instead. - * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) */ -abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface +class Twig_Function { + protected $name; + protected $callable; protected $options; protected $arguments = array(); - public function __construct(array $options = array()) + public function __construct($name, $callable, array $options = array()) { + $this->name = $name; + $this->callable = $callable; $this->options = array_merge(array( 'needs_environment' => false, 'needs_context' => false, - 'callable' => null, + 'is_safe' => null, + 'is_safe_callback' => null, + 'node_class' => 'Twig_Node_Expression_Function', ), $options); } + public function getName() + { + return $this->name; + } + + public function getCallable() + { + return $this->callable; + } + + public function getNodeClass() + { + return $this->options['node_class']; + } + public function setArguments($arguments) { $this->arguments = $arguments; @@ -53,19 +71,14 @@ abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCal public function getSafe(Twig_Node $functionArgs) { - if (isset($this->options['is_safe'])) { + if (null !== $this->options['is_safe']) { return $this->options['is_safe']; } - if (isset($this->options['is_safe_callback'])) { + if (null !== $this->options['is_safe_callback']) { return call_user_func($this->options['is_safe_callback'], $functionArgs); } return array(); } - - public function getCallable() - { - return $this->options['callable']; - } } diff --git a/lib/Twig/Function/Function.php b/lib/Twig/Function/Function.php deleted file mode 100644 index d1e1b96a2..000000000 --- a/lib/Twig/Function/Function.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Function extends Twig_Function -{ - protected $function; - - public function __construct($function, array $options = array()) - { - $options['callable'] = $function; - - parent::__construct($options); - - $this->function = $function; - } - - public function compile() - { - return $this->function; - } -} diff --git a/lib/Twig/Function/Method.php b/lib/Twig/Function/Method.php deleted file mode 100644 index 67039a956..000000000 --- a/lib/Twig/Function/Method.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Method extends Twig_Function -{ - protected $extension; - protected $method; - - public function __construct(Twig_ExtensionInterface $extension, $method, array $options = array()) - { - $options['callable'] = array($extension, $method); - - parent::__construct($options); - - $this->extension = $extension; - $this->method = $method; - } - - public function compile() - { - return sprintf('$this->env->getExtension(\'%s\')->%s', $this->extension->getName(), $this->method); - } -} diff --git a/lib/Twig/Function/Node.php b/lib/Twig/Function/Node.php deleted file mode 100644 index 06a0d0dbe..000000000 --- a/lib/Twig/Function/Node.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @deprecated since 1.12 (to be removed in 2.0) - */ -class Twig_Function_Node extends Twig_Function -{ - protected $class; - - public function __construct($class, array $options = array()) - { - parent::__construct($options); - - $this->class = $class; - } - - public function getClass() - { - return $this->class; - } - - public function compile() - { - } -} diff --git a/lib/Twig/FunctionCallableInterface.php b/lib/Twig/FunctionCallableInterface.php deleted file mode 100644 index 0aab4f5ec..000000000 --- a/lib/Twig/FunctionCallableInterface.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionCallableInterface -{ - public function getCallable(); -} diff --git a/lib/Twig/FunctionInterface.php b/lib/Twig/FunctionInterface.php deleted file mode 100644 index 67f4f89c0..000000000 --- a/lib/Twig/FunctionInterface.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @deprecated since 1.12 (to be removed in 2.0) - */ -interface Twig_FunctionInterface -{ - /** - * Compiles a function. - * - * @return string The PHP code for the function - */ - public function compile(); - - public function needsEnvironment(); - - public function needsContext(); - - public function getSafe(Twig_Node $filterArgs); - - public function setArguments($arguments); - - public function getArguments(); -} diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index 8ef6aca2f..98d6234f0 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -14,71 +14,6 @@ * * @author Fabien Potencier */ -class Twig_SimpleFunction +class Twig_SimpleFunction extends Twig_Function { - protected $name; - protected $callable; - protected $options; - protected $arguments = array(); - - public function __construct($name, $callable, array $options = array()) - { - $this->name = $name; - $this->callable = $callable; - $this->options = array_merge(array( - 'needs_environment' => false, - 'needs_context' => false, - 'is_safe' => null, - 'is_safe_callback' => null, - 'node_class' => 'Twig_Node_Expression_Function', - ), $options); - } - - public function getName() - { - return $this->name; - } - - public function getCallable() - { - return $this->callable; - } - - public function getNodeClass() - { - return $this->options['node_class']; - } - - public function setArguments($arguments) - { - $this->arguments = $arguments; - } - - public function getArguments() - { - return $this->arguments; - } - - public function needsEnvironment() - { - return $this->options['needs_environment']; - } - - public function needsContext() - { - return $this->options['needs_context']; - } - - public function getSafe(Twig_Node $functionArgs) - { - if (null !== $this->options['is_safe']) { - return $this->options['is_safe']; - } - - if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); - } - - return array(); - } }