System\Classes\MarkupManager

Source: ~/modules/system/classes/MarkupManager.php

This class manages Twig functions, token parsers and filters.

Protected properties

protected array $callbacks

Cache of registration callbacks.

protected array $items

Globally registered extension items

protected System\Classes\PluginManager $pluginManager

protected array $transactionItems

Transaction based extension items

protected bool $transactionMode

Manager is in transaction mode

protected static $instance

Public methods

public void __clone()

public void __wakeup()

public void beginTransaction()

Start a new transaction.

public void endTransaction()

Ends an active transaction.

public static void forgetInstance()

Forget this singleton's instance if it exists

public static void instance()

Create a new instance of this singleton.

public array listExtensions($type $type)

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

Parameters
  • $type $type - String The Twig extension type

public array listFilters()

Returns a list of the registered Twig filters.

public array listFunctions()

Returns a list of the registered Twig functions.

public array listTokenParsers()

Returns a list of the registered Twig token parsers.

public array makeTwigFilters(array $filters=array())

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

Parameters
  • array $filters - Current collection

public array makeTwigFunctions(array $functions=array())

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

Parameters
  • array $functions - Current collection

public array makeTwigTokenParsers(array $parsers=array())

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

Parameters
  • array $parsers - Current collection

public void registerCallback(callable $callback)

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
  • callable $callback - A callable function.

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

Registers the CMS Twig extension items. The argument is an array of the extension definitions. The array keys represent the function/filter name, specific for the plugin/module. Each element in the array should be an associative array.

Parameters
  • string $type - The extension type: filters, functions, tokens
  • array $definitions - An array of the extension definitions.

public void registerFilters(array $definitions)

Registers a CMS Twig Filter

Parameters
  • array $definitions - An array of the extension definitions.

public void registerFunctions(array $definitions)

Registers a CMS Twig Function

Parameters
  • array $definitions - An array of the extension definitions.

public void registerTokenParsers(array $definitions)

Registers a CMS Twig Token Parser

Parameters
  • array $definitions - An array of the extension definitions.

public void transaction(Closure $callback)

Execute a single serving transaction, containing filters, functions, and token parsers that are disposed of afterwards.

Parameters
  • Closure $callback

Protected methods

protected void __construct()

Constructor.

protected void init()

Initialize this singleton.

protected mixed isWildCallable(callable $callable, string|bool $replaceWith=false)

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

Parameters
  • callable $callable
  • string|bool $replaceWith

protected void loadExtensions()