removed deprecated Twig_Filter_* classes

This commit is contained in:
Fabien Potencier
2013-08-05 18:27:53 +02:00
parent f9195a2dc1
commit 4aef0c2fb4
7 changed files with 28 additions and 270 deletions
+27 -14
View File
@@ -3,7 +3,7 @@
/* /*
* This file is part of Twig. * This file is part of Twig.
* *
* (c) 2009 Fabien Potencier * (c) 2009-2012 Fabien Potencier
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
@@ -12,27 +12,45 @@
/** /**
* Represents a template filter. * Represents a template filter.
* *
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/ */
abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableInterface class Twig_Filter
{ {
protected $name;
protected $callable;
protected $options; protected $options;
protected $arguments = array(); 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( $this->options = array_merge(array(
'needs_environment' => false, 'needs_environment' => false,
'needs_context' => false, 'needs_context' => false,
'is_safe' => null,
'is_safe_callback' => null,
'pre_escape' => null, 'pre_escape' => null,
'preserves_safety' => null, 'preserves_safety' => null,
'callable' => null, 'node_class' => 'Twig_Node_Expression_Filter',
), $options); ), $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) public function setArguments($arguments)
{ {
$this->arguments = $arguments; $this->arguments = $arguments;
@@ -55,11 +73,11 @@ abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableI
public function getSafe(Twig_Node $filterArgs) public function getSafe(Twig_Node $filterArgs)
{ {
if (isset($this->options['is_safe'])) { if (null !== $this->options['is_safe']) {
return $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'], $filterArgs); return call_user_func($this->options['is_safe_callback'], $filterArgs);
} }
} }
@@ -73,9 +91,4 @@ abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableI
{ {
return $this->options['pre_escape']; return $this->options['pre_escape'];
} }
public function getCallable()
{
return $this->options['callable'];
}
} }
-37
View File
@@ -1,37 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a function template filter.
*
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/
class Twig_Filter_Function extends Twig_Filter
{
protected $function;
public function __construct($function, array $options = array())
{
$options['callable'] = $function;
parent::__construct($options);
$this->function = $function;
}
public function compile()
{
return $this->function;
}
}
-39
View File
@@ -1,39 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a method template filter.
*
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/
class Twig_Filter_Method extends Twig_Filter
{
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);
}
}
-39
View File
@@ -1,39 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2011 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a template filter as a node.
*
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/
class Twig_Filter_Node extends Twig_Filter
{
protected $class;
public function __construct($class, array $options = array())
{
parent::__construct($options);
$this->class = $class;
}
public function getClass()
{
return $this->class;
}
public function compile()
{
}
}
-23
View File
@@ -1,23 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2012 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a callable template filter.
*
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/
interface Twig_FilterCallableInterface
{
public function getCallable();
}
-42
View File
@@ -1,42 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2010 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a template filter.
*
* Use Twig_SimpleFilter instead.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since 1.12 (to be removed in 2.0)
*/
interface Twig_FilterInterface
{
/**
* Compiles a filter.
*
* @return string The PHP code for the filter
*/
public function compile();
public function needsEnvironment();
public function needsContext();
public function getSafe(Twig_Node $filterArgs);
public function getPreservesSafety();
public function getPreEscape();
public function setArguments($arguments);
public function getArguments();
}
+1 -76
View File
@@ -14,81 +14,6 @@
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class Twig_SimpleFilter class Twig_SimpleFilter extends Twig_Filter
{ {
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,
'pre_escape' => null,
'preserves_safety' => null,
'node_class' => 'Twig_Node_Expression_Filter',
), $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 $filterArgs)
{
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'], $filterArgs);
}
}
public function getPreservesSafety()
{
return $this->options['preserves_safety'];
}
public function getPreEscape()
{
return $this->options['pre_escape'];
}
} }