Skip to content

omnibridge/twig API reference

Floor
Bridge
Version
1.x
Verified for real
Its README does not say
Licence
MIT
composer require omnibridge/twig:1.x-dev

Read from the package's own PHP files at the commit ca8a648306a4: its namespaces, classes, interfaces and enums, their public constants, properties and methods with their PHPDoc, and the options its factories take. Nothing of it is run.

Omnibridge\Twig

  • AccessExtension class

    What a page asks of the visitor's host: whether the visitor may do something, `is_granted(attribute, subject)` (omnisense/omnibridge's Access), and the token a form of theirs carries against cross-site requests, `csrf_token(intent)` (Tokens) - under the names Symfony gives them, answered by the host's adapters.

    2 methods

  • ContractExtension class

    What a page may use beyond Twig itself: `path()`, `url()`, `asset()` and the `trans` filter, under the names Symfony gives them. A framework that already has them (Symfony) does not register this extension; any other one does, with its own answers to the contract.

    3 methods

  • HelperExtension class

    The small helpers omnibase gives the templates of its sites, for a framework rendering those templates without omnibase: the same names and the same results as omnibase's (Resources/Functions.php and FunctionTwigExtension), framework-free. Copied here because two frameworks now need them (plan 0, rule 13); omnibase registers this extension first and its own win where they do more. |at and |emoji_only are only here (they left omnibase's FunctionTwigExtension, audit R24).

    16 methods · 3 constants

  • MapExtension class

    omnisense/omnimap in a page, whichever framework renders it:

    5 methods · 2 constants

Omnibridge\Twig

AccessExtension class

final class AccessExtension extends AbstractExtension AccessExtension.php:24

What a page asks of the visitor's host: whether the visitor may do something, is_granted(attribute, subject) (omnisense/omnibridge's Access), and the token a form of theirs carries against cross-site requests, csrf_token(intent) (Tokens) - under the names Symfony gives them, answered by the host's adapters.

Registered by every host, Symfony included (omnibridge/symfony, after twig-bridge's SecurityExtension and CsrfExtension, whose functions it then answers with the same services), so that a page asks the same code whichever framework renders it. A contract the host does not bind leaves its function out (a Symfony application without SecurityBundle or without CSRF protection).

AccessExtension::__construct()

public function __construct(readonly ?Access $access = null, readonly ?Tokens $tokens = null)

AccessExtension::getFunctions()

public function getFunctions(): array

ContractExtension class

final class ContractExtension extends AbstractExtension ContractExtension.php:17

What a page may use beyond Twig itself: path(), url(), asset() and the trans filter, under the names Symfony gives them. A framework that already has them (Symfony) does not register this extension; any other one does, with its own answers to the contract.

ContractExtension::__construct()

public function __construct(readonly Urls $urls, readonly Translations $translations)

ContractExtension::getFunctions()

public function getFunctions(): array

ContractExtension::getFilters()

public function getFilters(): array

HelperExtension class

final class HelperExtension extends AbstractExtension HelperExtension.php:18

The small helpers omnibase gives the templates of its sites, for a framework rendering those templates without omnibase: the same names and the same results as omnibase's (Resources/Functions.php and FunctionTwigExtension), framework-free. Copied here because two frameworks now need them (plan 0, rule 13); omnibase registers this extension first and its own win where they do more. |at and |emoji_only are only here (they left omnibase's FunctionTwigExtension, audit R24).

const SHORTEN_FRONT = -1
const SHORTEN_MIDDLE = 0
const SHORTEN_BACK = 1

HelperExtension::__construct()

public function __construct(readonly string $locale = 'fr', readonly ?string $timezone = null)

HelperExtension::getFunctions()

public function getFunctions(): array

HelperExtension::getFilters()

public function getFilters(): array

HelperExtension::htmlAttributes()

public static function htmlAttributes(array ...$attributes): string

class="a b" data-x="y", the values as given (omnibase's html_attributes()).

HelperExtension::shorten()

public static function shorten(?string $haystack, int $length = 100, int $position = self::SHORTEN_BACK, string $separator = ' [..] '): ?string

A text cut to $length characters, the separator where it was cut (omnibase's str_shorten()).

HelperExtension::ucfirst()

public static function ucfirst(array|string|null $text): array|string

HelperExtension::second()

public static function second(iterable|null $list): mixed

HelperExtension::joinIfExists()

public static function joinIfExists(?array $list, string $separator): ?string

HelperExtension::highlight()

public static function highlight(?string $content, string|array|null $pattern): ?string

The words of $pattern marked in $content (omnibase's highlight, without its excerpt mode).

HelperExtension::lessThan()

public static function lessThan(mixed $date, mixed $diff): bool

Whether $date is more recent than $diff ("+2 day": less than two days ago).

HelperExtension::at()

public static function at(array $array, int|string $index): mixed

A list's entry at an index, null when it has none (omnibase's |at).

HelperExtension::isEmojiOnly()

public static function isEmojiOnly(?string $value): bool

Whether a text is made of emoji alone, spaces aside (omnibase's |emoji_only: a comment of one emoji shown big).

HelperExtension::lang()

public static function lang(?string $locale): string

fr-FR, fr_FR: fr.

HelperExtension::country()

public static function country(?string $locale): string

en-GB: GB; a bare language, its own country (fr: FR).

HelperExtension::datetime()

public function datetime(mixed $date, string $pattern = 'YYYY-MM-dd HH:mm:ss', ?string $locale = null): string

A date in the page's language by an ICU pattern, lower case, as omnibase gives it ("MMMM YYYY": "mars 2022", |title after it for "Mars 2022").

A string in ISO 8601 (a screen's moment, omnibase's Base\Screen\Shape::moment(): 2026-04-10T18:05:00+00:00) is that moment, printed as the DateTime it came from was in the extension's time zone - as omnibase's |datetime reads it since 25b8ebac; any other string is not read as a date, only lowered ("Présent", "Now"); none is the pattern itself.

HelperExtension::isMoment()

public static function isMoment(string $value): bool

Whether a string is a moment in ISO 8601: a date, a time, and a zone or not (omnibase's FunctionTwigExtension::isMoment()).

MapExtension class

final class MapExtension extends AbstractExtension MapExtension.php:30

omnisense/omnimap in a page, whichever framework renders it:

{{ omnimap(view) }} the picture kept, or the live map (MapPrinter's rule) {{ omnimap_export(view, {class: 'item', text: '…'}) }} the button that sends the live map's picture to the cache {{ omnimap_suppress(view, {text: '…'}) }} the button that deletes it

Who may change the map is the host's Access ($control, ROLE_ADMIN by default); the buttons post to the routes named $routes with a token of the host's Tokens (intents "omnimap-export", "omnimap-suppress"): under Symfony omnibridge/symfony's map cache routes; under Laravel routes the application declares itself (omnibridge/laravel routes the tile only). Registered by omnibridge/symfony and omnibridge/laravel when omnimap is configured.

const EXPORT = 'omnimap-export'
const SUPPRESS = 'omnimap-suppress'

MapExtension::__construct()

public function __construct(readonly MapPrinter $printer, readonly Urls $urls, readonly ?Access $access = null, readonly ?Tokens $tokens = null, readonly string $control = 'ROLE_ADMIN', readonly array $routes = [])

MapExtension::getFunctions()

public function getFunctions(): array

MapExtension::map()

public function map(?MapView $view): string

MapExtension::export()

public function export(?MapView $view, array $attributes = []): string
$attributes

the button's, and its text

MapExtension::suppress()

public function suppress(?MapView $view, array $attributes = []): string
$attributes

the button's, and its text