Skip to content

Commit 61bd29e

Browse files
committed
#23354 Add $kernel->getTmpDir() to separate it from the cache directory
1 parent 01794d0 commit 61bd29e

File tree

18 files changed

+40
-15
lines changed

18 files changed

+40
-15
lines changed

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ protected function createContainer(array $data = []): ContainerBuilder
263263
return new ContainerBuilder(new ParameterBag(array_merge([
264264
'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
265265
'kernel.cache_dir' => __DIR__,
266+
'kernel.tmp_dir' => __DIR__,
266267
'kernel.container_class' => 'kernel',
267268
'kernel.project_dir' => __DIR__,
268269
], $data)));

src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private function createContainer()
7474
{
7575
$container = new ContainerBuilder(new ParameterBag([
7676
'kernel.cache_dir' => __DIR__,
77+
'kernel.tmp_dir' => __DIR__,
7778
'kernel.charset' => 'UTF-8',
7879
'kernel.debug' => true,
7980
'kernel.bundles' => ['DebugBundle' => 'Symfony\\Bundle\\DebugBundle\\DebugBundle'],

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7676
['Debug', $kernel->isDebug() ? 'true' : 'false'],
7777
['Charset', $kernel->getCharset()],
7878
['Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],
79+
['Temp directory', self::formatPath($kernel->getTmpDir(), $kernel->getTmpDir()).' (<comment>'.self::formatFileSize($kernel->getTmpDir()).'</>)'],
7980
['Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'],
8081
new TableSeparator(),
8182
['<info>PHP</>'],

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080

8181
$kernel = $this->getApplication()->getKernel();
8282
$realCacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir');
83+
$realTmpDir = $kernel->getContainer()->getParameter('kernel.tmp_dir');
8384
// the old cache dir name must not be longer than the real one to avoid exceeding
8485
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
8586
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
86-
$fs->remove($oldCacheDir);
87+
$oldTmpDir = substr($realTmpDir, 0, -1).('~' === substr($realTmpDir, -1) ? '+' : '~');
88+
$fs->remove([$oldCacheDir, $oldTmpDir]);
8789

8890
if (!is_writable($realCacheDir)) {
8991
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir));

src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8585

8686
foreach ($clearers as $id => $clearer) {
8787
$io->comment(sprintf('Calling cache clearer: <info>%s</info>', $id));
88-
$clearer->clear($kernel->getContainer()->getParameter('kernel.cache_dir'));
88+
$clearer->clear($kernel->getContainer()->getParameter('kernel.tmp_dir'));
8989
}
9090

9191
foreach ($pools as $id => $pool) {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
230230
->booleanNode('collect')->defaultTrue()->end()
231231
->booleanNode('only_exceptions')->defaultFalse()->end()
232232
->booleanNode('only_master_requests')->defaultFalse()->end()
233-
->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()
233+
->scalarNode('dsn')->defaultValue('file:%kernel.tmp_dir%/profiler')->end()
234234
->end()
235235
->end()
236236
->end()
@@ -527,7 +527,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
527527
->scalarNode('gc_divisor')->end()
528528
->scalarNode('gc_probability')->defaultValue(1)->end()
529529
->scalarNode('gc_maxlifetime')->end()
530-
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
530+
->scalarNode('save_path')->defaultValue('%kernel.tmp_dir%/sessions')->end()
531531
->integerNode('metadata_update_threshold')
532532
->defaultValue(0)
533533
->info('seconds to wait between 2 session metadata updates')
@@ -881,7 +881,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
881881
->info('System related cache pools configuration')
882882
->defaultValue('cache.adapter.system')
883883
->end()
884-
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools')->end()
884+
->scalarNode('directory')->defaultValue('%kernel.tmp_dir%/pools')->end()
885885
->scalarNode('default_doctrine_provider')->end()
886886
->scalarNode('default_psr6_provider')->end()
887887
->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end()

src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ protected function createSurrogate()
7474

7575
protected function createStore()
7676
{
77-
return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
77+
return new Store($this->cacheDir ?: $this->kernel->getTmpDir().'/http_cache');
7878
}
7979
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<argument /> <!-- namespace -->
4747
<argument>0</argument> <!-- default lifetime -->
4848
<argument /> <!-- version -->
49-
<argument>%kernel.cache_dir%/pools</argument>
49+
<argument>%kernel.tmp_dir%/pools</argument>
5050
<argument type="service" id="logger" on-invalid="ignore" />
5151
</service>
5252

@@ -77,7 +77,7 @@
7777
<tag name="monolog.logger" channel="cache" />
7878
<argument /> <!-- namespace -->
7979
<argument>0</argument> <!-- default lifetime -->
80-
<argument>%kernel.cache_dir%/pools</argument>
80+
<argument>%kernel.tmp_dir%/pools</argument>
8181
<argument type="service" id="cache.default_marshaller" on-invalid="ignore" />
8282
<call method="setLogger">
8383
<argument type="service" id="logger" on-invalid="ignore" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<tag name="data_collector" template="@WebProfiler/Collector/logger.html.twig" id="logger" priority="300" />
3636
<tag name="monolog.logger" channel="profiler" />
3737
<argument type="service" id="logger" on-invalid="ignore" />
38-
<argument>%kernel.cache_dir%/%kernel.container_class%</argument>
38+
<argument>%kernel.tmp_dir%/%kernel.container_class%</argument>
3939
<argument type="service" id="request_stack" on-invalid="ignore" />
4040
</service>
4141

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</service>
5454

5555
<service id="session.storage.mock_file" class="Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage">
56-
<argument>%kernel.cache_dir%/sessions</argument>
56+
<argument>%kernel.tmp_dir%/sessions</argument>
5757
<argument>MOCKSESSID</argument>
5858
<argument type="service" id="session.storage.metadata_bag" />
5959
</service>

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<argument>%kernel.default_locale%</argument>
1414
<argument type="collection" /> <!-- translation loaders ids -->
1515
<argument type="collection">
16-
<argument key="cache_dir">%kernel.cache_dir%/translations</argument>
16+
<argument key="cache_dir">%kernel.tmp_dir%/translations</argument>
1717
<argument key="debug">%kernel.debug%</argument>
1818
</argument>
1919
<argument type="collection" /> <!-- enabled locales -->

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ protected static function getBundleDefaultConfig()
362362
'enabled' => false,
363363
'only_exceptions' => false,
364364
'only_master_requests' => false,
365-
'dsn' => 'file:%kernel.cache_dir%/profiler',
365+
'dsn' => 'file:%kernel.tmp_dir%/profiler',
366366
'collect' => true,
367367
],
368368
'translator' => [
@@ -427,7 +427,7 @@ protected static function getBundleDefaultConfig()
427427
'cookie_httponly' => true,
428428
'cookie_samesite' => null,
429429
'gc_probability' => 1,
430-
'save_path' => '%kernel.cache_dir%/sessions',
430+
'save_path' => '%kernel.tmp_dir%/sessions',
431431
'metadata_update_threshold' => 0,
432432
],
433433
'request' => [
@@ -448,7 +448,7 @@ protected static function getBundleDefaultConfig()
448448
'pools' => [],
449449
'app' => 'cache.adapter.filesystem',
450450
'system' => 'cache.adapter.system',
451-
'directory' => '%kernel.cache_dir%/pools',
451+
'directory' => '%kernel.tmp_dir%/pools',
452452
'default_redis_provider' => 'redis://localhost',
453453
'default_memcached_provider' => 'memcached://localhost',
454454
'default_pdo_provider' => class_exists(Connection::class) ? 'database_connection' : null,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ protected function createContainer(array $data = [])
14571457
'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
14581458
'kernel.bundles_metadata' => ['FrameworkBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..']],
14591459
'kernel.cache_dir' => __DIR__,
1460+
'kernel.tmp_dir' => __DIR__,
14601461
'kernel.project_dir' => __DIR__,
14611462
'kernel.debug' => false,
14621463
'kernel.environment' => 'test',

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function doTestCachePools($options, $adapterClass)
9090
$pool2 = $container->get('cache.pool2');
9191
$pool2->save($item);
9292

93-
$container->get('cache_clearer')->clear($container->getParameter('kernel.cache_dir'));
93+
$container->get('cache_clearer')->clear($container->getParameter('kernel.tmp_dir'));
9494
$item = $pool1->getItem($key);
9595
$this->assertFalse($item->isHit());
9696

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSessionDomainConstraintPassTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private function createContainer($sessionStorageOptions)
125125
$container = new ContainerBuilder();
126126
$container->setParameter('kernel.bundles_metadata', []);
127127
$container->setParameter('kernel.cache_dir', __DIR__);
128+
$container->setParameter('kernel.tmp_dir', __DIR__);
128129
$container->setParameter('kernel.charset', 'UTF-8');
129130
$container->setParameter('kernel.container_class', 'cc');
130131
$container->setParameter('kernel.debug', true);

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ protected function setUp(): void
6262
$this->container->register('twig', 'Twig\Environment')->addArgument(new Reference('twig_loader'))->setPublic(true);
6363
$this->container->setParameter('kernel.bundles', []);
6464
$this->container->setParameter('kernel.cache_dir', __DIR__);
65+
$this->container->setParameter('kernel.tmp_dir', __DIR__);
6566
$this->container->setParameter('kernel.debug', false);
6667
$this->container->setParameter('kernel.project_dir', __DIR__);
6768
$this->container->setParameter('kernel.charset', 'UTF-8');

src/Symfony/Component/HttpKernel/Kernel.php

+10
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ public function getCacheDir()
333333
return $this->getProjectDir().'/var/cache/'.$this->environment;
334334
}
335335

336+
/**
337+
* {@inheritdoc}
338+
*/
339+
public function getTmpDir()
340+
{
341+
// Returns $this->getCacheDir() for backward compatibility
342+
return $this->getCacheDir();
343+
}
344+
336345
/**
337346
* {@inheritdoc}
338347
*/
@@ -595,6 +604,7 @@ protected function getKernelParameters()
595604
'kernel.environment' => $this->environment,
596605
'kernel.debug' => $this->debug,
597606
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
607+
'kernel.tmp_dir' => realpath($this->getTmpDir()) ?: $this->getTmpDir(),
598608
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
599609
'kernel.bundles' => $bundles,
600610
'kernel.bundles_metadata' => $bundlesMetadata,

src/Symfony/Component/HttpKernel/KernelInterface.php

+7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public function getStartTime();
125125
*/
126126
public function getCacheDir();
127127

128+
/**
129+
* Gets the temporary directory.
130+
*
131+
* @return string The temporary directory
132+
*/
133+
public function getTmpDir();
134+
128135
/**
129136
* Gets the log directory.
130137
*

0 commit comments

Comments
 (0)