简体   繁体   中英

How to apply symfony bundle to Laravel?

\\I heard that Laravel was made with symfony, php framework. So, I thought symfony bundle will work at Laravel, too.

IgorwFileServeBundle github

I want to install it to Laravel "5.1.*". So I edited this line at composer.json.

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "igorw/file-serve-bundle": "~1.0"
},

then I executed composer update . readme.md say I have to add it to my app's kernel.

public function registerBundles()
{
    $bundles = array(
        // ...
        new Igorw\FileServeBundle\IgorwFileServeBundle(),
        // ...
    );
    // ...
}

So I added it to my kernel.

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \Igorw\FileServeBundle\IgorwFileServeBundle::class,
];

But When I save and go to my app at brower, FatalErrorException in Bundle.php line 29: Class 'Symfony\\Component\\DependencyInjection\\ContainerAware' not found was appear.

What I'm wrong?

Symfony and Laravel are 2 completely different frameworks. Symfony is build on top of 20+ (maybe even 30+) Symfony components (standalone libraries created by the Symfony team). These components are bound together by the framework bundle and the framework that was created is called the Symfony full-stack framework.

Some of these components are also used by Laravel. The Laravel framework is just another way of glueing these components together. Silex, another framework, is yet another way of binding these components.

Bundles is a concept from the Symfony full-stack component (HttpKernel component actually). Laravel does not use this, so you can't use any bundles in Laravel.

If you need to use a Symfony bundle, you need to have a Symfony application. Fortunately for your, Laravel has a big community as well. It's very likely that there is a Laravel package implementing the same feature for the Laravel framework.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM