MappedSlots

Learn how to reference slot IDs and the slot content map.

This interface holds the slot ID union and the indexed slot map, generated by the CLI in the Croct\Content namespace.

Example

Supposing you have a slot named home-banner with versions 1 and 2, SlotId is the union of every valid ID ('home-banner', 'home-banner@latest', 'home-banner@1', and 'home-banner@2'), and SlotMap maps each ID to its content type.

With a @template bound to SlotId, a handler can keep the content type in sync with the ID it receives. Import the types with @phpstan-import-type:

<?php/** * @phpstan-import-type SlotId from \Croct\Content\MappedSlots * @phpstan-import-type SlotMap from \Croct\Content\MappedSlots */final class Renderer{    /**     * @template T of SlotId     *     * @param T $slotId     * @param SlotMap[T] $content     */    public function render(string $slotId, array $content): void    {        // Render the content for the slot.    }}

Indexing the map requires PHPStan. Psalm supports SlotId through @psalm-import-type but cannot index the map, so type the content with a named type instead.