symfony/framework-bundle
FrameworkBundle tightly integrates Symfony components into the full-stack Symfony framework, providing the core configuration, service container, routing, and bundle infrastructure that powers Symfony applications out of the box.
Installation:
composer require symfony/framework-bundle
Typically pulled in automatically via symfony/symfony or symfony/flex.
v8.1.8 note: FrameworkBundle now requires
symfony/dependency-injection: ^8.1.8. If you pin DependencyInjection explicitly, bump both together:composer update symfony/framework-bundle symfony/dependency-injection --with-dependencies.
First Use Case:
config/bundles.php). No manual configuration needed for basic usage.use Symfony\Component\HttpKernel\KernelInterface;
public function __construct(private KernelInterface $kernel) {}
config/routes.yaml or via attributes:
# config/routes.yaml
app_homepage:
path: /
controller: App\Controller\HomeController::index
Where to Look First:
config/packages/framework.yaml (generated by Flex).config/bundles.php.Service Configuration:
framework.yaml:
# config/packages/framework.yaml
framework:
session:
handler_id: cache.app
http_cache:
invalidation:
enabled: true
config/packages/dev/framework.yaml, config/packages/prod/framework.yaml.Dependency Injection:
RequestStack, RouterInterface, HttpClientInterface).#[Tag('kernel.event_listener', ['event' => 'kernel.request'])]
class MyListener {}
debug:container. If you previously saw (closure) / errors while inspecting such services, re-run:
php bin/console debug:container App\Service\MyService
Routing and Controllers:
#[Route('/profile', name: 'app_profile')]
public function profile(): Response {}
framework.webhook.routing keys if you see it.HTTP Client:
http_client push:
framework:
http_client:
default_options:
# HTTP/2 push no longer applies to the default client
Serialization:
Testing:
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class MyTest extends KernelTestCase {
public function testSomething(): void {
self::bootKernel();
$client = static::createClient();
$client->request('GET', '/');
}
}
static::getContainer() in modern versions.Event Listeners / Subscribers:
services:
App\EventListener\MyListener:
tags: ['kernel.event_listener']
App\EventListener\MySubscriber:
tags: ['kernel.event_subscriber']
Console Commands:
#[AsCommand(name: 'app:greet')]
class GreetCommand extends Command {}
Register with tags: ['console.command'].
Configuration Reference:
php bin/console config:dump-reference framework
BundleInterface / extend AbstractBundle to wrap FrameworkBundle features.%env(APP_SECRET)% in config, values in .env / .env.local.APP_DEBUG=1 + Web Profiler at /_profiler.DotenvVault, see the back-reference fix in Gotchas before rotating secrets.Composer / Version Constraints (new in 8.1.8):
symfony/framework-bundle 8.1.8 requires symfony/dependency-injection ^8.1.8. A partial upgrade (composer update symfony/framework-bundle) without updating DependencyInjection will fail resolution. Use --with-dependencies, or bump both entries in composer.json together.HTTP/2 Push Silently Ignored (new in 8.1.8):
Serializer Metadata Cache in Debug Mode (new in 8.1.8):
php bin/console cache:clear
Don't waste time debugging the serializer config itself — it's the cache.DotenvVault Back-References (new in 8.1.8):
$OTHER_VAR inside a sealed value) from being corrupted on decrypt. If you sealed such values with an older 8.1.x, re-verify them and re-seal if the decrypted value looks mangled:
php bin/console secrets:list
Caching Quirks:
php bin/console cache:warmup after config changes.KernelTestCase handles shutdown.Routing Issues:
use_attribute_as_key are historical; that's a YAML loader option, not a router toggle.debug:router.Dependency Injection:
autowire: false + explicit bindings, or a lazy service.services.yaml and that the class is in the autodiscovery path.Session Handling:
$session = new Session();
$session->setStorage(new MockSessionStorage());
static::getContainer()->set('session', $session);
cookie_lifetime explicitly for session cookies.Configuration Merging:
config/packages/overrides.yaml.config:dump-reference to check the real shape before guessing.Testing Gotchas:
self::ensureKernelShutdown() when testing HTTP cache.Console Commands:
symfony/console must be installed; the command data collector only exists when it is.php bin/console debug:container # now handles env-closure args (8.1.8 fix)
php bin/console debug:container App\MyService
php bin/console debug:router
php bin/console debug:env
php bin/console debug:config framework
php bin/console debug:event-dispatcher
php bin/console debug:serializer # check mapping/attribute metadata
ConfiguratorInterface for config validation/normalisation.EventSubscriberInterface for kernel.request, kernel.response, etc.HttpKernelInterface for cross-cutting request/response handling.PassConfig).LoaderInterface for dynamic routes.cache.app for session storage to offload the DB.framework.http_cache for shared caching of anonymous responses.framework.csrf_protection.enabled: true.framework:
http_client:
headers:
Strict-Transport-Security: "max-age=31536000; includeSubDomains"
nelmio/cors-bundle.How can I help you explore Laravel packages today?