mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
moved some more classes to namespaced ones
This commit is contained in:
+36
-36
@@ -123,23 +123,23 @@ Filters
|
||||
Creating a filter is as simple as associating a name with a PHP callable::
|
||||
|
||||
// an anonymous function
|
||||
$filter = new Twig_Filter('rot13', function ($string) {
|
||||
$filter = new \Twig\TwigFilter('rot13', function ($string) {
|
||||
return str_rot13($string);
|
||||
});
|
||||
|
||||
// or a simple PHP function
|
||||
$filter = new Twig_Filter('rot13', 'str_rot13');
|
||||
$filter = new \Twig\TwigFilter('rot13', 'str_rot13');
|
||||
|
||||
// or a class static method
|
||||
$filter = new Twig_Filter('rot13', ['SomeClass', 'rot13Filter']);
|
||||
$filter = new Twig_Filter('rot13', 'SomeClass::rot13Filter');
|
||||
$filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']);
|
||||
$filter = new \Twig\TwigFilter('rot13', 'SomeClass::rot13Filter');
|
||||
|
||||
// or a class method
|
||||
$filter = new Twig_Filter('rot13', [$this, 'rot13Filter']);
|
||||
$filter = new \Twig\TwigFilter('rot13', [$this, 'rot13Filter']);
|
||||
// the one below needs a runtime implementation (see below for more information)
|
||||
$filter = new Twig_Filter('rot13', ['SomeClass', 'rot13Filter']);
|
||||
$filter = new \Twig\TwigFilter('rot13', ['SomeClass', 'rot13Filter']);
|
||||
|
||||
The first argument passed to the ``Twig_Filter`` constructor is the name of the
|
||||
The first argument passed to the ``\Twig\TwigFilter`` constructor is the name of the
|
||||
filter you will use in templates and the second one is the PHP callable to
|
||||
associate with it.
|
||||
|
||||
@@ -172,9 +172,9 @@ is compiled to something like the following::
|
||||
<?php echo strtolower('TWIG') ?>
|
||||
<?php echo twig_date_format_filter($now, 'd/m/Y') ?>
|
||||
|
||||
The ``Twig_Filter`` class takes an array of options as its last argument::
|
||||
The ``\Twig\TwigFilter`` class takes an array of options as its last argument::
|
||||
|
||||
$filter = new Twig_Filter('rot13', 'str_rot13', $options);
|
||||
$filter = new \Twig\TwigFilter('rot13', 'str_rot13', $options);
|
||||
|
||||
Environment-aware Filters
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -183,7 +183,7 @@ If you want to access the current environment instance in your filter, set the
|
||||
``needs_environment`` option to ``true``; Twig will pass the current
|
||||
environment as the first argument to the filter call::
|
||||
|
||||
$filter = new Twig_Filter('rot13', function (Twig_Environment $env, $string) {
|
||||
$filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $string) {
|
||||
// get the current charset for instance
|
||||
$charset = $env->getCharset();
|
||||
|
||||
@@ -198,11 +198,11 @@ If you want to access the current context in your filter, set the
|
||||
the first argument to the filter call (or the second one if
|
||||
``needs_environment`` is also set to ``true``)::
|
||||
|
||||
$filter = new Twig_Filter('rot13', function ($context, $string) {
|
||||
$filter = new \Twig\TwigFilter('rot13', function ($context, $string) {
|
||||
// ...
|
||||
}, ['needs_context' => true]);
|
||||
|
||||
$filter = new Twig_Filter('rot13', function (Twig_Environment $env, $context, $string) {
|
||||
$filter = new \Twig\TwigFilter('rot13', function (Twig_Environment $env, $context, $string) {
|
||||
// ...
|
||||
}, ['needs_context' => true, 'needs_environment' => true]);
|
||||
|
||||
@@ -214,14 +214,14 @@ before printing. If your filter acts as an escaper (or explicitly outputs HTML
|
||||
or JavaScript code), you will want the raw output to be printed. In such a
|
||||
case, set the ``is_safe`` option::
|
||||
|
||||
$filter = new Twig_Filter('nl2br', 'nl2br', ['is_safe' => ['html']]);
|
||||
$filter = new \Twig\TwigFilter('nl2br', 'nl2br', ['is_safe' => ['html']]);
|
||||
|
||||
Some filters may need to work on input that is already escaped or safe, for
|
||||
example when adding (safe) HTML tags to originally unsafe output. In such a
|
||||
case, set the ``pre_escape`` option to escape the input data before it is run
|
||||
through your filter::
|
||||
|
||||
$filter = new Twig_Filter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]);
|
||||
$filter = new \Twig\TwigFilter('somefilter', 'somefilter', ['pre_escape' => 'html', 'is_safe' => ['html']]);
|
||||
|
||||
Variadic Filters
|
||||
~~~~~~~~~~~~~~~~
|
||||
@@ -230,7 +230,7 @@ When a filter should accept an arbitrary number of arguments, set the
|
||||
``is_variadic`` option to ``true``; Twig will pass the extra arguments as the
|
||||
last argument to the filter call as an array::
|
||||
|
||||
$filter = new Twig_Filter('thumbnail', function ($file, array $options = []) {
|
||||
$filter = new \Twig\TwigFilter('thumbnail', function ($file, array $options = []) {
|
||||
// ...
|
||||
}, ['is_variadic' => true]);
|
||||
|
||||
@@ -244,7 +244,7 @@ Dynamic Filters
|
||||
A filter name containing the special ``*`` character is a dynamic filter as
|
||||
the ``*`` can be any string::
|
||||
|
||||
$filter = new Twig_Filter('*_path', function ($name, $arguments) {
|
||||
$filter = new \Twig\TwigFilter('*_path', function ($name, $arguments) {
|
||||
// ...
|
||||
});
|
||||
|
||||
@@ -255,7 +255,7 @@ The following filters will be matched by the above defined dynamic filter:
|
||||
|
||||
A dynamic filter can define more than one dynamic parts::
|
||||
|
||||
$filter = new Twig_Filter('*_path_*', function ($name, $suffix, $arguments) {
|
||||
$filter = new \Twig\TwigFilter('*_path_*', function ($name, $suffix, $arguments) {
|
||||
// ...
|
||||
});
|
||||
|
||||
@@ -271,7 +271,7 @@ You can mark a filter as being deprecated by setting the ``deprecated`` option
|
||||
to ``true``. You can also give an alternative filter that replaces the
|
||||
deprecated one when that makes sense::
|
||||
|
||||
$filter = new Twig_Filter('obsolete', function () {
|
||||
$filter = new \Twig\TwigFilter('obsolete', function () {
|
||||
// ...
|
||||
}, ['deprecated' => true, 'alternative' => 'new_one']);
|
||||
|
||||
@@ -282,10 +282,10 @@ Functions
|
||||
---------
|
||||
|
||||
Functions are defined in the exact same way as filters, but you need to create
|
||||
an instance of ``Twig_Function``::
|
||||
an instance of ``\Twig\TwigFunction``::
|
||||
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$function = new Twig_Function('function_name', function () {
|
||||
$function = new \Twig\TwigFunction('function_name', function () {
|
||||
// ...
|
||||
});
|
||||
$twig->addFunction($function);
|
||||
@@ -297,10 +297,10 @@ Tests
|
||||
-----
|
||||
|
||||
Tests are defined in the exact same way as filters and functions, but you need
|
||||
to create an instance of ``Twig_Test``::
|
||||
to create an instance of ``\Twig\TwigTest``::
|
||||
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$test = new Twig_Test('test_name', function () {
|
||||
$test = new \Twig\TwigTest('test_name', function () {
|
||||
// ...
|
||||
});
|
||||
$twig->addTest($test);
|
||||
@@ -310,7 +310,7 @@ boolean conditions. As a simple example, let's create a Twig test that checks if
|
||||
objects are 'red'::
|
||||
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$test = new Twig_Test('red', function ($value) {
|
||||
$test = new \Twig\TwigTest('red', function ($value) {
|
||||
if (isset($value->color) && $value->color == 'red') {
|
||||
return true;
|
||||
}
|
||||
@@ -328,10 +328,10 @@ compilation. This is useful if your test can be compiled into PHP primitives.
|
||||
This is used by many of the tests built into Twig::
|
||||
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$test = new Twig_Test(
|
||||
$test = new \Twig\TwigTest(
|
||||
'odd',
|
||||
null,
|
||||
['node_class' => 'Twig_Node_Expression_Test_Odd']);
|
||||
['node_class' => '\Twig\Node\Expression\Test\OddTest']);
|
||||
$twig->addTest($test);
|
||||
|
||||
class Twig_Node_Expression_Test_Odd extends \Twig\Node\Expression\TestExpression
|
||||
@@ -557,21 +557,21 @@ An extension is a class that implements the following interface::
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return Twig_Filter[]
|
||||
* @return \Twig\TwigFilter[]
|
||||
*/
|
||||
public function getFilters();
|
||||
|
||||
/**
|
||||
* Returns a list of tests to add to the existing list.
|
||||
*
|
||||
* @return Twig_Test[]
|
||||
* @return \Twig\TwigTest[]
|
||||
*/
|
||||
public function getTests();
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return Twig_Function[]
|
||||
* @return \Twig\TwigFunction[]
|
||||
*/
|
||||
public function getFunctions();
|
||||
|
||||
@@ -636,7 +636,7 @@ method::
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('lipsum', 'generate_lipsum'),
|
||||
new \Twig\TwigFunction('lipsum', 'generate_lipsum'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ environment::
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new Twig_Filter('rot13', 'str_rot13'),
|
||||
new \Twig\TwigFilter('rot13', 'str_rot13'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -717,7 +717,7 @@ The ``getTests()`` method lets you add new test functions::
|
||||
public function getTests()
|
||||
{
|
||||
return [
|
||||
new Twig_Test('even', 'twig_test_even'),
|
||||
new \Twig\TwigTest('even', 'twig_test_even'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ The simplest way to use methods is to define them on the extension itself::
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('rot13', [$this, 'rot13']),
|
||||
new \Twig\TwigFunction('rot13', [$this, 'rot13']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -817,9 +817,9 @@ It is now possible to move the runtime logic to a new
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('rot13', ['Project_Twig_RuntimeExtension', 'rot13']),
|
||||
new \Twig\TwigFunction('rot13', ['Project_Twig_RuntimeExtension', 'rot13']),
|
||||
// or
|
||||
new Twig_Function('rot13', 'Project_Twig_RuntimeExtension::rot13'),
|
||||
new \Twig\TwigFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -836,7 +836,7 @@ possible** (order matters)::
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new Twig_Filter('date', [$this, 'dateFilter']),
|
||||
new \Twig\TwigFilter('date', [$this, 'dateFilter']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -855,7 +855,7 @@ If you do the same on the ``\Twig\Environment`` itself, beware that it takes
|
||||
precedence over any other registered extensions::
|
||||
|
||||
$twig = new \Twig\Environment($loader);
|
||||
$twig->addFilter(new Twig_Filter('date', function ($timestamp, $format = 'F j, Y H:i') {
|
||||
$twig->addFilter(new \Twig\TwigFilter('date', function ($timestamp, $format = 'F j, Y H:i') {
|
||||
// do something different from the built-in date filter
|
||||
}));
|
||||
// the date filter will come from the above registration, not
|
||||
|
||||
+1
-1
@@ -277,7 +277,7 @@ For functions, use ``registerUndefinedFunctionCallback()``::
|
||||
// don't try this at home as it's not secure at all!
|
||||
$twig->registerUndefinedFunctionCallback(function ($name) {
|
||||
if (function_exists($name)) {
|
||||
return new Twig_Function($name, $name);
|
||||
return new \Twig\TwigFunction($name, $name);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -742,7 +742,7 @@ class Twig_Environment
|
||||
return $this->extensionSet->getNodeVisitors();
|
||||
}
|
||||
|
||||
public function addFilter(Twig_Filter $filter)
|
||||
public function addFilter(\Twig\TwigFilter $filter)
|
||||
{
|
||||
$this->extensionSet->addFilter($filter);
|
||||
}
|
||||
@@ -755,7 +755,7 @@ class Twig_Environment
|
||||
*
|
||||
* @param string $name The filter name
|
||||
*
|
||||
* @return Twig_Filter|false A Twig_Filter instance or false if the filter does not exist
|
||||
* @return \Twig\TwigFilter|false A Twig_Filter instance or false if the filter does not exist
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -774,7 +774,7 @@ class Twig_Environment
|
||||
*
|
||||
* Be warned that this method cannot return filters defined with registerUndefinedFilterCallback.
|
||||
*
|
||||
* @return Twig_Filter[]
|
||||
* @return \Twig\TwigFilter[]
|
||||
*
|
||||
* @see registerUndefinedFilterCallback
|
||||
*
|
||||
@@ -785,7 +785,7 @@ class Twig_Environment
|
||||
return $this->extensionSet->getFilters();
|
||||
}
|
||||
|
||||
public function addTest(Twig_Test $test)
|
||||
public function addTest(\Twig\TwigTest $test)
|
||||
{
|
||||
$this->extensionSet->addTest($test);
|
||||
}
|
||||
@@ -793,7 +793,7 @@ class Twig_Environment
|
||||
/**
|
||||
* Gets the registered Tests.
|
||||
*
|
||||
* @return Twig_Test[]
|
||||
* @return \Twig\TwigTest[]
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -807,7 +807,7 @@ class Twig_Environment
|
||||
*
|
||||
* @param string $name The test name
|
||||
*
|
||||
* @return Twig_Test|false A Twig_Test instance or false if the test does not exist
|
||||
* @return \Twig\TwigTest|false A Twig_Test instance or false if the test does not exist
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -816,7 +816,7 @@ class Twig_Environment
|
||||
return $this->extensionSet->getTest($name);
|
||||
}
|
||||
|
||||
public function addFunction(Twig_Function $function)
|
||||
public function addFunction(\Twig\TwigFunction $function)
|
||||
{
|
||||
$this->extensionSet->addFunction($function);
|
||||
}
|
||||
@@ -829,7 +829,7 @@ class Twig_Environment
|
||||
*
|
||||
* @param string $name function name
|
||||
*
|
||||
* @return Twig_Function|false A Twig_Function instance or false if the function does not exist
|
||||
* @return \Twig\TwigFunction|false A Twig_Function instance or false if the function does not exist
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -848,7 +848,7 @@ class Twig_Environment
|
||||
*
|
||||
* Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.
|
||||
*
|
||||
* @return Twig_Function[]
|
||||
* @return \Twig\TwigFunction[]
|
||||
*
|
||||
* @see registerUndefinedFunctionCallback
|
||||
*
|
||||
|
||||
+50
-50
@@ -137,80 +137,80 @@ final class Twig_Extension_Core extends \Twig\Extension\AbstractExtension
|
||||
{
|
||||
return [
|
||||
// formatting filters
|
||||
new Twig_Filter('date', 'twig_date_format_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('format', 'sprintf'),
|
||||
new Twig_Filter('replace', 'twig_replace_filter'),
|
||||
new Twig_Filter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('abs', 'abs'),
|
||||
new Twig_Filter('round', 'twig_round'),
|
||||
new \Twig\TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('format', 'sprintf'),
|
||||
new \Twig\TwigFilter('replace', 'twig_replace_filter'),
|
||||
new \Twig\TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('abs', 'abs'),
|
||||
new \Twig\TwigFilter('round', 'twig_round'),
|
||||
|
||||
// encoding
|
||||
new Twig_Filter('url_encode', 'twig_urlencode_filter'),
|
||||
new Twig_Filter('json_encode', 'json_encode'),
|
||||
new Twig_Filter('convert_encoding', 'twig_convert_encoding'),
|
||||
new \Twig\TwigFilter('url_encode', 'twig_urlencode_filter'),
|
||||
new \Twig\TwigFilter('json_encode', 'json_encode'),
|
||||
new \Twig\TwigFilter('convert_encoding', 'twig_convert_encoding'),
|
||||
|
||||
// string filters
|
||||
new Twig_Filter('title', 'twig_title_string_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('upper', 'twig_upper_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('lower', 'twig_lower_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('striptags', 'strip_tags'),
|
||||
new Twig_Filter('trim', 'twig_trim_filter'),
|
||||
new Twig_Filter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new \Twig\TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('striptags', 'strip_tags'),
|
||||
new \Twig\TwigFilter('trim', 'twig_trim_filter'),
|
||||
new \Twig\TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
|
||||
// array helpers
|
||||
new Twig_Filter('join', 'twig_join_filter'),
|
||||
new Twig_Filter('split', 'twig_split_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('sort', 'twig_sort_filter'),
|
||||
new Twig_Filter('merge', 'twig_array_merge'),
|
||||
new Twig_Filter('batch', 'twig_array_batch'),
|
||||
new \Twig\TwigFilter('join', 'twig_join_filter'),
|
||||
new \Twig\TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('sort', 'twig_sort_filter'),
|
||||
new \Twig\TwigFilter('merge', 'twig_array_merge'),
|
||||
new \Twig\TwigFilter('batch', 'twig_array_batch'),
|
||||
|
||||
// string/array filters
|
||||
new Twig_Filter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('length', 'twig_length_filter', ['needs_environment' => true]),
|
||||
new Twig_Filter('slice', 'twig_slice', ['needs_environment' => true]),
|
||||
new Twig_Filter('first', 'twig_first', ['needs_environment' => true]),
|
||||
new Twig_Filter('last', 'twig_last', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('slice', 'twig_slice', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('first', 'twig_first', ['needs_environment' => true]),
|
||||
new \Twig\TwigFilter('last', 'twig_last', ['needs_environment' => true]),
|
||||
|
||||
// iteration and runtime
|
||||
new Twig_Filter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']),
|
||||
new Twig_Filter('keys', 'twig_get_array_keys_filter'),
|
||||
new \Twig\TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']),
|
||||
new \Twig\TwigFilter('keys', 'twig_get_array_keys_filter'),
|
||||
|
||||
// escaping
|
||||
new Twig_Filter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
||||
new Twig_Filter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
||||
new \Twig\TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
||||
new \Twig\TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('max', 'max'),
|
||||
new Twig_Function('min', 'min'),
|
||||
new Twig_Function('range', 'range'),
|
||||
new Twig_Function('constant', 'twig_constant'),
|
||||
new Twig_Function('cycle', 'twig_cycle'),
|
||||
new Twig_Function('random', 'twig_random', ['needs_environment' => true]),
|
||||
new Twig_Function('date', 'twig_date_converter', ['needs_environment' => true]),
|
||||
new Twig_Function('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
|
||||
new Twig_Function('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
|
||||
new \Twig\TwigFunction('max', 'max'),
|
||||
new \Twig\TwigFunction('min', 'min'),
|
||||
new \Twig\TwigFunction('range', 'range'),
|
||||
new \Twig\TwigFunction('constant', 'twig_constant'),
|
||||
new \Twig\TwigFunction('cycle', 'twig_cycle'),
|
||||
new \Twig\TwigFunction('random', 'twig_random', ['needs_environment' => true]),
|
||||
new \Twig\TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]),
|
||||
new \Twig\TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]),
|
||||
new \Twig\TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return [
|
||||
new Twig_Test('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']),
|
||||
new Twig_Test('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']),
|
||||
new Twig_Test('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']),
|
||||
new Twig_Test('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']),
|
||||
new Twig_Test('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
||||
new Twig_Test('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
||||
new Twig_Test('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']),
|
||||
new Twig_Test('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']),
|
||||
new Twig_Test('empty', 'twig_test_empty'),
|
||||
new Twig_Test('iterable', 'twig_test_iterable'),
|
||||
new \Twig\TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']),
|
||||
new \Twig\TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']),
|
||||
new \Twig\TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']),
|
||||
new \Twig\TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']),
|
||||
new \Twig\TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
||||
new \Twig\TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']),
|
||||
new \Twig\TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']),
|
||||
new \Twig\TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']),
|
||||
new \Twig\TwigTest('empty', 'twig_test_empty'),
|
||||
new \Twig\TwigTest('iterable', 'twig_test_iterable'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ final class Twig_Extension_Debug extends \Twig\Extension\AbstractExtension
|
||||
;
|
||||
|
||||
return [
|
||||
new Twig_Function('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]),
|
||||
new \Twig\TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ final class Twig_Extension_Escaper extends \Twig\Extension\AbstractExtension
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new Twig_Filter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
|
||||
new \Twig\TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ final class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension
|
||||
private $tokenParsers = [];
|
||||
private $tests = [];
|
||||
|
||||
public function addFunction(Twig_Function $function)
|
||||
public function addFunction(\Twig\TwigFunction $function)
|
||||
{
|
||||
if (isset($this->functions[$function->getName()])) {
|
||||
throw new \LogicException(sprintf('Function "%s" is already registered.', $function->getName()));
|
||||
@@ -38,7 +38,7 @@ final class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension
|
||||
return $this->functions;
|
||||
}
|
||||
|
||||
public function addFilter(Twig_Filter $filter)
|
||||
public function addFilter(\Twig\TwigFilter $filter)
|
||||
{
|
||||
if (isset($this->filters[$filter->getName()])) {
|
||||
throw new \LogicException(sprintf('Filter "%s" is already registered.', $filter->getName()));
|
||||
@@ -76,7 +76,7 @@ final class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension
|
||||
return $this->tokenParsers;
|
||||
}
|
||||
|
||||
public function addTest(Twig_Test $test)
|
||||
public function addTest(\Twig\TwigTest $test)
|
||||
{
|
||||
if (isset($this->tests[$test->getName()])) {
|
||||
throw new \LogicException(sprintf('Test "%s" is already registered.', $test->getTag()));
|
||||
|
||||
@@ -14,7 +14,7 @@ final class Twig_Extension_StringLoader extends \Twig\Extension\AbstractExtensio
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
|
||||
new \Twig\TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,21 +33,21 @@ interface Twig_ExtensionInterface
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return Twig_Filter[]
|
||||
* @return \Twig\TwigFilter[]
|
||||
*/
|
||||
public function getFilters();
|
||||
|
||||
/**
|
||||
* Returns a list of tests to add to the existing list.
|
||||
*
|
||||
* @return Twig_Test[]
|
||||
* @return \Twig\TwigTest[]
|
||||
*/
|
||||
public function getTests();
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return Twig_Function[]
|
||||
* @return \Twig\TwigFunction[]
|
||||
*/
|
||||
public function getFunctions();
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ final class Twig_ExtensionSet
|
||||
$this->extensions[$class] = $extension;
|
||||
}
|
||||
|
||||
public function addFunction(Twig_Function $function)
|
||||
public function addFunction(\Twig\TwigFunction $function)
|
||||
{
|
||||
if ($this->initialized) {
|
||||
throw new \LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $function->getName()));
|
||||
@@ -183,7 +183,7 @@ final class Twig_ExtensionSet
|
||||
*
|
||||
* @param string $name function name
|
||||
*
|
||||
* @return Twig_Function|false A Twig_Function instance or false if the function does not exist
|
||||
* @return \Twig\TwigFunction|false A Twig_Function instance or false if the function does not exist
|
||||
*/
|
||||
public function getFunction($name)
|
||||
{
|
||||
@@ -220,7 +220,7 @@ final class Twig_ExtensionSet
|
||||
$this->functionCallbacks[] = $callable;
|
||||
}
|
||||
|
||||
public function addFilter(Twig_Filter $filter)
|
||||
public function addFilter(\Twig\TwigFilter $filter)
|
||||
{
|
||||
if ($this->initialized) {
|
||||
throw new \LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $filter->getName()));
|
||||
@@ -246,7 +246,7 @@ final class Twig_ExtensionSet
|
||||
*
|
||||
* @param string $name The filter name
|
||||
*
|
||||
* @return Twig_Filter|false A Twig_Filter instance or false if the filter does not exist
|
||||
* @return \Twig\TwigFilter|false A Twig_Filter instance or false if the filter does not exist
|
||||
*/
|
||||
public function getFilter($name)
|
||||
{
|
||||
@@ -346,7 +346,7 @@ final class Twig_ExtensionSet
|
||||
return $globals;
|
||||
}
|
||||
|
||||
public function addTest(Twig_Test $test)
|
||||
public function addTest(\Twig\TwigTest $test)
|
||||
{
|
||||
if ($this->initialized) {
|
||||
throw new \LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $test->getName()));
|
||||
@@ -369,7 +369,7 @@ final class Twig_ExtensionSet
|
||||
*
|
||||
* @param string $name The test name
|
||||
*
|
||||
* @return Twig_Test|false A Twig_Test instance or false if the test does not exist
|
||||
* @return \Twig\TwigTest|false A Twig_Test instance or false if the test does not exist
|
||||
*/
|
||||
public function getTest($name)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class_exists('Twig_Filter');
|
||||
|
||||
if (false) {
|
||||
final class Twig_SimpleFilter extends Twig_Filter
|
||||
final class Twig_SimpleFilter extends \Twig\TwigFilter
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class_exists('Twig_Function');
|
||||
|
||||
if (false) {
|
||||
final class Twig_SimpleFunction extends Twig_Function
|
||||
final class Twig_SimpleFunction extends \Twig\TwigFunction
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class_exists('Twig_Test');
|
||||
|
||||
if (false) {
|
||||
final class Twig_SimpleTest extends Twig_Test
|
||||
final class Twig_SimpleTest extends \Twig\TwigTest
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_Filter[]
|
||||
* @return \Twig\TwigFilter[]
|
||||
*/
|
||||
protected function getTwigFilters()
|
||||
{
|
||||
@@ -49,7 +49,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_Function[]
|
||||
* @return \Twig\TwigFunction[]
|
||||
*/
|
||||
protected function getTwigFunctions()
|
||||
{
|
||||
@@ -57,7 +57,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_Test[]
|
||||
* @return \Twig\TwigTest[]
|
||||
*/
|
||||
protected function getTwigTests()
|
||||
{
|
||||
|
||||
@@ -445,21 +445,21 @@ class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExten
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new Twig_Filter('foo_filter'),
|
||||
new \Twig\TwigFilter('foo_filter'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return [
|
||||
new Twig_Test('foo_test'),
|
||||
new \Twig\TwigTest('foo_test'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('foo_function'),
|
||||
new \Twig\TwigFunction('foo_function'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -529,8 +529,8 @@ class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends \Twig\Extension
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']),
|
||||
new Twig_Function('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'),
|
||||
new \Twig\TwigFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']),
|
||||
new \Twig\TwigFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -136,41 +136,41 @@ class TwigTestExtension extends \Twig\Extension\AbstractExtension
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new Twig_Filter('§', [$this, '§Filter']),
|
||||
new Twig_Filter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]),
|
||||
new Twig_Filter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new Twig_Filter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]),
|
||||
new Twig_Filter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]),
|
||||
new Twig_Filter('static_call_string', 'TwigTestExtension::staticCall'),
|
||||
new Twig_Filter('static_call_array', ['TwigTestExtension', 'staticCall']),
|
||||
new Twig_Filter('magic_call', [$this, 'magicCall']),
|
||||
new Twig_Filter('magic_call_string', 'TwigTestExtension::magicStaticCall'),
|
||||
new Twig_Filter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']),
|
||||
new Twig_Filter('*_path', [$this, 'dynamic_path']),
|
||||
new Twig_Filter('*_foo_*_bar', [$this, 'dynamic_foo']),
|
||||
new Twig_Filter('anon_foo', function ($name) { return '*'.$name.'*'; }),
|
||||
new \Twig\TwigFilter('§', [$this, '§Filter']),
|
||||
new \Twig\TwigFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]),
|
||||
new \Twig\TwigFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
|
||||
new \Twig\TwigFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]),
|
||||
new \Twig\TwigFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]),
|
||||
new \Twig\TwigFilter('static_call_string', 'TwigTestExtension::staticCall'),
|
||||
new \Twig\TwigFilter('static_call_array', ['TwigTestExtension', 'staticCall']),
|
||||
new \Twig\TwigFilter('magic_call', [$this, 'magicCall']),
|
||||
new \Twig\TwigFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'),
|
||||
new \Twig\TwigFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']),
|
||||
new \Twig\TwigFilter('*_path', [$this, 'dynamic_path']),
|
||||
new \Twig\TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']),
|
||||
new \Twig\TwigFilter('anon_foo', function ($name) { return '*'.$name.'*'; }),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_Function('§', [$this, '§Function']),
|
||||
new Twig_Function('safe_br', [$this, 'br'], ['is_safe' => ['html']]),
|
||||
new Twig_Function('unsafe_br', [$this, 'br']),
|
||||
new Twig_Function('static_call_string', 'TwigTestExtension::staticCall'),
|
||||
new Twig_Function('static_call_array', ['TwigTestExtension', 'staticCall']),
|
||||
new Twig_Function('*_path', [$this, 'dynamic_path']),
|
||||
new Twig_Function('*_foo_*_bar', [$this, 'dynamic_foo']),
|
||||
new Twig_Function('anon_foo', function ($name) { return '*'.$name.'*'; }),
|
||||
new \Twig\TwigFunction('§', [$this, '§Function']),
|
||||
new \Twig\TwigFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]),
|
||||
new \Twig\TwigFunction('unsafe_br', [$this, 'br']),
|
||||
new \Twig\TwigFunction('static_call_string', 'TwigTestExtension::staticCall'),
|
||||
new \Twig\TwigFunction('static_call_array', ['TwigTestExtension', 'staticCall']),
|
||||
new \Twig\TwigFunction('*_path', [$this, 'dynamic_path']),
|
||||
new \Twig\TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']),
|
||||
new \Twig\TwigFunction('anon_foo', function ($name) { return '*'.$name.'*'; }),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return [
|
||||
new Twig_Test('multi word', [$this, 'is_multi_word']),
|
||||
new Twig_Test('test_*', [$this, 'dynamic_test']),
|
||||
new \Twig\TwigTest('multi word', [$this, 'is_multi_word']),
|
||||
new \Twig\TwigTest('test_*', [$this, 'dynamic_test']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase
|
||||
public function getTests()
|
||||
{
|
||||
$environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
|
||||
$environment->addFilter(new Twig_Filter('bar', 'twig_tests_filter_dummy', ['needs_environment' => true]));
|
||||
$environment->addFilter(new Twig_Filter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true]));
|
||||
$environment->addFilter(new \Twig\TwigFilter('bar', 'twig_tests_filter_dummy', ['needs_environment' => true]));
|
||||
$environment->addFilter(new \Twig\TwigFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true]));
|
||||
|
||||
$tests = [];
|
||||
|
||||
@@ -136,7 +136,7 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase
|
||||
protected function getEnvironment()
|
||||
{
|
||||
$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
|
||||
$env->addFilter(new Twig_Filter('anonymous', function () {}));
|
||||
$env->addFilter(new \Twig\TwigFilter('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase
|
||||
public function getTests()
|
||||
{
|
||||
$environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
|
||||
$environment->addFunction(new Twig_Function('foo', 'twig_tests_function_dummy', []));
|
||||
$environment->addFunction(new Twig_Function('bar', 'twig_tests_function_dummy', ['needs_environment' => true]));
|
||||
$environment->addFunction(new Twig_Function('foofoo', 'twig_tests_function_dummy', ['needs_context' => true]));
|
||||
$environment->addFunction(new Twig_Function('foobar', 'twig_tests_function_dummy', ['needs_environment' => true, 'needs_context' => true]));
|
||||
$environment->addFunction(new Twig_Function('barbar', 'twig_tests_function_barbar', ['is_variadic' => true]));
|
||||
$environment->addFunction(new \Twig\TwigFunction('foo', 'twig_tests_function_dummy', []));
|
||||
$environment->addFunction(new \Twig\TwigFunction('bar', 'twig_tests_function_dummy', ['needs_environment' => true]));
|
||||
$environment->addFunction(new \Twig\TwigFunction('foofoo', 'twig_tests_function_dummy', ['needs_context' => true]));
|
||||
$environment->addFunction(new \Twig\TwigFunction('foobar', 'twig_tests_function_dummy', ['needs_environment' => true, 'needs_context' => true]));
|
||||
$environment->addFunction(new \Twig\TwigFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true]));
|
||||
|
||||
$tests = [];
|
||||
|
||||
@@ -96,7 +96,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase
|
||||
protected function getEnvironment()
|
||||
{
|
||||
$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
|
||||
$env->addFunction(new Twig_Function('anonymous', function () {}));
|
||||
$env->addFunction(new \Twig\TwigFunction('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase
|
||||
public function getTests()
|
||||
{
|
||||
$environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
|
||||
$environment->addTest(new Twig_Test('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true]));
|
||||
$environment->addTest(new \Twig\TwigTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true]));
|
||||
|
||||
$tests = [];
|
||||
|
||||
@@ -68,7 +68,7 @@ class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase
|
||||
protected function getEnvironment()
|
||||
{
|
||||
$env = new \Twig\Environment(new \Twig\Loader\ArrayLoader([]));
|
||||
$env->addTest(new Twig_Test('anonymous', function () {}));
|
||||
$env->addTest(new \Twig\TwigTest('anonymous', function () {}));
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user