ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Extension_Core Class Reference

@final More...

+ Inheritance diagram for Twig_Extension_Core:
+ Collaboration diagram for Twig_Extension_Core:

Public Member Functions

 setEscaper ($strategy, $callable)
 Defines a new escaper to be used via the escape filter. More...
 
 getEscapers ()
 Gets all defined escapers. More...
 
 setDateFormat ($format=null, $dateIntervalFormat=null)
 Sets the default format to be used by the date filter. More...
 
 getDateFormat ()
 Gets the default format to be used by the date filter. More...
 
 setTimezone ($timezone)
 Sets the default timezone to be used by the date filter. More...
 
 getTimezone ()
 Gets the default timezone to be used by the date filter. More...
 
 setNumberFormat ($decimal, $decimalPoint, $thousandSep)
 Sets the default format to be used by the number_format filter. More...
 
 getNumberFormat ()
 Get the default format used by the number_format filter. More...
 
 getTokenParsers ()
 Returns the token parser instances to add to the existing list. More...
 
 getFilters ()
 Returns a list of filters to add to the existing list. More...
 
 getFunctions ()
 Returns a list of functions to add to the existing list. More...
 
 getTests ()
 Returns a list of tests to add to the existing list. More...
 
 getOperators ()
 Returns a list of operators to add to the existing list. More...
 
 getName ()
 
- Public Member Functions inherited from Twig_Extension
 initRuntime (Twig_Environment $environment)
 
 getTokenParsers ()
 Returns the token parser instances to add to the existing list. More...
 
 getNodeVisitors ()
 Returns the node visitor instances to add to the existing list. More...
 
 getFilters ()
 Returns a list of filters to add to the existing list. More...
 
 getTests ()
 Returns a list of tests to add to the existing list. More...
 
 getFunctions ()
 Returns a list of functions to add to the existing list. More...
 
 getOperators ()
 Returns a list of operators to add to the existing list. More...
 
 getGlobals ()
 
 getName ()
 
 initRuntime (Twig_Environment $environment)
 Initializes the runtime environment. More...
 
 getTokenParsers ()
 Returns the token parser instances to add to the existing list. More...
 
 getNodeVisitors ()
 Returns the node visitor instances to add to the existing list. More...
 
 getFilters ()
 Returns a list of filters to add to the existing list. More...
 
 getTests ()
 Returns a list of tests to add to the existing list. More...
 
 getFunctions ()
 Returns a list of functions to add to the existing list. More...
 
 getOperators ()
 Returns a list of operators to add to the existing list. More...
 
 getGlobals ()
 Returns a list of global variables to add to the existing list. More...
 
 getName ()
 Returns the name of the extension. More...
 

Protected Attributes

 $dateFormats = array('F j, Y H:i', '%d days')
 
 $numberFormat = array(0, '.', ',')
 
 $timezone = null
 
 $escapers = array()
 

Detailed Description

@final

Definition at line 19 of file Core.php.

Member Function Documentation

◆ getDateFormat()

Twig_Extension_Core::getDateFormat ( )

Gets the default format to be used by the date filter.

Returns
array The default date format string and the default date interval format string

Definition at line 69 of file Core.php.

70 {
71 return $this->dateFormats;
72 }

References $dateFormats.

◆ getEscapers()

Twig_Extension_Core::getEscapers ( )

Gets all defined escapers.

Returns
array An array of escapers

Definition at line 42 of file Core.php.

43 {
44 return $this->escapers;
45 }

References $escapers.

◆ getFilters()

Twig_Extension_Core::getFilters ( )

Returns a list of filters to add to the existing list.

Returns
Twig_SimpleFilter[]

Reimplemented from Twig_Extension.

Definition at line 142 of file Core.php.

143 {
144 $filters = array(
145 // formatting filters
146 new Twig_SimpleFilter('date', 'twig_date_format_filter', array('needs_environment' => true)),
147 new Twig_SimpleFilter('date_modify', 'twig_date_modify_filter', array('needs_environment' => true)),
148 new Twig_SimpleFilter('format', 'sprintf'),
149 new Twig_SimpleFilter('replace', 'twig_replace_filter'),
150 new Twig_SimpleFilter('number_format', 'twig_number_format_filter', array('needs_environment' => true)),
151 new Twig_SimpleFilter('abs', 'abs'),
152 new Twig_SimpleFilter('round', 'twig_round'),
153
154 // encoding
155 new Twig_SimpleFilter('url_encode', 'twig_urlencode_filter'),
156 new Twig_SimpleFilter('json_encode', 'twig_jsonencode_filter'),
157 new Twig_SimpleFilter('convert_encoding', 'twig_convert_encoding'),
158
159 // string filters
160 new Twig_SimpleFilter('title', 'twig_title_string_filter', array('needs_environment' => true)),
161 new Twig_SimpleFilter('capitalize', 'twig_capitalize_string_filter', array('needs_environment' => true)),
162 new Twig_SimpleFilter('upper', 'strtoupper'),
163 new Twig_SimpleFilter('lower', 'strtolower'),
164 new Twig_SimpleFilter('striptags', 'strip_tags'),
165 new Twig_SimpleFilter('trim', 'twig_trim_filter'),
166 new Twig_SimpleFilter('nl2br', 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))),
167
168 // array helpers
169 new Twig_SimpleFilter('join', 'twig_join_filter'),
170 new Twig_SimpleFilter('split', 'twig_split_filter', array('needs_environment' => true)),
171 new Twig_SimpleFilter('sort', 'twig_sort_filter'),
172 new Twig_SimpleFilter('merge', 'twig_array_merge'),
173 new Twig_SimpleFilter('batch', 'twig_array_batch'),
174
175 // string/array filters
176 new Twig_SimpleFilter('reverse', 'twig_reverse_filter', array('needs_environment' => true)),
177 new Twig_SimpleFilter('length', 'twig_length_filter', array('needs_environment' => true)),
178 new Twig_SimpleFilter('slice', 'twig_slice', array('needs_environment' => true)),
179 new Twig_SimpleFilter('first', 'twig_first', array('needs_environment' => true)),
180 new Twig_SimpleFilter('last', 'twig_last', array('needs_environment' => true)),
181
182 // iteration and runtime
183 new Twig_SimpleFilter('default', '_twig_default_filter', array('node_class' => 'Twig_Node_Expression_Filter_Default')),
184 new Twig_SimpleFilter('keys', 'twig_get_array_keys_filter'),
185
186 // escaping
187 new Twig_SimpleFilter('escape', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')),
188 new Twig_SimpleFilter('e', 'twig_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')),
189 );
190
191 if (function_exists('mb_get_info')) {
192 $filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', array('needs_environment' => true));
193 $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', array('needs_environment' => true));
194 }
195
196 return $filters;
197 }
Represents a template filter.

◆ getFunctions()

Twig_Extension_Core::getFunctions ( )

Returns a list of functions to add to the existing list.

Returns
Twig_SimpleFunction[]

Reimplemented from Twig_Extension.

Definition at line 199 of file Core.php.

200 {
201 return array(
202 new Twig_SimpleFunction('max', 'max'),
203 new Twig_SimpleFunction('min', 'min'),
204 new Twig_SimpleFunction('range', 'range'),
205 new Twig_SimpleFunction('constant', 'twig_constant'),
206 new Twig_SimpleFunction('cycle', 'twig_cycle'),
207 new Twig_SimpleFunction('random', 'twig_random', array('needs_environment' => true)),
208 new Twig_SimpleFunction('date', 'twig_date_converter', array('needs_environment' => true)),
209 new Twig_SimpleFunction('include', 'twig_include', array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))),
210 new Twig_SimpleFunction('source', 'twig_source', array('needs_environment' => true, 'is_safe' => array('all'))),
211 );
212 }
Represents a template function.

◆ getName()

Twig_Extension_Core::getName ( )
Deprecated:
since 1.26 (to be removed in 2.0), not used anymore internally

Reimplemented from Twig_Extension.

Definition at line 273 of file Core.php.

274 {
275 return 'core';
276 }

◆ getNumberFormat()

Twig_Extension_Core::getNumberFormat ( )

Get the default format used by the number_format filter.

Returns
array The arguments for number_format()

Definition at line 115 of file Core.php.

116 {
117 return $this->numberFormat;
118 }

References $numberFormat.

◆ getOperators()

Twig_Extension_Core::getOperators ( )

Returns a list of operators to add to the existing list.

Returns
array<array> First array of unary operators, second array of binary operators

Reimplemented from Twig_Extension.

Definition at line 232 of file Core.php.

233 {
234 return array(
235 array(
236 'not' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
237 '-' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'),
238 '+' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'),
239 ),
240 array(
241 'or' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
242 'and' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
243 'b-or' => array('precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
244 'b-xor' => array('precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
245 'b-and' => array('precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
246 '==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
247 '!=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
248 '<' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
249 '>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
250 '>=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
251 '<=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
252 'not in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
253 'in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
254 'matches' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Matches', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
255 'starts with' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_StartsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
256 'ends with' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_EndsWith', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
257 '..' => array('precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
258 '+' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
259 '-' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
260 '~' => array('precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
261 '*' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mul', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
262 '/' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Div', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
263 '//' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_FloorDiv', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
264 '%' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
265 'is' => array('precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
266 'is not' => array('precedence' => 100, 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
267 '**' => array('precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT),
268 '??' => array('precedence' => 300, 'class' => 'Twig_Node_Expression_NullCoalesce', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT),
269 ),
270 );
271 }

References Twig_ExpressionParser\OPERATOR_LEFT, and Twig_ExpressionParser\OPERATOR_RIGHT.

◆ getTests()

Twig_Extension_Core::getTests ( )

Returns a list of tests to add to the existing list.

Returns
Twig_SimpleTest[]

Reimplemented from Twig_Extension.

Definition at line 214 of file Core.php.

215 {
216 return array(
217 new Twig_SimpleTest('even', null, array('node_class' => 'Twig_Node_Expression_Test_Even')),
218 new Twig_SimpleTest('odd', null, array('node_class' => 'Twig_Node_Expression_Test_Odd')),
219 new Twig_SimpleTest('defined', null, array('node_class' => 'Twig_Node_Expression_Test_Defined')),
220 new Twig_SimpleTest('sameas', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas', 'deprecated' => '1.21', 'alternative' => 'same as')),
221 new Twig_SimpleTest('same as', null, array('node_class' => 'Twig_Node_Expression_Test_Sameas')),
222 new Twig_SimpleTest('none', null, array('node_class' => 'Twig_Node_Expression_Test_Null')),
223 new Twig_SimpleTest('null', null, array('node_class' => 'Twig_Node_Expression_Test_Null')),
224 new Twig_SimpleTest('divisibleby', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby', 'deprecated' => '1.21', 'alternative' => 'divisible by')),
225 new Twig_SimpleTest('divisible by', null, array('node_class' => 'Twig_Node_Expression_Test_Divisibleby')),
226 new Twig_SimpleTest('constant', null, array('node_class' => 'Twig_Node_Expression_Test_Constant')),
227 new Twig_SimpleTest('empty', 'twig_test_empty'),
228 new Twig_SimpleTest('iterable', 'twig_test_iterable'),
229 );
230 }
Represents a template test.
Definition: SimpleTest.php:20

◆ getTimezone()

Twig_Extension_Core::getTimezone ( )

Gets the default timezone to be used by the date filter.

Returns
DateTimeZone The default timezone currently in use

Definition at line 89 of file Core.php.

90 {
91 if (null === $this->timezone) {
92 $this->timezone = new DateTimeZone(date_default_timezone_get());
93 }
94
95 return $this->timezone;
96 }

References $timezone.

◆ getTokenParsers()

Twig_Extension_Core::getTokenParsers ( )

Returns the token parser instances to add to the existing list.

Returns
Twig_TokenParserInterface[]

Reimplemented from Twig_Extension.

Definition at line 120 of file Core.php.

121 {
122 return array(
139 );
140 }
Marks a section of a template as being reusable.
Definition: Block.php:26
Evaluates an expression, discarding the returned value.
Definition: Do.php:18
Embeds a template.
Definition: Embed.php:18
Extends a template by another one.
Definition: Extends.php:23
Filters a section of a template by applying filters.
Definition: Filter.php:24
Flushes the output to the client.
Definition: Flush.php:20
Loops over each item of a sequence.
Definition: For.php:27
Imports macros.
Definition: From.php:22
Tests a condition.
Definition: If.php:29
Imports macros.
Definition: Import.php:22
Includes a template.
Definition: Include.php:23
Defines a macro.
Definition: Macro.php:24
Defines a variable.
Definition: Set.php:32
Remove whitespaces between HTML tags.
Definition: Spaceless.php:28
Imports blocks defined in another template into the current template.
Definition: Use.php:29
Creates a nested scope.
Definition: With.php:20

◆ setDateFormat()

Twig_Extension_Core::setDateFormat (   $format = null,
  $dateIntervalFormat = null 
)

Sets the default format to be used by the date filter.

Parameters
string$formatThe default date format string
string$dateIntervalFormatThe default date interval format string

Definition at line 53 of file Core.php.

54 {
55 if (null !== $format) {
56 $this->dateFormats[0] = $format;
57 }
58
59 if (null !== $dateIntervalFormat) {
60 $this->dateFormats[1] = $dateIntervalFormat;
61 }
62 }
$format
Definition: metadata.php:141

References $format.

◆ setEscaper()

Twig_Extension_Core::setEscaper (   $strategy,
  $callable 
)

Defines a new escaper to be used via the escape filter.

Parameters
string$strategyThe strategy name that should be used as a strategy in the escape call
callable$callableA valid PHP callable

Definition at line 32 of file Core.php.

33 {
34 $this->escapers[$strategy] = $callable;
35 }

◆ setNumberFormat()

Twig_Extension_Core::setNumberFormat (   $decimal,
  $decimalPoint,
  $thousandSep 
)

Sets the default format to be used by the number_format filter.

Parameters
int$decimalthe number of decimal places to use
string$decimalPointthe character(s) to use for the decimal point
string$thousandSepthe character(s) to use for the thousands separator

Definition at line 105 of file Core.php.

106 {
107 $this->numberFormat = array($decimal, $decimalPoint, $thousandSep);
108 }

◆ setTimezone()

Twig_Extension_Core::setTimezone (   $timezone)

Sets the default timezone to be used by the date filter.

Parameters
DateTimeZone | string$timezoneThe default timezone string or a DateTimeZone object

Definition at line 79 of file Core.php.

80 {
81 $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
82 }

References $timezone.

Field Documentation

◆ $dateFormats

Twig_Extension_Core::$dateFormats = array('F j, Y H:i', '%d days')
protected

Definition at line 21 of file Core.php.

Referenced by getDateFormat().

◆ $escapers

Twig_Extension_Core::$escapers = array()
protected

Definition at line 24 of file Core.php.

Referenced by getEscapers().

◆ $numberFormat

Twig_Extension_Core::$numberFormat = array(0, '.', ',')
protected

Definition at line 22 of file Core.php.

Referenced by getNumberFormat().

◆ $timezone

Twig_Extension_Core::$timezone = null
protected

Definition at line 23 of file Core.php.

Referenced by getTimezone(), and setTimezone().


The documentation for this class was generated from the following file: