Skip to content

Configuration

phil/ujo-bundle
# config/packages/phil_ujo.yaml
phil_ujo:
    allow_raw: false        # whether documents may hold raw HTML blocks
    max_bytes: 4194304      # the largest UJO JSON read, in bytes
    max_depth: 8            # the deepest nesting of blocks inside blocks
    max_blocks: 10000       # the most blocks a document may hold, nested ones included
    max_html_length: 100000 # the longest HTML field, in characters
    max_raw_length: 50000   # the longest HTML of a raw block, in characters
OptionDefaultEffect
allow_rawfalsetrue adds the raw type to the registry: its HTML is sanitized with the raw profile. Accept it only from writers you trust with page structure
max_bytes4194304A larger JSON is refused before parsing. At least 1
max_depth8Blocks nested deeper are refused. At least 1
max_blocks10000A document of more blocks, nested ones included, is refused. At least 1
max_html_length100000An HTML field longer, in characters, is refused before it is sanitized. At least 1
max_raw_length50000The same for the HTML of a raw block. At least 1

The block and length limits bound what showing a document costs: its HTML is sanitized again at each render, through ujo_html as through Ujo::toHtml().

Services

ServiceBuilt as
Phil\Ujo\Type\BlockTypeRegistryBlockTypeRegistry::default(), with StandardTypes::raw() when allow_raw
Phil\Ujo\Normalizeron that registry, the default tunes and sanitizer, max_depth, max_blocks, max_html_length and max_raw_length
Phil\Ujo\Html\HtmlRendererHtmlRenderer::default()
Phil\Ujo\Text\PlainTextwith the default conversions
Phil\Ujo\Json\JsonDecoderwith max_bytes
Phil\Ujo\Ujoon the four above; public

Registries and renderers are immutable values. To add a type, a tune, a renderer or a conversion, build the value the application needs in a factory of its own and declare that factory for the service:

// src/Ujo/UjoFactory.php
final class UjoFactory
{
    public static function types(): BlockTypeRegistry
    {
        return BlockTypeRegistry::default()->with(CalloutType::create());
    }

    public static function renderer(): HtmlRenderer
    {
        return HtmlRenderer::default()->with('callout', new CalloutRenderer());
    }
}
# config/services.yaml
services:
    Phil\Ujo\Type\BlockTypeRegistry:
        factory: ['App\Ujo\UjoFactory', 'types']
    Phil\Ujo\Html\HtmlRenderer:
        factory: ['App\Ujo\UjoFactory', 'renderer']

The other services, Ujo first, take the redefined ones by reference.