PHP Класс PicoTwigExtension

Автор: Daniel Rudolf
Наследование: extends Twig_Extension
Показать файл Открыть проект

Открытые методы

Метод Описание
__construct ( Pico $pico ) Constructs a new instance of this Twig extension
getFilters ( ) : Twig_SimpleFilter[] Returns the Twig filters markdown, map and sort_by
getKeyOfVar ( array | Traversable | ArrayAccess | object $var, mixed $keyPath ) : mixed Returns the value of a variable item specified by a scalar key or a arbitrary deep sub-key using a key path
getName ( ) : string Returns the name of the extension
getPico ( ) : Pico Returns the extensions instance of Pico
mapFilter ( array | Traversable $var, mixed $mapKeyPath ) : array Returns a array with the values of the given key or key path
markdownFilter ( string $markdown ) : string Parses a markdown string to HTML
sortByFilter ( array | Traversable $var, mixed $sortKeyPath, string $fallback = 'bottom' ) : array Sorts an array by one of its keys or a arbitrary deep sub-key

Описание методов

__construct() публичный Метод

Constructs a new instance of this Twig extension
public __construct ( Pico $pico )
$pico Pico current instance of Pico

getFilters() публичный Метод

Returns the Twig filters markdown, map and sort_by
См. также: Twig_ExtensionInterface::getFilters()
public getFilters ( ) : Twig_SimpleFilter[]
Результат Twig_SimpleFilter[] array of Pico's Twig filters

getKeyOfVar() публичный статический Метод

Returns the value of a variable item specified by a scalar key or a arbitrary deep sub-key using a key path
public static getKeyOfVar ( array | Traversable | ArrayAccess | object $var, mixed $keyPath ) : mixed
$var array | Traversable | ArrayAccess | object base variable
$keyPath mixed scalar key or a array interpreted as key path (when passing e.g. ['foo', 'bar'], the method will return $var['foo']['bar']) specifying the value
Результат mixed the requested value or NULL when the given key or key path didn't match

getName() публичный Метод

Returns the name of the extension
См. также: Twig_ExtensionInterface::getName()
public getName ( ) : string
Результат string the extension name

getPico() публичный Метод

Returns the extensions instance of Pico
См. также: Pico
public getPico ( ) : Pico
Результат Pico the extensions instance of Pico

mapFilter() публичный Метод

This method is registered as the Twig map filter. You can use this filter to e.g. get all page titles ({{ pages|map("title") }}).
public mapFilter ( array | Traversable $var, mixed $mapKeyPath ) : array
$var array | Traversable variable to map
$mapKeyPath mixed key to map; either a scalar or a array interpreted as key path (i.e. ['foo', 'bar'] will return all $item['foo']['bar'] values)
Результат array mapped values

markdownFilter() публичный Метод

This method is registered as the Twig markdown filter. You can use it to e.g. parse a meta variable ({{ meta.description|markdown }}). Don't use it to parse the contents of a page, use the content filter instead, what ensures the proper preparation of the contents.
public markdownFilter ( string $markdown ) : string
$markdown string markdown to parse
Результат string parsed HTML

sortByFilter() публичный Метод

This method is registered as the Twig sort_by filter. You can use this filter to e.g. sort the pages array by a arbitrary meta value. Calling {{ pages|sort_by("meta:nav"|split(":")) }} returns all pages sorted by the meta value nav. Please note the "meta:nav"|split(":") part of the example. The sorting algorithm will never assume equality of two values, it will then fall back to the original order. The result is always sorted in ascending order, apply Twigs reverse filter to achieve a descending order.
public sortByFilter ( array | Traversable $var, mixed $sortKeyPath, string $fallback = 'bottom' ) : array
$var array | Traversable variable to sort
$sortKeyPath mixed key to use for sorting; either a scalar or a array interpreted as key path (i.e. ['foo', 'bar'] will sort $var by $item['foo']['bar'])
$fallback string specify what to do with items which don't contain the specified sort key; use "bottom" (default) to move those items to the end of the sorted array, "top" to rank them first, or "keep" to keep the original order of those items
Результат array sorted array