G
G
Gleb Starkov2012-05-04 15:34:56
symfony
Gleb Starkov, 2012-05-04 15:34:56

AppKernel in Symfony 2

Recently working with Symfony 2. I have a
question.

As you know, AppKernel.php includes all the necessary bundles.
For example, in addition to the main ones, I have additional bundles for the
admin panel, for migrations (DoctrineMigrationsBundle) and some others.

When the pages of the frontend part are loaded, why are these unnecessary bundles loaded?
In addition, migrations are generally used only in the console.
Why are they loaded everywhere?

Or am I cooking it wrong? ©

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
Sergey, 2012-05-04
@colonel

At the first boot, all bundles are connected. This is done in order to form a list of services for each bundle and generally understand what is what. Therefore, a call to all available services appears in the cache, and, in theory, until the cache is cleared, the bundles will no longer be connected unnecessarily. in the dev environment, they are constantly connected just so that the list of services is up-to-date (although not a fact either).

C
cystbear, 2012-05-04
@cystbear

You can separate the set of downloadable bundles using different environments

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            // ....
        );

        $environment = $this->getEnvironment();

        if (in_array($environment, array('test', 'behat'))) {
            $bundles[] = new Behat\BehatBundle\BehatBundle();
            $bundles[] = new Behat\MinkBundle\MinkBundle();
        }

        return $bundles;
    }
}

Calling a console with a non-default (dev) env
app/console --env=test %YOUR_COMMAND%

N
nuclear, 2012-05-04
@nuclear

The migration bundle can be loaded in the dev environment, as By default, the console starts with this environment.
And for the rest. Do you have real performance problems due to the fact that all bundles are loaded?
It's just that the bundles themselves are almost empty classes and they should not create a load.

M
MuXaJIbI4, 2012-05-04
@MuXaJIbI4

I've been thinking about this problem for a long time too. And I even decided to make several projects to separate the admin panel and the front-end, and took out the general functionality into my bundles and connected them in these projects. But then I realized that there is almost no point in this and right now I am doing everything together in one project.

M
MuXaJIbI4, 2012-05-04
@MuXaJIbI4

Another idea came to mind while writing the previous comment. You can make different entry points for the admin and frontend and connect your own AppKernel in each, where each will have its own set of bundles. To be honest, I don't know how well this works. But you can try :)

S
shagguboy, 2012-05-06
@shagguboy

in Symphony, everything is loaded by autoload (well, Lazy Load is used to the fullest), so connecting bundles does not load anything much.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question