Skip to content

Configuration

friendsofmago/mago-symfony reads configuration from worker environment variables, auto-discovered container files, and standard Mago [analyzer] settings.

Environment variables

Pass these variables in [extension-hosts.symfony] environment in mago.toml or export them in the shell before running mago analyze:

Variable Effect Default
MAGO_SYMFONY_CONTAINER_XML Path to a compiled Symfony container XML dump, such as var/cache/dev/App_KernelDevDebugContainer.xml. Auto-discovers var/cache/dev/*Container.xml and var/cache/test/*Container.xml in sorted path order.
MAGO_SYMFONY_CONTAINER_MAP Path to a JSON service and parameter map. If the path ends with .xml, the loader parses it as a compiled container XML dump. Auto-discovers .mago/symfony-container.json when present.
MAGO_SYMFONY_USER_CLASS Fully qualified name of a class or interface that implements Symfony\Component\Security\Core\User\UserInterface. Narrows Security getUser() to that configured type or null, such as App\Entity\User\|null. Unset. getUser() keeps Symfony's declared return type.
MAGO_SYMFONY_STRICT_CONTAINER_SERVICES Enables symfony/unknown-service-id when set to 1, true, yes, or on, ignoring case. Requires a loaded XML container dump. Disabled.

Container metadata resolution order

ServiceClassMap::fromOptions() resolves container metadata in this order and stops at the first matching source:

  1. The explicit containerXml argument passed to SymfonyExtension::plugins().
  2. The explicit containerMap argument passed to SymfonyExtension::plugins().
  3. The MAGO_SYMFONY_CONTAINER_XML environment variable.
  4. The MAGO_SYMFONY_CONTAINER_MAP environment variable.
  5. .mago/symfony-container.json, when auto-discovery is enabled and the file is readable.
  6. The first readable match in var/cache/dev/*Container.xml and then var/cache/test/*Container.xml, sorted by path, when auto-discovery is enabled.

When no container dump or JSON map is loaded, literal class-name service IDs resolve to the declared class or interface in the analyzed codebase. Non-class string service IDs such as 'logger' keep Symfony's declared ?object return type.

JSON container map format

A JSON map file must decode to a JSON object. Top-level string entries map service IDs directly to class or interface names. Optional services and parameters objects organize services and scalar, list, or map parameters explicitly:

{
    "services": {
        "app.mailer": "App\\Mail\\Mailer",
        "logger": "Psr\\Log\\LoggerInterface"
    },
    "parameters": {
        "app.locale": "en",
        "app.retries": 3,
        "app.features": ["search", "export"]
    }
}

Mapped class or interface names must exist in Mago's analyzed codebase or [source] includes. The loader strips leading backslashes automatically.

Analyzer plugins

SymfonyExtension::create() registers two analyzer plugins, both enabled by default:

Plugin identifier Class Role
symfony MagoSymfony\Analyzer\SymfonyPlugin Container services and parameters, Console checks, HTTP, Form, Serializer, Messenger, Security, lifecycle initializers, and entry points.
symfony-tree-builder-root MagoSymfony\Analyzer\TreeBuilderRootTypePlugin TreeBuilder::getRootNode(), fluent node builder chains, return issue filtering, and invalid root node method checks.

The TreeBuilder plugin runs separately so provider memoization stays enabled on symfony.

Suppressing diagnostics

Silence a diagnostic across the project in mago.toml:

[analyzer]
ignore = [
    "symfony/private-service-access",
    { code = "symfony/unknown-console-option", in = "src/Legacy/" },
]

Silence a single occurrence inline:

// @mago-ignore analysis:symfony/private-service-access
$container->get('app.private_service');

See Diagnostics for all six diagnostic codes.

Compatibility and SemVer policy

friendsofmago/mago-symfony follows Semantic Versioning 2.0.0 starting at 1.0.0.

  • Public PHP API. MagoSymfony\SymfonyExtension::create() and MagoSymfony\SymfonyExtension::plugins() are the supported PHP entry points. All classes under MagoSymfony\Analyzer are @internal and may change without a major version bump.
  • Worker entry points. resources/worker.php and bin/mago-symfony-worker are supported. Standard output carries the Mago extension protocol. Diagnostics and warnings go to standard error.
  • Diagnostic codes. symfony/private-service-access, symfony-tree-builder-root/invalid-root-node-method, symfony/unknown-console-argument, symfony/unknown-console-option, and symfony/invalid-console-input-definition are enabled by default. symfony/unknown-service-id is opt-in. Adding a new default-on diagnostic is a minor bump. Changing the meaning of a code, removing a code, or enabling an opt-in diagnostic by default is a major bump.
  • Supported floors. PHP ^8.1, Mago ^1.60.2, and Symfony ^6.4 || ^7.0. CI tests Mago 1.60.2, 1.61.0, 1.62.0, and latest.