Install¶
Follow these steps to install friendsofmago/mago-symfony and run mago analyze on a Symfony project.
Check prerequisites¶
Verify that your environment meets these requirements:
- PHP 8.1 or newer with
ext-tokenizer. ext-dom,ext-libxml, andext-xmlreaderwhen loading compiled Symfony container XML dumps.carthage-software/mago^1.60.2.- Symfony
^6.4 || ^7.0.
Install the package¶
Install the extension as a development dependency:
composer require --dev friendsofmago/mago-symfony
Register the worker in mago.toml¶
Create or edit mago.toml next to composer.json. Add Symfony and PSR contracts to [source] includes, then register the worker under [extension-hosts.symfony]:
[source]
paths = ["src"]
includes = ["vendor/symfony", "vendor/psr"]
[extension-hosts.symfony]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/friendsofmago/mago-symfony/resources/worker.php"]
workers = 1
To pass container dumps, a Security user class, or strict service checks, add an environment table to [extension-hosts.symfony]:
[extension-hosts.symfony]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/friendsofmago/mago-symfony/resources/worker.php"]
workers = 1
environment = {
MAGO_SYMFONY_CONTAINER_XML = "var/cache/dev/App_KernelDevDebugContainer.xml",
MAGO_SYMFONY_USER_CLASS = "App\\Entity\\User",
MAGO_SYMFONY_STRICT_CONTAINER_SERVICES = "1",
}
Omit keys you do not need so defaults and container auto-discovery stay active. See Configuration for every environment variable.
Configure source includes¶
Mago reads files under [source] includes to resolve Symfony method signatures without reporting issues in vendor code.
- Listing
"vendor/symfony"covers every installed Symfony package. - If you list individual Symfony packages instead, include every package your application calls plus
"vendor/psr". - For standalone Symfony Console applications without FrameworkBundle, exclude
vendor/symfony/framework-bundlefromincludesso default option checks matchSymfony\Component\Console\Application.
Validate and run analysis¶
Use the Composer-installed binary so the CLI and SDK protocol versions match:
vendor/bin/mago extension validate
vendor/bin/mago analyze
Use a custom vendor path¶
If vendor/ is not next to mago.toml, update both [source] includes and the path to worker.php in [extension-hosts.symfony] to match:
[source]
includes = ["../../vendor/symfony", "../../vendor/psr"]
[extension-hosts.symfony]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "../../vendor/friendsofmago/mago-symfony/resources/worker.php"]
workers = 1
Next steps¶
- Set container and diagnostic options in Configuration.
- Inspect worker behavior in The worker.
- Combine multiple extensions in one worker process in Composing extensions.