symfony/flex
Symfony Flex streamlines Symfony app setup by automatically enabling bundles, configuring recipes, and managing Composer packages. It helps bootstrap projects faster with sensible defaults, environment config, and smooth upgrades across Symfony versions.
Install Flex in a Symfony Project
Ensure your project has composer.json with "extra": { "symfony": { ... } } or is a Symfony skeleton. Flex is pre-installed in Symfony 4+ skeletons.
composer require symfony/flex # Only needed if not using a Symfony skeleton
First Use Case: Installing a Bundle
Require a Symfony bundle (e.g., doctrine/doctrine-bundle) and let Flex handle the rest:
composer require doctrine/doctrine-bundle
doctrine/doctrine-bundle recipe).config/packages/doctrine.yaml, environment variables, or scripts).AppKernel registration (Symfony 4+) or AppBundle creation needed.Verify Configuration
Check config/packages/ for new files. Run:
php bin/console debug:config doctrine # Confirm bundle is enabled
Explore Recipes
Browse Symfony Recipes or a bundle’s RECIPES.md (if provided) to understand what Flex applies.
composer require with Flex’s auto-configuration:
composer require api platform/core
api_platform.yaml config, Doctrine mappings), and updates config/bundles.php.config/packages/override/ (Symfony 4+) or merge configs manually.composer require symfony/webpack-encore-pack
.env.local variables for bundles like monolog).config/packages/dev/doctrine.yaml for environment-specific tweaks.composer.json (e.g., post-install-cmd for migrations):
"scripts": {
"post-install-cmd": [
"@symfony-scripts",
"DoctrineMigrations\\Migrations\\MigrationsGenerator:generate"
]
}
composer post-install
composer update api-platform/core
doctrine.yaml).Laravel-Specific Adaptations:
config/ and migrations/ auto-loading (e.g., spatie/laravel-package-tools).PackageServiceProvider).composer.json could define:
"extra": {
"laravel": {
"providers": ["Vendor\\Package\\ServiceProvider"],
"aliases": {
"Package": "Vendor\\Package\\Facades\\Package"
}
}
}
Debugging Recipe Issues:
var/cache/dev/app_recipes.json for applied recipes.composer why-not <package> to diagnose dependency conflicts.Extending Recipes:
RECIPES.md in your repo (see Symfony Recipe Guide).Recipe Conflicts
doctrine.yaml).config/packages/override/ to merge configs or manually resolve conflicts.composer why-not symfony/orm-pack to check dependency issues.Caching Quirks
config/packages/ aren’t reflected due to cached recipes.rm -rf var/cache/dev/app_recipes.json
composer dump-autoload
Legacy Symfony (3.x) Limitations
AppKernel).AppKernel.php if using Symfony 3.Overzealous Scripts
composer install (e.g., migrations).composer.json:
"scripts": {
"post-install-cmd": [
"@symfony-scripts --no-scripts"
]
}
Pack Compatibility
web-pack + api-pack) may cause conflicts.composer show --tree | grep recipe
composer why symfony/orm-pack
composer config extra.symfony.enable-flex false
(Re-enable with true after debugging.)Custom Recipes
RECIPES.md in your package’s root:
# MyPackage Recipe
## Config
- Copy `config/my_package.php` to `config/packages/my_package.yaml`
## Scripts
- Add to `composer.json`:
```json
"scripts": {
"post-install-cmd": [
"MyPackage\\Installer\\Installer::postInstall"
]
}
Hook into Flex Events
symfony/flex’s post-install events in your package’s composer.json:
"scripts": {
"post-install-cmd": [
"@symfony-scripts",
"Vendor\\Package\\Composer\\ScriptHandler::postInstall"
]
}
Laravel Package Auto-Loading
spatie/laravel-package-tools to auto-publish configs:
// config/my_package.php
return [
'enabled' => env('MY_PACKAGE_ENABLED', true),
];
config/my_package.php on install.config/packages/_default/ for shared configs across environments.var/cache/dev/app_recipes.json to speed up builds.ln -s vendor/symfony/orm-pack/Resources/stubs/config/doctrine.yaml config/packages/doctrine.yaml
How can I help you explore Laravel packages today?