CoreExtension
extends AbstractExtension
in package
Table of Contents
Constants
- ARRAY_LIKE_CLASSES = ['ArrayIterator', 'ArrayObject', 'CachingIterator', 'RecursiveArrayIterator', 'RecursiveCachingIterator', 'SplDoublyLinkedList', 'SplFixedArray', 'SplObjectStorage', 'SplQueue', 'SplStack', 'WeakMap']
- DEFAULT_TRIM_CHARS = " \t\n\r\x00\v"
Properties
- $dateFormats : mixed
- $numberFormat : mixed
- $timezone : mixed
Methods
- convertDate() : DateTime|DateTimeImmutable
- Converts an input to a \DateTime instance.
- formatDate() : string
- Formats a date.
- formatNumber() : string
- Formats a number.
- getDateFormat() : array<string|int, mixed>
- Gets the default format to be used by the date filter.
- getExpressionParsers() : array<string|int, mixed>
- getFilters() : array<string|int, TwigFilter>
- Returns a list of filters to add to the existing list.
- getFunctions() : array<string|int, TwigFunction>
- Returns a list of functions to add to the existing list.
- getLastModified() : int
- Returns the last modification time of the extension for cache invalidation.
- getNodeVisitors() : array<string|int, NodeVisitorInterface>
- Returns the node visitor instances to add to the existing list.
- getNumberFormat() : array<string|int, mixed>
- Get the default format used by the number_format filter.
- getOperators() : array<string|int, array<string|int, mixed>>
- Returns a list of operators to add to the existing list.
- getTests() : array<string|int, TwigTest>
- Returns a list of tests to add to the existing list.
- getTimezone() : DateTimeZone
- Gets the default timezone to be used by the date filter.
- getTokenParsers() : array<string|int, TokenParserInterface>
- Returns the token parser instances to add to the existing list.
- setDateFormat() : mixed
- Sets the default format to be used by the date filter.
- setNumberFormat() : mixed
- Sets the default format to be used by the number_format filter.
- setTimezone() : mixed
- Sets the default timezone to be used by the date filter.
- getPropertyChecker() : Closure
Constants
ARRAY_LIKE_CLASSES
public
mixed
ARRAY_LIKE_CLASSES
= ['ArrayIterator', 'ArrayObject', 'CachingIterator', 'RecursiveArrayIterator', 'RecursiveCachingIterator', 'SplDoublyLinkedList', 'SplFixedArray', 'SplObjectStorage', 'SplQueue', 'SplStack', 'WeakMap']
DEFAULT_TRIM_CHARS
private
mixed
DEFAULT_TRIM_CHARS
= " \t\n\r\x00\v"
Properties
$dateFormats
private
mixed
$dateFormats
= ['F j, Y H:i', '%d days']
$numberFormat
private
mixed
$numberFormat
= [0, '.', ',']
$timezone
private
mixed
$timezone
= null
Methods
convertDate()
Converts an input to a \DateTime instance.
public
convertDate([DateTimeInterface|string|int|null $date = null ][, DateTimeZone|string|false|null $timezone = null ]) : DateTime|DateTimeImmutable
{% if date(user.created_at) < date('+2days') %} {# do something #} {% endif %}
Parameters
- $date : DateTimeInterface|string|int|null = null
-
A date, a timestamp or null to use the current time
- $timezone : DateTimeZone|string|false|null = null
-
The target timezone, null to use the default, false to leave unchanged
Return values
DateTime|DateTimeImmutableformatDate()
Formats a date.
public
formatDate(DateTimeInterface|DateInterval|string|int|null $date[, string|null $format = null ][, DateTimeZone|string|false|null $timezone = null ]) : string
{{ post.published_at|date("m/d/Y") }}
Parameters
- $date : DateTimeInterface|DateInterval|string|int|null
-
A date, a timestamp or null to use the current time
- $format : string|null = null
-
The target format, null to use the default
- $timezone : DateTimeZone|string|false|null = null
-
The target timezone, null to use the default, false to leave unchanged
Return values
stringformatNumber()
Formats a number.
public
formatNumber(mixed $number[, int|null $decimal = null ][, string|null $decimalPoint = null ][, string|null $thousandSep = null ]) : string
All of the formatting options can be left null, in that case the defaults will be used. Supplying any of the parameters will override the defaults set in the environment object.
Parameters
- $number : mixed
-
A float/int/string of the number to format
- $decimal : int|null = null
-
the number of decimal points to display
- $decimalPoint : string|null = null
-
the character(s) to use for the decimal point
- $thousandSep : string|null = null
-
the character(s) to use for the thousands separator
Return values
stringgetDateFormat()
Gets the default format to be used by the date filter.
public
getDateFormat() : array<string|int, mixed>
Return values
array<string|int, mixed> —The default date format string and the default date interval format string
getExpressionParsers()
public
getExpressionParsers() : array<string|int, mixed>
Return values
array<string|int, mixed>getFilters()
Returns a list of filters to add to the existing list.
public
getFilters() : array<string|int, TwigFilter>
Return values
array<string|int, TwigFilter>getFunctions()
Returns a list of functions to add to the existing list.
public
getFunctions() : array<string|int, TwigFunction>
Return values
array<string|int, TwigFunction>getLastModified()
Returns the last modification time of the extension for cache invalidation.
public
getLastModified() : int
This timestamp should be the last time the source code of the extension class and all its dependencies were modified (including the Runtime class).
Return values
intgetNodeVisitors()
Returns the node visitor instances to add to the existing list.
public
getNodeVisitors() : array<string|int, NodeVisitorInterface>
Return values
array<string|int, NodeVisitorInterface>getNumberFormat()
Get the default format used by the number_format filter.
public
getNumberFormat() : array<string|int, mixed>
Return values
array<string|int, mixed> —The arguments for number_format()
getOperators()
Returns a list of operators to add to the existing list.
public
getOperators() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>getTests()
Returns a list of tests to add to the existing list.
public
getTests() : array<string|int, TwigTest>
Return values
array<string|int, TwigTest>getTimezone()
Gets the default timezone to be used by the date filter.
public
getTimezone() : DateTimeZone
Return values
DateTimeZone —The default timezone currently in use
getTokenParsers()
Returns the token parser instances to add to the existing list.
public
getTokenParsers() : array<string|int, TokenParserInterface>
Return values
array<string|int, TokenParserInterface>setDateFormat()
Sets the default format to be used by the date filter.
public
setDateFormat([string|null $format = null ][, string|null $dateIntervalFormat = null ]) : mixed
Parameters
- $format : string|null = null
-
The default date format string
- $dateIntervalFormat : string|null = null
-
The default date interval format string
setNumberFormat()
Sets the default format to be used by the number_format filter.
public
setNumberFormat(int $decimal, string $decimalPoint, string $thousandSep) : mixed
Parameters
- $decimal : int
-
the number of decimal places to use
- $decimalPoint : string
-
the character(s) to use for the decimal point
- $thousandSep : string
-
the character(s) to use for the thousands separator
setTimezone()
Sets the default timezone to be used by the date filter.
public
setTimezone(DateTimeZone|string $timezone) : mixed
Parameters
- $timezone : DateTimeZone|string
-
The default timezone string or a \DateTimeZone object
getPropertyChecker()
private
static getPropertyChecker(string $class, string $property) : Closure
Parameters
- $class : string
- $property : string