Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Framework Bundle Laravel Package

symfony/framework-bundle

Symfony FrameworkBundle tightly integrates Symfony components into the full-stack framework, providing core framework services and configuration. Part of the main Symfony repository; see official docs for contributing, issues, and pull requests.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Steps
1. **Installation**:
   ```bash
   composer require symfony/framework-bundle:^8.1.0-BETA3

Note: This is a beta release (v8.1.0-BETA3). Ensure compatibility with Symfony 8.1+ and test thoroughly in staging.

  1. First Use Case:

    • Bootstrapping the Kernel: Initialize via App\Kernel (extends Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait or AbstractKernel).
      • New: Kernel now enforces stricter type hints for constructor arguments (e.g., ContainerInterface must be explicitly typed).
    • Configuration: Define settings in config/packages/framework.yaml (e.g., secret, http_client, router).
      • New: Added framework.http_client.throw config to control exception handling for HTTP client failures (default: false).
    • Routing: Use attribute routing (#[Route]) or YAML/XML files. The bundle auto-registers routes via Kernel::getProjectDir().
      • Fix: Resolved edge cases where route priorities were incorrectly calculated (affects YAML-based routes).
  2. Where to Look First:

    • config/packages/framework.yaml: Core framework settings (new: http_client.throw).
    • src/Kernel.php: Kernel class (now requires explicit MicroKernelTrait extension; check for new constructor type hints).
    • config/routes/: Routing definitions (prefer attributes for Symfony 8.1+).
    • tests/: Use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase (ensure bootKernel() is called in setUp() for beta stability).

Implementation Patterns

Core Workflows

  1. Dependency Injection (DI) and Services:

    • Auto-wiring: Services annotated with #[Autowire] or tagged are auto-discovered. For Symfony 8.1+, ensure:
      # config/services.yaml
      parameters:
          kernel.secret: '%env(APP_SECRET)%'
      framework:
          autowire: true
          auto_mapping: true
          container.dumper.inline_class_loader: true  # New: Improves dev performance
      
    • Compiler Passes: Extend Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface for container modifications.
      • Fix: Beta includes fixes for circular references in compiler passes (test thoroughly).
    • Service Dumping: Use php bin/console debug:container or php bin/console cache:dump to rebuild the container.
      • New: Added --format=json flag to debug:container for machine-readable output.
  2. Routing:

    • Attribute Routing: Prefer #[Route] over annotations (Symfony 8.1+):
      #[Route('/profile', name: 'app_profile', methods: ['GET', 'HEAD'])]
      public function profile(): Response { ... }
      
      • Fix: Resolved issue where methods attribute was ignored in some edge cases.
    • Dynamic Routes: Use parameters and requirements in YAML:
      # config/routes.yaml
      app_homepage:
          path: /{page}
          controller: App\Controller\PageController::index
          requirements:
              page: \d+
          defaults:
              _locale: '%locale%'  # New: Supports parameterized defaults
      
    • Route Caching: Enable via:
      framework:
          router:
              cache_warmup: true
              route_cache_warmup: true  # New: Separate config for route cache
      
  3. HTTP Request/Response Handling:

    • Request Handling: Inject Symfony\Component\HttpFoundation\Request:
      public function index(Request $request): Response {
          $query = $request->query->get('q');
          $this->denyAccessUnlessGranted('ROLE_USER');  # New: Shortcut for security checks
      }
      
    • Response Customization: Use Symfony\Component\HttpFoundation\Response or shortcuts:
      return $this->json(['data' => 'value'], 200, [], ['Cache-Control' => 'public']);
      return new RedirectResponse('/login', 302);
      
      • New: Added Response::createFromContent() factory method for easier response creation.
  4. Configuration Management:

    • Environment Variables: Use %env() in framework.yaml:
      framework:
          secret: '%env(APP_SECRET)%'
          http_client:
              timeout: '%env(int:HTTP_CLIENT_TIMEOUT)%'  # New: Type-casting support
      
    • Parameter Bag: Access via $this->getParameter('param_name') or $container->getParameter('param_name').
      • Fix: Resolved issue where boolean parameters were not parsed correctly in some cases.
    • Debug Mode: Toggle in .env (APP_DEBUG=1) or override in Kernel::isDebug().
      • New: Debug mode now logs deprecation warnings to error_log by default.
  5. Testing:

    • Functional Tests: Extend KernelTestCase:
      use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
      
      class MyTest extends KernelTestCase {
          protected function setUp(): void {
              parent::setUp();
              self::bootKernel();  // Critical for beta stability
          }
      
          public function testHomepage() {
              $client = static::createClient();
              $client->request('GET', '/');
              $this->assertResponseIsSuccessful();
              $this->assertSelectorTextContains('h1', 'Welcome');  # New: Assertion helper
          }
      }
      
    • Mocking Services: Use self::$container->get('service')->method('...')->willReturn(...).
      • New: Added createMockBuilder() helper to KernelTestCase for easier mocking.
    • Cache Warmup: Call $client->getContainer()->get('kernel')->warmup() before tests.
      • Fix: Warmup now handles circular dependencies more gracefully.
  6. Event Listeners/Subscribers:

    • Kernel Events: Listen to KernelEvents::REQUEST, KernelEvents::TERMINATE, etc.:
      #[AsEventListener(event: KernelEvents::REQUEST, method: 'onKernelRequest', priority: 10)]
      public function onKernelRequest(RequestEvent $event): void {
          if (!$event->isMainRequest()) {
              return;
          }
          $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
      }
      
    • Dependency Injection: Tag services with kernel.event_listener:
      #[Tag('kernel.event_listener')]
      class MyListener { ... }
      
      • Fix: Resolved issue where event listeners with no priority were not sorted correctly.
  7. Console Integration:

    • Commands: Create commands in src/Command/ and tag them:
      #[AsCommand(name: 'app:greet', description: 'Greets a user')]
      class GreetCommand extends Command {
          protected function execute(InputInterface $input, OutputInterface $output): int {
              $output->writeln(sprintf('Hello %s!', $input->getArgument('name')));
              return Command::SUCCESS;
          }
      }
      
      • New: Added #[AsCommand] attribute support for Symfony 8.1+.
    • Debug Commands: Use debug:container, debug:config, or debug:router.
      • Fix: debug:config now correctly shows merged configuration for all environments.
  8. Caching:

    • HTTP Cache: Configure in framework.yaml:
      framework:
          http_cache:
              enabled: true
              life_time: 3600
              etag: true  # New: Enable ETag support
      
    • Pool Pruning: Run php bin/console cache:pool:prune to clean stale cache.
      • New: Added --dry-run flag to preview pruning results.

Integration Tips

  1. Bundles:

    • The bundle auto-loads other bundles listed in config/bundles.php. Example:
      return [
          Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
          App\Kernel::class => ['all' => true],
          Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
      ];
      
    • Fix: Resolved issue where bundles with no namespace were not loaded correctly.
  2. Environment-Specific Config:

    • Use config/packages/{env}/framework.yaml (e.g., framework.prod.yaml).
    • New: Added support for framework.{env}.{suffix}.yaml (e.g., framework.prod.db.yaml).
  3. Debugging:

    • Enable debug toolbar (APP_DEBUG=1) and profiler (APP_ENV=dev).
    • Use #[DumpServer] to inspect variables during requests.
      • Fix:
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai