Installation via Composer
Add the bundle to your Laravel project (via Symfony bridge or standalone) by requiring it in composer.json:
composer require symfony/distribution-bundle
Note: Since Laravel doesn’t natively support Symfony bundles, use a bridge like symfony/var-dumper or integrate via a custom service provider.
First Use Case: Bootstrap a Symfony-like Structure
Use the bundle’s Sensio\Bundle\DistributionBundle\SensioDistributionBundle to scaffold a Laravel project with Symfony conventions (e.g., app/config, web/app.php). Override Laravel’s default structure by:
php artisan vendor:publish --provider="Sensio\Bundle\DistributionBundle\SensioDistributionBundle" --tag=config
config/app.php to mirror Symfony’s AppKernel.php logic (e.g., bundle registration).Key Files to Inspect
Resources/config/config.xml: Default Symfony distribution config (adapt for Laravel).SensioDistributionBundle.php: Entry point for bundle logic.Bundle Registration Extend Laravel’s service container to load Symfony bundles:
// config/app.php
'providers' => [
// ...
Sensio\Bundle\DistributionBundle\SensioDistributionBundle::class,
// Custom bridge provider to adapt Symfony services to Laravel
];
Configuration Overrides Use Laravel’s config system to override Symfony defaults:
// config/sensio_distribution.php
return [
'framework' => [
'router' => [
'resource' => '%kernel.root_dir%/config/routing.yml', // Symfony-style routing
'strict_requirements' => env('ROUTING_STRICT', true),
],
],
];
Asset Management Leverage Symfony’s asset system for Laravel:
// app/Providers/AppServiceProvider.php
use Sensio\Bundle\FrameworkExtraBundle\Asset\Packages;
public function register()
{
$this->app->singleton(Packages::class, function () {
return new Packages($this->app['kernel']->getRootDir() . '/public');
});
}
Debugging Tools Integrate Symfony’s profiler (e.g., WebProfilerBundle) for Laravel:
composer require symfony/web-profiler-bundle
Configure in config/app.php and use middleware to inject the toolbar.
Environment-Specific Configs
Use Laravel’s .env to toggle Symfony features:
APP_DEBUG=true
SENSIO_DISTRIBUTION_ENABLED=true
Namespace Collisions
src/ and App/ namespaces. In Laravel, alias these in composer.json:
"autoload": {
"psr-4": {
"App\\": "app/",
"Sensio\\": "vendor/sensio/"
}
}
use statements with fully qualified names (e.g., Sensio\Bundle\...) to avoid ambiguity.Routing Conflicts
routing.yml may clash with Laravel’s routes/web.php. Merge them:
# config/routing.yml (Symfony-style)
app:
resource: "@AppBundle/Resources/config/routing.yml"
prefix: /
RouteServiceProvider to preload Symfony routes:
public function boot()
{
parent::boot();
$loader = new YamlFileLoader($this->app['filesystem'], new FileLocator());
$loader->load($this->app['kernel']->getRootDir() . '/config/routing.yml');
}
Dependency Injection Quirks
ContainerInterface) differs from Laravel’s. Bridge them:
$symfonyContainer = new SymfonyContainer();
$this->app->instance('symfony.container', $symfonyContainer);
symfony/dependency-injection to create a hybrid container.Asset Pipeline Issues
asset() helper may not resolve Laravel’s public/ path. Override:
// app/Providers/AppServiceProvider.php
use Sensio\Bundle\FrameworkExtraBundle\Asset\AssetManager;
public function boot()
{
$assetManager = $this->app->make(AssetManager::class);
$assetManager->setPublicPath($this->app->basePath() . '/public');
}
Debugging the Profiler
APP_DEBUG=true in .env.$this->app->middleware(Sensio\Bundle\FrameworkExtraBundle\EventListener\WebProfilerMiddleware::class);
php artisan cache:clear
php artisan config:clear
Extension Points
App\SensioBundle).EventServiceProvider:
protected $listen = [
'kernel.request' => [
'Sensio\Bundle\FrameworkExtraBundle\EventListener\RouterListener::onKernelRequest',
],
];
symfony/twig-bridge.Performance Notes
composer dump-autoload --optimize
composer install --no-dev
How can I help you explore Laravel packages today?