Skip to content

Commit 6709cf2

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Messenger] Fix unreachable catch [DependencyInjection] Fix PHPDoc syntax for InstantiatorInterface [DomCrawler] Handle malformed tags in HTML5 parser [MonologBundle] Accept HttpExceptionInterface in HttpCodeActivationStrategy Add the proper type declarations for the messenger SerializerInterface [HttpKernel] Make Kernel::getShareDir() nullable
2 parents 652e8b5 + 7311853 commit 6709cf2

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

Command/AboutCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7373
['Charset', $kernel->getCharset()],
7474
['Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],
7575
['Build directory', self::formatPath($buildDir, $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($buildDir).'</>)'],
76-
['Share directory', self::formatPath($shareDir, $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($shareDir).'</>)'],
76+
['Share directory', null === $shareDir ? 'none' : self::formatPath($shareDir, $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($shareDir).'</>)'],
7777
['Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'],
7878
new TableSeparator(),
7979
['<info>PHP</>'],

HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ protected function createSurrogate(): SurrogateInterface
8383

8484
protected function createStore(): StoreInterface
8585
{
86-
return $this->store ?? new Store($this->cacheDir ?: $this->kernel->getShareDir().'/http_cache');
86+
return $this->store ?? new Store($this->cacheDir ?: ($this->kernel->getShareDir() ?? $this->kernel->getCacheDir()).'/http_cache');
8787
}
8888
}

Kernel/MicroKernelTrait.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,15 @@ public function getBuildDir(): string
124124
return parent::getBuildDir();
125125
}
126126

127-
public function getShareDir(): string
127+
public function getShareDir(): ?string
128128
{
129129
if (isset($_SERVER['APP_SHARE_DIR'])) {
130-
return $_SERVER['APP_SHARE_DIR'].'/'.$this->environment;
130+
if (false === $dir = filter_var($_SERVER['APP_SHARE_DIR'], \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE) ?? $_SERVER['APP_SHARE_DIR']) {
131+
return null;
132+
}
133+
if (\is_string($dir)) {
134+
return $dir.'/'.$this->environment;
135+
}
131136
}
132137

133138
return parent::getShareDir();

Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,49 @@ protected function tearDown(): void
4646
}
4747
}
4848

49+
public function testGetShareDirDisabledByEnv()
50+
{
51+
$previous = $_SERVER['APP_SHARE_DIR'] ?? null;
52+
$_SERVER['APP_SHARE_DIR'] = 'false';
53+
54+
try {
55+
$kernel = $this->kernel = new ConcreteMicroKernel('test', false);
56+
57+
$this->assertNull($kernel->getShareDir());
58+
59+
$parameters = $kernel->getKernelParameters();
60+
$this->assertArrayNotHasKey('kernel.share_dir', $parameters);
61+
} finally {
62+
if (null === $previous) {
63+
unset($_SERVER['APP_SHARE_DIR']);
64+
} else {
65+
$_SERVER['APP_SHARE_DIR'] = $previous;
66+
}
67+
}
68+
}
69+
70+
public function testGetShareDirCustomPathFromEnv()
71+
{
72+
$previous = $_SERVER['APP_SHARE_DIR'] ?? null;
73+
$_SERVER['APP_SHARE_DIR'] = sys_get_temp_dir();
74+
75+
try {
76+
$kernel = $this->kernel = new ConcreteMicroKernel('test', false);
77+
78+
$expected = rtrim(sys_get_temp_dir(), '/').'/test';
79+
$this->assertSame($expected, $kernel->getShareDir());
80+
81+
$parameters = $kernel->getKernelParameters();
82+
$this->assertSame($expected, $parameters['kernel.share_dir'] ?? null);
83+
} finally {
84+
if (null === $previous) {
85+
unset($_SERVER['APP_SHARE_DIR']);
86+
} else {
87+
$_SERVER['APP_SHARE_DIR'] = $previous;
88+
}
89+
}
90+
}
91+
4992
public function test()
5093
{
5194
$kernel = $this->kernel = new ConcreteMicroKernel('test', false);

0 commit comments

Comments
 (0)