Skip to content

Commit a4ffed5

Browse files
Merge branch '4.0'
* 4.0: (23 commits) Clean up Update return type in docblock. PHP CS Fixer: no need to exclude xml and yml files PHP CS Fixer: no need to exclude json file [#22749] fix version in changelog Update LICENSE year... forever fixed some deprecation messages fixed CS Fixes for Oracle in PdoSessionHandler fixed some deprecation messages fixed some deprecation messages fixed some deprecation messages fixed some deprecation messages Remove dead code [TwigBundle/Brige] catch missing requirements to throw meaningful exceptions [DI] fix CS [HttpKernel] Call Response->setPrivate() instead of sending raw header() when session is started [FrameworkBundle] Make cache:clear "atomic" and consistent with cache:warmup Suggest to write an implementation if the interface cannot be autowired [Debug] Skip DebugClassLoader checks for already parsed files ...
2 parents 14b8c51 + cd10db8 commit a4ffed5

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

Command/CacheClearCommand.php

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,62 @@ protected function configure()
7373
*/
7474
protected function execute(InputInterface $input, OutputInterface $output)
7575
{
76+
$fs = $this->filesystem;
7677
$io = new SymfonyStyle($input, $output);
7778

7879
$kernel = $this->getApplication()->getKernel();
7980
$realCacheDir = $kernel->getContainer()->getParameter('kernel.cache_dir');
8081
// the old cache dir name must not be longer than the real one to avoid exceeding
8182
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
8283
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
84+
$fs->remove($oldCacheDir);
8385

8486
if (!is_writable($realCacheDir)) {
8587
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
8688
}
8789

88-
if ($this->filesystem->exists($oldCacheDir)) {
89-
$this->filesystem->remove($oldCacheDir);
90-
}
91-
9290
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
9391
$this->cacheClearer->clear($realCacheDir);
9492

9593
// The current event dispatcher is stale, let's not use it anymore
9694
$this->getApplication()->setDispatcher(new EventDispatcher());
9795

98-
if ($input->getOption('no-warmup')) {
99-
$this->filesystem->rename($realCacheDir, $oldCacheDir);
100-
} else {
101-
$this->warmupCache($input, $output, $realCacheDir, $oldCacheDir);
96+
$containerDir = new \ReflectionObject($kernel->getContainer());
97+
$containerDir = basename(dirname($containerDir->getFileName()));
98+
99+
// the warmup cache dir name must have the same length as the real one
100+
// to avoid the many problems in serialized resources files
101+
$warmupDir = substr($realCacheDir, 0, -1).('_' === substr($realCacheDir, -1) ? '-' : '_');
102+
103+
if ($output->isVerbose() && $fs->exists($warmupDir)) {
104+
$io->comment('Clearing outdated warmup directory...');
105+
}
106+
$fs->remove($warmupDir);
107+
$fs->mkdir($warmupDir);
108+
109+
if (!$input->getOption('no-warmup')) {
110+
if ($output->isVerbose()) {
111+
$io->comment('Warming up cache...');
112+
}
113+
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
114+
}
115+
116+
$containerDir = $fs->exists($warmupDir.'/'.$containerDir) ? false : $containerDir;
117+
118+
$fs->rename($realCacheDir, $oldCacheDir);
119+
$fs->rename($warmupDir, $realCacheDir);
120+
121+
if ($containerDir) {
122+
$fs->rename($oldCacheDir.'/'.$containerDir, $realCacheDir.'/'.$containerDir);
123+
touch($realCacheDir.'/'.$containerDir.'.legacy');
102124
}
103125

104126
if ($output->isVerbose()) {
105127
$io->comment('Removing old cache directory...');
106128
}
107129

108130
try {
109-
$this->filesystem->remove($oldCacheDir);
131+
$fs->remove($oldCacheDir);
110132
} catch (IOException $e) {
111133
$io->warning($e->getMessage());
112134
}
@@ -118,34 +140,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
118140
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
119141
}
120142

121-
private function warmupCache(InputInterface $input, OutputInterface $output, string $realCacheDir, string $oldCacheDir)
122-
{
123-
$io = new SymfonyStyle($input, $output);
124-
125-
// the warmup cache dir name must have the same length than the real one
126-
// to avoid the many problems in serialized resources files
127-
$realCacheDir = realpath($realCacheDir);
128-
$warmupDir = substr($realCacheDir, 0, -1).('_' === substr($realCacheDir, -1) ? '-' : '_');
129-
130-
if ($this->filesystem->exists($warmupDir)) {
131-
if ($output->isVerbose()) {
132-
$io->comment('Clearing outdated warmup directory...');
133-
}
134-
$this->filesystem->remove($warmupDir);
135-
}
136-
137-
if ($output->isVerbose()) {
138-
$io->comment('Warming up cache...');
139-
}
140-
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
141-
142-
$this->filesystem->rename($realCacheDir, $oldCacheDir);
143-
if ('\\' === DIRECTORY_SEPARATOR) {
144-
sleep(1); // workaround for Windows PHP rename bug
145-
}
146-
$this->filesystem->rename($warmupDir, $realCacheDir);
147-
}
148-
149143
private function warmup(string $warmupDir, string $realCacheDir, bool $enableOptionalWarmers = true)
150144
{
151145
// create a temporary kernel

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
670670

671671
// session storage
672672
$container->setAlias('session.storage', $config['storage_id'])->setPrivate(true);
673-
$options = array();
673+
$options = array('cache_limiter' => '0');
674674
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
675675
if (isset($config[$key])) {
676676
$options[$key] = $config[$key];
@@ -913,9 +913,6 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
913913
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
914914
$dirs[] = $dir;
915915
}
916-
if ($container->fileExists($dir = $defaultDir.'/'.$name)) {
917-
$dirs[] = $dir;
918-
}
919916
if ($container->fileExists($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
920917
$dirs[] = $dir;
921918
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2017 Fabien Potencier
1+
Copyright (c) 2004-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)