Skip to content

Commit 01cdaf3

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Routing] Fix case sensitivity for static host matching in compiled routes [Routing] Fix localized prefix updates breaking aliases [Routing] Fix addNamePrefix breaking aliases to external routes [Workflow] Fix MethodMarkingStore crash with inherited uninitialized properties [AssetMapper] Fix entrypoint status lost during update [ObjectMapper] map to embedded object with property access [FrameworkBundle] Make `APP_*_DIR` relative to the project directory [Console] Fix completion for global options values
2 parents bc48341 + 4623bcd commit 01cdaf3

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

Kernel/MicroKernelTrait.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,30 @@ private function getBundlesPath(): string
108108

109109
public function getCacheDir(): string
110110
{
111-
if (isset($_SERVER['APP_CACHE_DIR'])) {
112-
return $_SERVER['APP_CACHE_DIR'].'/'.$this->environment;
111+
if (null !== $dir = $_SERVER['APP_CACHE_DIR'] ?? null) {
112+
return $this->getEnvDir($dir);
113113
}
114114

115115
return parent::getCacheDir();
116116
}
117117

118118
public function getBuildDir(): string
119119
{
120-
if (isset($_SERVER['APP_BUILD_DIR'])) {
121-
return $_SERVER['APP_BUILD_DIR'].'/'.$this->environment;
120+
if (null !== $dir = $_SERVER['APP_BUILD_DIR'] ?? null) {
121+
return $this->getEnvDir($dir);
122122
}
123123

124124
return parent::getBuildDir();
125125
}
126126

127127
public function getShareDir(): ?string
128128
{
129-
if (isset($_SERVER['APP_SHARE_DIR'])) {
130-
if (false === $dir = filter_var($_SERVER['APP_SHARE_DIR'], \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE) ?? $_SERVER['APP_SHARE_DIR']) {
129+
if (null !== $dir = $_SERVER['APP_SHARE_DIR'] ?? null) {
130+
if (false === $dir = filter_var($dir, \FILTER_VALIDATE_BOOL, \FILTER_NULL_ON_FAILURE) ?? $dir) {
131131
return null;
132132
}
133133
if (\is_string($dir)) {
134-
return $dir.'/'.$this->environment;
134+
return $this->getEnvDir($dir);
135135
}
136136
}
137137

@@ -267,4 +267,16 @@ protected function getKernelParameters(): array
267267

268268
return $parameters;
269269
}
270+
271+
private function getEnvDir(string $dir): string
272+
{
273+
if ('' !== $dir && \in_array($dir[0], ['/', '\\'], true)) {
274+
return $dir.'/'.$this->environment;
275+
}
276+
if ('\\' === \DIRECTORY_SEPARATOR && ':' === ($dir[1] ?? '') && 65 <= \ord($dir[0]) && \ord($dir[0]) <= 122 && !\in_array($dir[0], ['[', ']', '^', '_', '`'], true)) {
277+
return $dir.'/'.$this->environment;
278+
}
279+
280+
return $this->getProjectDir().'/'.$dir.'/'.$this->environment;
281+
}
270282
}

Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Psr\Log\NullLogger;
1717
use Symfony\Bundle\FrameworkBundle\Console\Application;
18+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
1819
use Symfony\Component\Console\Attribute\AsCommand;
1920
use Symfony\Component\Console\Input\ArrayInput;
2021
use Symfony\Component\Console\Output\BufferedOutput;
@@ -239,4 +240,33 @@ public function testGetKernelParametersWithBundlesFile()
239240
'TestBundle' => ['test' => true, 'dev' => true],
240241
], $parameters['.kernel.bundles_definition']);
241242
}
243+
244+
public function testRelativeEnvDirsAreResolvedFromProjectDir()
245+
{
246+
$_SERVER['APP_CACHE_DIR'] = 'var/custom-cache';
247+
$_SERVER['APP_BUILD_DIR'] = 'var/custom-build';
248+
$_SERVER['APP_SHARE_DIR'] = 'var/custom-share';
249+
250+
$projectDir = sys_get_temp_dir().'/sf_env_dir_kernel';
251+
$kernel = new EnvDirKernel($projectDir);
252+
253+
$this->assertSame($projectDir.'/var/custom-cache/test', $kernel->getCacheDir());
254+
$this->assertSame($projectDir.'/var/custom-build/test', $kernel->getBuildDir());
255+
$this->assertSame($projectDir.'/var/custom-share/test', $kernel->getShareDir());
256+
}
257+
}
258+
259+
class EnvDirKernel extends Kernel
260+
{
261+
use MicroKernelTrait;
262+
263+
public function __construct(private readonly string $projectDir)
264+
{
265+
parent::__construct('test', false);
266+
}
267+
268+
public function getProjectDir(): string
269+
{
270+
return $this->projectDir;
271+
}
242272
}

0 commit comments

Comments
 (0)