New in Symfony 6.4: Build Dir Improvements
November 3, 2023 • Published by Javier Eguiluz
Symfony 6.4 is backed by:
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
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:
1 2 3 4 5 6 7 8
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 Symfony
,
which is used in the App\Kernel
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
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:
1 2 3 4 5 6 7
namespace Symfony\Component\HttpKernel\CacheWarmer;
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.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.