-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[HttpKernel] Make Kernel::getShareDir() nullable #62204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,49 @@ protected function tearDown(): void | |
| } | ||
| } | ||
|
|
||
| public function testGetShareDirDisabledByEnv() | ||
| { | ||
| $previous = $_SERVER['APP_SHARE_DIR'] ?? null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? PHPUnit does restore the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's quite possible 😬
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FTR, it's the opposite: #62273 |
||
| $_SERVER['APP_SHARE_DIR'] = 'false'; | ||
|
|
||
| try { | ||
| $kernel = $this->kernel = new ConcreteMicroKernel('test', false); | ||
|
|
||
| $this->assertNull($kernel->getShareDir()); | ||
|
|
||
| $parameters = $kernel->getKernelParameters(); | ||
| $this->assertArrayNotHasKey('kernel.share_dir', $parameters); | ||
| } finally { | ||
| if (null === $previous) { | ||
| unset($_SERVER['APP_SHARE_DIR']); | ||
| } else { | ||
| $_SERVER['APP_SHARE_DIR'] = $previous; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public function testGetShareDirCustomPathFromEnv() | ||
| { | ||
| $previous = $_SERVER['APP_SHARE_DIR'] ?? null; | ||
| $_SERVER['APP_SHARE_DIR'] = sys_get_temp_dir(); | ||
|
|
||
| try { | ||
| $kernel = $this->kernel = new ConcreteMicroKernel('test', false); | ||
|
|
||
| $expected = rtrim(sys_get_temp_dir(), '/').'/test'; | ||
| $this->assertSame($expected, $kernel->getShareDir()); | ||
|
|
||
| $parameters = $kernel->getKernelParameters(); | ||
| $this->assertSame($expected, $parameters['kernel.share_dir'] ?? null); | ||
| } finally { | ||
| if (null === $previous) { | ||
| unset($_SERVER['APP_SHARE_DIR']); | ||
| } else { | ||
| $_SERVER['APP_SHARE_DIR'] = $previous; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public function test() | ||
| { | ||
| $kernel = $this->kernel = new ConcreteMicroKernel('test', false); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,7 +303,7 @@ public function getBuildDir(): string | |
| return $this->getCacheDir(); | ||
| } | ||
|
|
||
| public function getShareDir(): string | ||
| public function getShareDir(): ?string | ||
| { | ||
| // Returns $this->getCacheDir() for backward compatibility | ||
| return $this->getCacheDir(); | ||
|
Comment on lines
308
to
309
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this not be now
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope: we want to null to be opt-in |
||
|
|
@@ -586,13 +586,12 @@ protected function getKernelParameters(): array | |
| 'kernel.debug' => $this->debug, | ||
| '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(), | ||
| 'kernel.container_class' => $this->getContainerClass(), | ||
| ]; | ||
| ] + (null !== ($dir = $this->getShareDir()) ? ['kernel.share_dir' => realpath($dir) ?: $dir] : []); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.