New in Symfony 6.4: Build Dir Improvements

In Symfony applications, the kernel.build_dir option defines the directory where
read-only contents are generated during the compilation of the application. In
Symfony 6.4 we’ve made some improvements related to it.

APP_BUILD_DIR Support

Contributed by
Roland Franssen

in #50951.

By default, the getBuildDir() method in the Symfony Kernel class returns
$this->getCacheDir() for backward-compatibility reasons. In Symfony 6.4 we’ve
improved this method to check first the value of the APP_BUILD_DIR environment
variable:

public function getBuildDir(): string
{
if (isset($_SERVER[‚APP_BUILD_DIR‘])) {
return $_SERVER[‚APP_BUILD_DIR‘].‚/‘.$this->environment;
}

return parent::getBuildDir();
}

These changes were added to the SymfonyBundleFrameworkBundleKernelMicroKernelTrait,
which is used in the AppKernel class created by default in new Symfony applications.
This will simplify the deployment of Symfony applications to read-only filesystems
like Docker containers or AWS Lambda.

Using Build Dir to Generate More Contents

Contributed by
Quentin D.

in #50391.

The build_dir feature is probably underused in Symfony. By default, only the
compiled container is dumped in the build_dir. All the other read-only compiled
artifacts are dumped into the cache_dir: the router cache, Doctrine proxy classes,
Symfony Config classes, translations, etc.

In order to improve this, we’re making a change in the cache warmer classes.
The warmUp() method of the WarmableInterface now accepts a second argument
with the $buildDir value:

namespace SymfonyComponentHttpKernelCacheWarmer;

interface WarmableInterface
{
– public function warmUp(string $cacheDir): array;
+ public function warmUp(string $cacheDir/* , string $buildDir = null */): array;
}

Thanks to this change, you can now store read-only artifacts more easily in the
build_dir, which is the best location for them. In order to make the change
backward-compatible, we added the argument as a comment in 6.4 (and it will be a
true argument in Symfony 7.0).

This change will trigger deprecation messages when updating your applications to
Symfony 6.4. Make sure to add this change to your warmers (and to contribute this
change to third-party bundles used in your applications) so you can later upgrade
to Symfony 7.

Sponsor the Symfony project.

Symfony Blog

Read More

Latest News

PHP-Releases

PHP 8.4.1 released!

PHP 8.1.31 released!

PHP 8.3.14 released!

PHP 8.2.26 released!

Generated by Feedzy