Manually recompile the Symfony container

I am trying to create a symfony attachment application. The problem is that the DI container is created during the assembly of the Docker container, which means that I cannot insert runtime parameters into it. So far, I decided to clear the cache at the entry point to the container, but I realized that in some cases it can be quite a difficult operation, so I created a custom compilation function in AppKernel based on the kernel boot function:

/**
 * Recompiles the container without warming up the whole cache.
 *
 * Can be called upon docker container start to inject custom parameters.
 */
public function compile()
{
    // Load class cache
    if ($this->loadClassCache) {
        $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
    }

    // Initialize bundles to be able to parse configurations
    $this->initializeBundles();

    $class = $this->getContainerClass();
    $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);

    $container = $this->buildContainer();
    $container->compile();
    $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
}

This function will now be called every time the Docker container is started (before the application starts).

? , ? ( , ).

symfony: https://github.com/symfony/symfony/issues/19525

PR : https://github.com/webplates/symfony-standard/pull/42

+4
1

, , . , (, ), , .

0

Source: https://habr.com/ru/post/1650234/


All Articles