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

Symfony Kernel Laravel Package

dpoposki/symfony-kernel

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require dpoposki/symfony-kernel
    

    Register the bundle in config/bundles.php (Symfony) or AppKernel.php (legacy):

    return [
        // ...
        Dpoposki\SymfonyKernel\DpoposkiSymfonyKernelBundle::class => ['all' => true],
    ];
    
  2. First Use Case Leverage the kernel for custom request handling or bootstrapping logic. Example:

    use Symfony\Component\HttpKernel\KernelInterface;
    use Dpoposki\SymfonyKernel\Kernel\CustomKernel;
    
    class AppKernel extends CustomKernel {
        public function __construct($environment, $debug) {
            parent::__construct($environment, $debug);
        }
    
        // Override to add custom bundles or logic
        protected function build(KernelInterface $kernel) {
            $kernel->getContainer()->loadFromExtension('framework', [
                'secret' => '%env(APP_SECRET)%',
            ]);
        }
    }
    
  3. Where to Look First

    • src/Kernel/CustomKernel.php: Core kernel logic.
    • src/DependencyInjection/: Configuration and extensions.
    • tests/: Example use cases and edge scenarios.

Implementation Patterns

Workflows

  1. Extending the Kernel Override CustomKernel to inject custom logic:

    class AppKernel extends CustomKernel {
        public function registerBundles() {
            $bundles = parent::registerBundles();
            $bundles[] = new \Acme\CustomBundle\AcmeCustomBundle();
            return $bundles;
        }
    }
    
  2. Dynamic Configuration Use the kernel’s build() method to modify container parameters dynamically:

    protected function build(KernelInterface $kernel) {
        $container = $kernel->getContainer();
        $container->setParameter('custom.param', 'dynamic_value');
    }
    
  3. Event Listeners Attach listeners to kernel events (e.g., kernel.request):

    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    
    $kernel->getContainer()->get('event_dispatcher')->addListener(
        'kernel.request',
        function (GetResponseEvent $event) {
            // Custom logic here
        }
    );
    

Integration Tips

  • Laravel-Symfony Hybrid Apps: Use this kernel to bridge Symfony components (e.g., HTTP client, forms) into Laravel.
  • Microservices: Deploy as a standalone Symfony kernel for API endpoints while sharing logic with Laravel.
  • Testing: Mock the kernel in PHPUnit:
    $kernel = $this->createMock(CustomKernel::class);
    $kernel->method('getContainer')->willReturn($container);
    

Gotchas and Tips

Pitfalls

  1. Bundle Registration Order

    • Symfony bundles must be registered before the kernel boots. Use registerBundles() carefully to avoid BundleNotFoundException.
    • Fix: Ensure all dependencies are installed and autoloaded.
  2. Circular Dependencies

    • Overriding build() or registerBundles() can create circular references if not managed.
    • Fix: Use dependency injection or lazy-loading where possible.
  3. Environment Variables

    • The kernel assumes Symfony’s %env() syntax. For Laravel, preload env vars:
      putenv('APP_ENV=' . getenv('APP_ENV'));
      

Debugging

  • Kernel Boot Errors: Check var/log/dev.log (Symfony) or Laravel’s storage/logs/laravel.log.
  • Container Dumping: Dump the container to inspect services:
    $container->get('debug.dump_service');
    

Extension Points

  1. Custom Console Commands Extend the kernel to add CLI tools:

    $kernel->getContainer()->set('console.command.my_command', function () {
        return new MyCommand();
    });
    
  2. Middleware Integration Add Symfony middleware to Laravel’s pipeline:

    $kernel->getContainer()->get('http_kernel')->pushMiddleware(new MyMiddleware());
    
  3. Configuration Overrides Merge custom config in build():

    $container->loadFromExtension('framework', [
        'router' => ['resource' => '%kernel.project_dir%/config/routes.yaml'],
    ]);
    

Pro Tips

  • Performance: Cache the kernel instance if reused across requests (e.g., in CLI scripts).
  • Security: Validate environment variables in build():
    if (empty($container->getParameter('app.secret'))) {
        throw new \RuntimeException('APP_SECRET is required!');
    }
    
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver