MarkupManager

This class manages Twig functions, token parsers and filters.

 class System\Classes\MarkupManager

Traits

Trait Description
Singleton

Singleton trait.

Constants

Constant Description
EXTENSION_FILTER
string "filters"
EXTENSION_FUNCTION
string "functions"
EXTENSION_TOKEN_PARSER
string "tokens"

Properties

protected $callbacks : array

Cache of registration callbacks.

protected $items : array

Globally registered extension items

protected $pluginManager : System\Classes\PluginManager

Methods

public listExtensions (mixed $type) : array

Returns a list of the registered Twig extensions of a type.

Parameters
Property Description
$type
mixed

string The Twig extension type

Returns
array

public listFilters () : array

Returns a list of the registered Twig filters.

Returns
array

public listFunctions () : array

Returns a list of the registered Twig functions.

Returns
array

public listTokenParsers () : array

Returns a list of the registered Twig token parsers.

Returns
array

public static makeBaseTwigEnvironment ($loader = null, array $options = []) : Twig\Environment

Make an instance of the base TwigEnvironment to extend further

Parameters
Property Description
$loader
mixed
$options
array
Returns
Twig\Environment

public makeTwigFilters (array $filters = []) : array

Makes a set of Twig filters for use in a twig extension.

Parameters
Property Description
$filters
array

Current collection

Returns
array

public makeTwigFunctions (array $functions = []) : array

Makes a set of Twig functions for use in a twig extension.

Parameters
Property Description
$functions
array

Current collection

Returns
array

public makeTwigTokenParsers (array $parsers = []) : array

Makes a set of Twig token parsers for use in a twig extension.

Parameters
Property Description
$parsers
array

Current collection

Returns
array

public registerCallback (callable $callback) : void

Registers a callback function that defines simple Twig extensions.

The callback function should register menu items by calling the manager's registerFunctions, registerFilters, registerTokenParsers function. The manager instance is passed to the callback function as an argument. Usage:

MarkupManager::registerCallback(function ($manager) {
    $manager->registerFilters([...]);
    $manager->registerFunctions([...]);
    $manager->registerTokenParsers([...]);
});
Parameters
Property Description
$callback
callable
Returns
void

public registerExtensions (string $type, array $definitions) : void

Registers the Twig extension items.

$type must be one of self::EXTENSION_TOKEN_PARSER, self::EXTENSION_FILTER, or self::EXTENSION_FUNCTION $definitions is of the format of [$extensionName => $associativeExtensionOptions]

Parameters
Property Description
$type
string
$definitions
array
Returns
void

public registerFilters (array $definitions) : void

Registers a Twig Filter

Parameters
Property Description
$definitions
array
Returns
void

public registerFunctions (array $definitions) : void

Registers a Twig Function

Parameters
Property Description
$definitions
array
Returns
void

public registerTokenParsers (array $definitions) : void

Registers a Twig Token Parser

Parameters
Property Description
$definitions
array
Returns
void

protected init ()

Initialize this singleton.

Returns
mixed

protected isWildCallable (callable $callable, boolean $replaceWith = false) : mixed

Tests if a callable type contains a wildcard, also acts as a utility to replace the wildcard with a string.

Parameters
Property Description
$callable
callable
$replaceWith
boolean
Returns
mixed

protected loadExtensions () : void

Loads all of the registered Twig extensions

Returns
void

inherited public __clone ()

Inherited from Singleton
Returns
mixed

inherited public __wakeup ()

Inherited from Singleton
Returns
mixed

inherited public static final forgetInstance ($container = null) : void

Inherited from Singleton

Forget this singleton's instance if it exists

Parameters
Property Description
$container
mixed
Returns
void

inherited public static final instance ($container = null) : static

Inherited from Singleton

Create a new instance of this singleton.

Parameters
Property Description
$container
mixed
Returns
static

inherited protected final __construct ()

Inherited from Singleton

Constructor.

Returns
mixed
Copyright © 2024 Winter CMS