Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CHANGELOG
* Initialize `router.request_context`'s `_locale` parameter to `%kernel.default_locale%`
* Deprecate `ConfigBuilderCacheWarmer`, return PHP arrays from your config instead
* Add support for selecting the appropriate error renderer based on the `APP_RUNTIME_MODE` env var
* Add `KernelInterface::getShareDir()`, `APP_SHARE_DIR` and `%kernel.share_dir%` to store application data that are shared between all front-end servers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this pattern is common enough to add it to the KernelInterface.


7.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe
->info('System related cache pools configuration.')
->defaultValue('cache.adapter.system')
->end()
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools/app')->end()
->scalarNode('directory')->defaultValue('%kernel.share_dir%/pools/app')->end()
->scalarNode('default_psr6_provider')->end()
->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end()
->scalarNode('default_valkey_provider')->defaultValue('valkey://localhost')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public function getBuildDir(): string
return parent::getBuildDir();
}

public function getShareDir(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be nullable. Not all applications can provide such shared dir.
Setting a value that isn't a shared directory would be incorrect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, it fallbacks to cache_dir which keeps BC.

{
if (isset($_SERVER['APP_SHARE_DIR'])) {
return $_SERVER['APP_SHARE_DIR'].'/'.$this->environment;
}

return parent::getShareDir();
}

public function getLogDir(): string
{
return $_SERVER['APP_LOG_DIR'] ?? parent::getLogDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ protected static function getBundleDefaultConfig()
'pools' => [],
'app' => 'cache.adapter.filesystem',
'system' => 'cache.adapter.system',
'directory' => '%kernel.cache_dir%/pools/app',
'directory' => '%kernel.share_dir%/pools/app',
'default_redis_provider' => 'redis://localhost',
'default_valkey_provider' => 'valkey://localhost',
'default_memcached_provider' => 'memcached://localhost',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,7 @@ protected function createContainer(array $data = [])
'kernel.bundles_metadata' => ['FrameworkBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..']],
'kernel.cache_dir' => __DIR__,
'kernel.build_dir' => __DIR__,
'kernel.share_dir' => __DIR__,
'kernel.project_dir' => __DIR__,
'kernel.debug' => false,
'kernel.environment' => 'test',
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"symfony/filesystem": "^7.1|^8.0",
"symfony/finder": "^6.4|^7.0|^8.0",
"symfony/http-foundation": "^7.4|^8.0",
"symfony/http-kernel": "^7.2|^8.0",
"symfony/http-kernel": "^7.4|^8.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php85": "^1.32",
"symfony/routing": "^7.4|^8.0"
Expand Down
13 changes: 10 additions & 3 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ public function getBuildDir(): string
return $this->getCacheDir();
}

public function getShareDir(): string
{
// Returns $this->getCacheDir() for backward compatibility
return $this->getCacheDir();
}

public function getLogDir(): string
{
return $this->getProjectDir().'/var/log';
Expand Down Expand Up @@ -578,9 +584,10 @@ protected function getKernelParameters(): array
'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%',
'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%',
'kernel.debug' => $this->debug,
'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
'kernel.build_dir' => realpath($dir = $this->warmupDir ?: $this->getBuildDir()) ?: $dir,
'kernel.cache_dir' => realpath($dir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $dir,
'kernel.share_dir' => realpath($dir = $this->getShareDir()) ?: $dir,
'kernel.logs_dir' => realpath($dir = $this->getLogDir()) ?: $dir,
'kernel.bundles' => $bundles,
'kernel.bundles_metadata' => $bundlesMetadata,
'kernel.charset' => $this->getCharset(),
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/HttpKernel/KernelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*
* It manages an environment made of application kernel and bundles.
*
* @method string getShareDir() Returns the share directory - not implementing it is deprecated since Symfony 7.4.
* This directory should be used to store data that is shared between all front-end servers.
* This typically fits application caches.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface KernelInterface extends HttpKernelInterface
Expand Down Expand Up @@ -123,7 +127,9 @@ public function getCacheDir(): string;
* Returns the build directory.
*
* This directory should be used to store build artifacts, and can be read-only at runtime.
* Caches written at runtime should be stored in the "cache directory" ({@see KernelInterface::getCacheDir()}).
* System caches written at runtime should be stored in the "cache directory" ({@see KernelInterface::getCacheDir()}).
* Application caches that are shared between all front-end servers should be stored
* in the "share directory" ({@see KernelInterface::getShareDir()}).
*/
public function getBuildDir(): string;

Expand Down
Loading