Service Tags Reference

PhrameCMS modules extend the core runtime and official packages through 13 official DI container service tags. Each tag is discovered automatically by its owning module when the container builds or boots.

Priority & Resolution Semantics

All tags are managed by PhrameCms\Core\Container\ContainerBuilder:

  • Register a tagged service with $builder->autowire(MyService::class, [SomeInterface::SERVICE_TAG]), $builder->singleton(...), or $builder->factory(...) (default priority 0).
  • Assign an explicit priority with $builder->tag(MyService::class, SomeInterface::SERVICE_TAG, priority: 100).
  • ContainerBuilder::build() sorts every tag's service IDs in descending priority order (higher integer runs/resolves first), breaking ties strictly in FIFO registration order.
  • Consumers resolve tagged services via TaggedContainerInterface::tagged($tag) or type-safe TaggedContainerInterface::taggedAs($tag, $interface). Registering a service under a tag whose interface it does not implement throws a module or container exception during resolution.

Summary Table (All 13 Official Service Tags)

# Tag String Constant FQCN Interface FQCN Owning Package Priority Behavior
1 phrame.operation PhrameCms\Core\Operation\OperationRegistry::OPERATION_TAG PhrameCms\Core\Contract\OperationInterface phramecms/core Registration order in OperationRegistry; duplicate operation names fail.
2 phrame.event_subscriber PhrameCms\Core\Contract\EventSubscriberInterface::SERVICE_TAG PhrameCms\Core\Contract\EventSubscriberInterface phramecms/core Per-listener priority is controlled by EventSubscription::$priority (descending, FIFO ties); tag priority only orders subscriber registration.
3 phrame.schema_installer PhrameCms\Database\Contract\SchemaInstallerInterface::SERVICE_TAG PhrameCms\Database\Contract\SchemaInstallerInterface phramecms/database Higher priority installs first (UserSchemaInstaller uses priority 100).
4 phrame.field_type PhrameCms\Entity\Contract\FieldTypeInterface::SERVICE_TAG PhrameCms\Entity\Contract\FieldTypeInterface phramecms/entity Registered in descending tag priority order into FieldTypeRegistry.
5 phrame.route_provider PhrameCms\Routing\Contract\RouteProviderInterface::SERVICE_TAG PhrameCms\Routing\Contract\RouteProviderInterface phramecms/routing Higher priority providers add routes to RouteCollection first.
6 phrame.http_middleware PhrameCms\Routing\HttpKernel::MIDDLEWARE_TAG Psr\Http\Server\MiddlewareInterface phramecms/routing Higher priority executes outermost/earliest in the PSR-15 pipeline (AdminSecurityHeadersMiddleware = 200, BearerAuthMiddleware = 100).
7 phrame.config_schema PhrameCms\Config\Contract\ConfigSchemaProviderInterface::SERVICE_TAG PhrameCms\Config\Contract\ConfigSchemaProviderInterface phramecms/config Registered in descending tag priority order; matched by prefix().
8 phrame.cli_command PhrameCms\Cli\CliApplication::COMMAND_TAG PhrameCms\Cli\Contract\CommandInterface phramecms/cli Registered into CliApplication in descending tag priority order.
9 phrame.mcp_resource_provider PhrameCms\Mcp\Contract\McpResourceProviderInterface::SERVICE_TAG PhrameCms\Mcp\Contract\McpResourceProviderInterface phramecms/mcp Higher priority providers list resources first and win first-match in resources/read (supports($uri)).
10 phrame.admin_menu PhrameCms\Admin\Contract\AdminMenuProviderInterface::SERVICE_TAG PhrameCms\Admin\Contract\AdminMenuProviderInterface phramecms/admin Items are collected across all providers and sorted by AdminMenuItem::$weight within each group.
11 phrame.admin_theme PhrameCms\Admin\Contract\AdminThemeInterface::SERVICE_TAG PhrameCms\Admin\Contract\AdminThemeInterface phramecms/admin Registered by unique AdminThemeInterface::id() into AdminThemeRegistry.
12 phrame.admin_template_namespace PhrameCms\Admin\Contract\AdminTemplateNamespaceProviderInterface::SERVICE_TAG PhrameCms\Admin\Contract\AdminTemplateNamespaceProviderInterface phramecms/admin Higher priority providers register Twig namespaces first in TwigTemplateRenderer.
13 phrame.admin_field_widget PhrameCms\Admin\Contract\FieldFormWidgetInterface::SERVICE_TAG PhrameCms\Admin\Contract\FieldFormWidgetInterface phramecms/admin First-match wins: higher priority widgets take precedence when supports($fieldType) returns true.

Tag-by-Tag Registration Reference

1. phrame.operation

  • Constant: PhrameCms\Core\Operation\OperationRegistry::OPERATION_TAG
  • Interface: PhrameCms\Core\Contract\OperationInterface
  • Package: phramecms/core
  • Purpose: Exposes a self-describing operation through OperationBus (RBAC, JSON Schema validation, audit logging, idempotency, dry-run diff previews), automatically surfaced in CLI (op:list, op:describe, op:run), MCP (tools/list, tools/call), and Change Proposals (proposal.create → proposal.approve when mutatesState: true and supportsDryRun: true).
php
use PhrameCms\Core\Contract\OperationInterface;
use PhrameCms\Core\Operation\ExecutionContext;
use PhrameCms\Core\Operation\OperationMetadata;
use PhrameCms\Core\Operation\OperationRegistry;
use PhrameCms\Core\Operation\OperationResult;

final readonly class NoteCreateOperation implements OperationInterface
{
    public function metadata(): OperationMetadata
    {
        return new OperationMetadata(
            name: 'acme.note.create',
            description: 'Create a note with dry-run preview support.',
            inputSchema: [
                'type' => 'object',
                'required' => ['slug', 'body'],
                'properties' => [
                    'slug' => ['type' => 'string', 'pattern' => '^[a-z0-9-]+$'],
                    'body' => ['type' => 'string', 'minLength' => 1],
                ],
                'additionalProperties' => false,
            ],
            outputSchema: [
                'type' => 'object',
                'required' => ['created'],
                'properties' => ['created' => ['type' => 'boolean']],
            ],
            requiredPermissions: ['acme.notes.write'],
            mutatesState: true,
            supportsDryRun: true,
        );
    }

    public function execute(array $input, ExecutionContext $context): OperationResult
    {
        if (!$context->dryRun) {
            // Persist state here.
        }

        return new OperationResult(
            data: ['created' => !$context->dryRun],
            dryRun: $context->dryRun,
            diff: ['before' => null, 'after' => $input],
            target: (string) $input['slug'],
            beforeHash: null,
            afterHash: hash('sha256', json_encode($input, JSON_THROW_ON_ERROR)),
        );
    }
}

// ModuleInterface::register():
$builder->autowire(NoteCreateOperation::class, [OperationRegistry::OPERATION_TAG]);

2. phrame.event_subscriber

  • Constant: PhrameCms\Core\Contract\EventSubscriberInterface::SERVICE_TAG
  • Interface: PhrameCms\Core\Contract\EventSubscriberInterface
  • Package: phramecms/core
  • Purpose: Registers prioritized PSR-14 listeners automatically with PhrameCms\Core\Event\ListenerProvider.
php
use PhrameCms\Core\Contract\EventSubscriberInterface;
use PhrameCms\Core\Event\EventSubscription;
use PhrameCms\Entity\Event\EntityPreSaveEvent;

final readonly class CatalogSubscriber implements EventSubscriberInterface
{
    /** @return list<EventSubscription> */
    public function subscriptions(): array
    {
        return [
            new EventSubscription(EntityPreSaveEvent::class, 'onPreSave', priority: 10),
        ];
    }

    public function onPreSave(EntityPreSaveEvent $event): void
    {
        if ($event->entityType === 'catalog' && !isset($event->fields['summary'])) {
            $event->setField('summary', 'Auto-generated summary');
        }
    }
}

// ModuleInterface::register():
$builder->autowire(CatalogSubscriber::class, [EventSubscriberInterface::SERVICE_TAG]);

3. phrame.schema_installer

  • Constant: PhrameCms\Database\Contract\SchemaInstallerInterface::SERVICE_TAG
  • Interface: PhrameCms\Database\Contract\SchemaInstallerInterface
  • Package: phramecms/database
  • Purpose: Discovered by SchemaInstallRunner::installAll() during ./bin/phrame site:install and ./bin/phrame schema:install. Use explicit tag priority if your table has foreign-key or ordering dependencies on another installer (UserSchemaInstaller uses priority 100).
php
use PhrameCms\Database\Contract\ConnectionInterface;
use PhrameCms\Database\Contract\SchemaInstallerInterface;
use PhrameCms\Database\Schema\ColumnType;
use PhrameCms\Database\Schema\TableBlueprint;

final readonly class NoteSchemaInstaller implements SchemaInstallerInterface
{
    public function __construct(private ConnectionInterface $connection) {}

    public function name(): string { return 'acme.notes'; }

    /** @return list<string> */
    public function tables(): array { return ['acme_notes']; }

    public function isInstalled(): bool
    {
        return $this->connection->schema()->hasTable('acme_notes');
    }

    public function install(): void
    {
        if ($this->isInstalled()) {
            return;
        }

        $this->connection->schema()->createTable('acme_notes', static function (TableBlueprint $t): void {
            $t->column('slug', ColumnType::String, length: 128);
            $t->column('body', ColumnType::Text);
            $t->primaryKey('slug');
        });
    }
}

// ModuleInterface::register():
$builder->autowire(NoteSchemaInstaller::class, [SchemaInstallerInterface::SERVICE_TAG]);

4. phrame.field_type

  • Constant: PhrameCms\Entity\Contract\FieldTypeInterface::SERVICE_TAG
  • Interface: PhrameCms\Entity\Contract\FieldTypeInterface
  • Package: phramecms/entity
  • Purpose: Registers a custom field type usable in field_storage.create and compiled into Bundle JSON Schemas.
php
use PhrameCms\Core\Schema\ValidationError;
use PhrameCms\Core\Schema\ValidationResult;
use PhrameCms\Entity\Contract\FieldTypeInterface;
use PhrameCms\Entity\Schema\FieldInstanceDefinition;
use PhrameCms\Entity\Schema\FieldStorageDefinition;

final readonly class MoneyFieldType implements FieldTypeInterface
{
    public function type(): string { return 'money'; }

    public function jsonSchema(FieldStorageDefinition $storage, FieldInstanceDefinition $instance): array
    {
        return [
            'type' => 'object',
            'required' => ['amount_cents', 'currency'],
            'properties' => [
                'amount_cents' => ['type' => 'integer', 'minimum' => 0],
                'currency' => ['type' => 'string', 'pattern' => '^[A-Z]{3}$'],
            ],
            'additionalProperties' => false,
        ];
    }

    public function validate(mixed $value, FieldStorageDefinition $storage, FieldInstanceDefinition $instance): ValidationResult
    {
        if (!is_array($value) || !is_int($value['amount_cents'] ?? null) || !is_string($value['currency'] ?? null)) {
            return ValidationResult::invalid([new ValidationError('', 'Invalid money object.', 'type')]);
        }

        return ValidationResult::valid();
    }

    public function normalize(mixed $value, FieldStorageDefinition $storage): mixed { return $value; }
    public function denormalize(mixed $value, FieldStorageDefinition $storage): mixed { return $value; }
}

// ModuleInterface::register():
$builder->autowire(MoneyFieldType::class, [FieldTypeInterface::SERVICE_TAG]);

5. phrame.route_provider

  • Constant: PhrameCms\Routing\Contract\RouteProviderInterface::SERVICE_TAG
  • Interface: PhrameCms\Routing\Contract\RouteProviderInterface
  • Package: phramecms/routing
  • Purpose: Adds HTTP routes to HttpKernel's RouteCollection.
php
use PhrameCms\Admin\AdminModule;
use PhrameCms\Routing\Contract\RouteProviderInterface;
use PhrameCms\Routing\Route;
use PhrameCms\Routing\RouteCollection;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class AcmeRouteProvider implements RouteProviderInterface
{
    public function __construct(private AcmeController $controller) {}

    public function registerRoutes(RouteCollection $routes): void
    {
        $routes->add(new Route(
            name: 'acme.health',
            methods: ['GET'],
            path: '/acme/health',
            handler: fn(ServerRequestInterface $r): ResponseInterface => $this->controller->health($r),
            meta: ['public' => true],
        ));

        $routes->add(new Route(
            name: 'acme.admin',
            methods: ['GET'],
            path: '/admin/acme',
            handler: fn(ServerRequestInterface $r): ResponseInterface => $this->controller->adminPage($r),
            middlewares: [AdminModule::SESSION_AUTH_MIDDLEWARE_SERVICE],
            meta: ['auth' => 'session'],
        ));
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeRouteProvider::class, [RouteProviderInterface::SERVICE_TAG]);

6. phrame.http_middleware

  • Constant: PhrameCms\Routing\HttpKernel::MIDDLEWARE_TAG
  • Interface: Psr\Http\Server\MiddlewareInterface
  • Package: phramecms/routing
  • Purpose: Adds global PSR-15 middleware to HttpKernel. Use $builder->tag(..., priority: ...) to position middleware relative to built-in middleware (AdminSecurityHeadersMiddleware at 200, BearerAuthMiddleware at 100).
php
use PhrameCms\Routing\HttpKernel;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

final readonly class CorrelationHeaderMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);
        $id = $request->getAttribute(HttpKernel::CORRELATION_ID_ATTRIBUTE);

        return is_string($id) ? $response->withHeader('X-Correlation-Id', $id) : $response;
    }
}

// ModuleInterface::register():
$builder->autowire(CorrelationHeaderMiddleware::class);
$builder->tag(CorrelationHeaderMiddleware::class, HttpKernel::MIDDLEWARE_TAG, priority: 150);

7. phrame.config_schema

  • Constant: PhrameCms\Config\Contract\ConfigSchemaProviderInterface::SERVICE_TAG
  • Interface: PhrameCms\Config\Contract\ConfigSchemaProviderInterface
  • Package: phramecms/config
  • Purpose: Enforces JSON Schema (draft 2020-12) validation for all config objects whose names start with prefix(). Also automatically surfaced in the phrame://schema/config MCP resource.
php
use PhrameCms\Config\Contract\ConfigSchemaProviderInterface;

final readonly class AcmeConfigSchemaProvider implements ConfigSchemaProviderInterface
{
    public function prefix(): string { return 'acme.'; }

    public function schema(): array
    {
        return [
            'type' => 'object',
            'required' => ['enabled'],
            'properties' => ['enabled' => ['type' => 'boolean']],
            'additionalProperties' => false,
        ];
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeConfigSchemaProvider::class, [ConfigSchemaProviderInterface::SERVICE_TAG]);

8. phrame.cli_command

  • Constant: PhrameCms\Cli\CliApplication::COMMAND_TAG
  • Interface: PhrameCms\Cli\Contract\CommandInterface
  • Package: phramecms/cli
  • Purpose: Registers a first-class CLI command runnable via ./bin/phrame <name>, automatically supporting --json via SymfonyCommandAdapter.
php
use PhrameCms\Cli\CliApplication;
use PhrameCms\Cli\Contract\CommandInterface;
use PhrameCms\Cli\ExitCode;
use PhrameCms\Cli\Input\CliInput;
use PhrameCms\Cli\Output\CliOutputInterface;

final readonly class AcmeStatusCommand implements CommandInterface
{
    public function name(): string { return 'acme:status'; }
    public function description(): string { return 'Print Acme module status'; }
    public function arguments(): array { return []; }
    public function options(): array { return []; }

    public function execute(CliInput $input, CliOutputInterface $output): ExitCode
    {
        $output->isJsonMode() ? $output->json(['ok' => true]) : $output->writeln('Acme OK');

        return ExitCode::Ok;
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeStatusCommand::class, [CliApplication::COMMAND_TAG]);

9. phrame.mcp_resource_provider

  • Constant: PhrameCms\Mcp\Contract\McpResourceProviderInterface::SERVICE_TAG
  • Interface: PhrameCms\Mcp\Contract\McpResourceProviderInterface
  • Package: phramecms/mcp
  • Purpose: Exposes read-only phrame://... resources to AI agents via MCP resources/list and resources/read. In resources/read, McpServer dispatches to the first provider (in descending tag priority order) where supports($uri) returns true.
php
use PhrameCms\Core\Contract\ActorInterface;
use PhrameCms\Core\Contract\PolicyEnforcerInterface;
use PhrameCms\Core\Exception\AuthorizationException;
use PhrameCms\Mcp\Contract\McpResourceProviderInterface;
use PhrameCms\Mcp\Exception\ResourceNotFoundException;
use PhrameCms\Mcp\Protocol\ResourceContent;
use PhrameCms\Mcp\Protocol\ResourceDefinition;

final readonly class AcmeResourceProvider implements McpResourceProviderInterface
{
    public const string URI = 'phrame://acme/status';

    public function __construct(private PolicyEnforcerInterface $policy) {}

    public function listResources(ActorInterface $actor): array
    {
        try {
            $this->policy->assertAllowed($actor, 'mcp.resource.read', ['acme.read']);
        } catch (AuthorizationException) {
            return [];
        }

        return [new ResourceDefinition(self::URI, 'Acme Status', 'Current module status', 'application/json')];
    }

    public function supports(string $uri): bool { return $uri === self::URI; }

    public function read(string $uri, ActorInterface $actor): ResourceContent
    {
        if (!$this->supports($uri)) {
            throw ResourceNotFoundException::forUri($uri);
        }

        $this->policy->assertAllowed($actor, 'mcp.resource.read', ['acme.read']);

        return new ResourceContent(self::URI, 'application/json', '{"status":"ok"}');
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeResourceProvider::class, [McpResourceProviderInterface::SERVICE_TAG]);

10. phrame.admin_menu

  • Constant: PhrameCms\Admin\Contract\AdminMenuProviderInterface::SERVICE_TAG
  • Interface: PhrameCms\Admin\Contract\AdminMenuProviderInterface
  • Package: phramecms/admin
  • Purpose: Adds permission-filtered sidebar navigation entries to /admin. Ordering is governed by AdminMenuItem::$weight within each $group.
php
use PhrameCms\Admin\Contract\AdminMenuProviderInterface;
use PhrameCms\Admin\Navigation\AdminMenuItem;

final readonly class AcmeMenuProvider implements AdminMenuProviderInterface
{
    /** @return list<AdminMenuItem> */
    public function items(): array
    {
        return [
            new AdminMenuItem(
                id: 'acme.dashboard',
                label: 'Acme',
                path: '/admin/acme',
                group: 'Extensions',
                weight: 50,
                requiredPermission: 'acme.read',
            ),
        ];
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeMenuProvider::class, [AdminMenuProviderInterface::SERVICE_TAG]);

11. phrame.admin_theme

  • Constant: PhrameCms\Admin\Contract\AdminThemeInterface::SERVICE_TAG
  • Interface: PhrameCms\Admin\Contract\AdminThemeInterface
  • Package: phramecms/admin
  • Purpose: Registers a pluggable Admin UI theme selectable at /admin/appearance or in config/sync/admin.settings.json.
php
use PhrameCms\Admin\Contract\AdminThemeInterface;

final readonly class AcmeDarkTheme implements AdminThemeInterface
{
    public function id(): string { return 'acme_dark'; }
    public function label(): string { return 'Acme Dark'; }
    public function templatePaths(): array { return [__DIR__ . '/templates']; }
    public function assets(): array
    {
        return [
            'acme-dark.css' => ['path' => __DIR__ . '/assets/acme-dark.css', 'contentType' => 'text/css; charset=utf-8'],
        ];
    }
    public function stylesheets(): array { return ['/admin/assets/admin.css', '/admin/assets/acme-dark.css']; }
    public function scripts(): array { return ['/admin/assets/admin.js']; }
    public function variables(): array { return ['accent' => '#0ea5e9']; }
}

// ModuleInterface::register():
$builder->autowire(AcmeDarkTheme::class, [AdminThemeInterface::SERVICE_TAG]);

12. phrame.admin_template_namespace

  • Constant: PhrameCms\Admin\Contract\AdminTemplateNamespaceProviderInterface::SERVICE_TAG
  • Interface: PhrameCms\Admin\Contract\AdminTemplateNamespaceProviderInterface
  • Package: phramecms/admin
  • Purpose: Registers a module-scoped Twig namespace (matching /\A[a-z][a-z0-9_]*\z/, excluding admin_base) so custom pages and widgets can render @my_module/... templates while supporting project overrides under templates/admin/modules/<namespace>/.
php
use PhrameCms\Admin\Contract\AdminTemplateNamespaceProviderInterface;

final readonly class AcmeTemplateNamespaceProvider implements AdminTemplateNamespaceProviderInterface
{
    /** @return array<string, string> */
    public function namespaces(): array
    {
        return ['acme' => __DIR__ . '/templates'];
    }
}

// ModuleInterface::register():
$builder->autowire(AcmeTemplateNamespaceProvider::class, [AdminTemplateNamespaceProviderInterface::SERVICE_TAG]);

13. phrame.admin_field_widget

  • Constant: PhrameCms\Admin\Contract\FieldFormWidgetInterface::SERVICE_TAG
  • Interface: PhrameCms\Admin\Contract\FieldFormWidgetInterface
  • Package: phramecms/admin
  • Purpose: Customizes /admin/content/... HTML form rendering, value formatting, and POST submission coercion for any built-in or custom field type. Widgets are evaluated in descending tag priority order; the first widget whose supports($fieldType) returns true wins.
php
use PhrameCms\Admin\Contract\FieldFormWidgetInterface;
use PhrameCms\Admin\Form\FieldCoercionResult;
use PhrameCms\Admin\Form\FormFieldDescriptor;
use PhrameCms\Core\Schema\ValidationError;
use PhrameCms\Entity\Schema\FieldInstanceDefinition;
use PhrameCms\Entity\Schema\FieldStorageDefinition;

final readonly class MoneyFieldWidget implements FieldFormWidgetInterface
{
    public function supports(string $fieldType): bool { return $fieldType === 'money'; }
    public function inputType(FieldStorageDefinition $storage, FieldInstanceDefinition $instance): string { return 'text'; }
    public function template(): ?string { return '@acme/widgets/money.html.twig'; }

    public function coerce(mixed $rawValue, FormFieldDescriptor $descriptor, string $path): FieldCoercionResult
    {
        if (!is_string($rawValue) || trim($rawValue) === '') {
            return FieldCoercionResult::empty();
        }
        if (preg_match('/\A(\d+)(?:\.(\d{2}))?\s+([A-Z]{3})\z/', trim($rawValue), $m) !== 1) {
            return FieldCoercionResult::errors([new ValidationError($path, 'Expected "19.99 USD".', 'format')]);
        }

        return FieldCoercionResult::value([
            'amount_cents' => ((int) $m[1] * 100) + ($m[2] !== '' ? (int) $m[2] : 0),
            'currency' => $m[3],
        ]);
    }

    public function formatForForm(mixed $value, FormFieldDescriptor $descriptor): string
    {
        return is_array($value) && is_int($value['amount_cents'] ?? null) && is_string($value['currency'] ?? null)
            ? sprintf('%d.%02d %s', intdiv($value['amount_cents'], 100), $value['amount_cents'] % 100, $value['currency'])
            : '';
    }
}

// ModuleInterface::register():
$builder->autowire(MoneyFieldWidget::class);
$builder->tag(MoneyFieldWidget::class, FieldFormWidgetInterface::SERVICE_TAG, priority: 10);