-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Added normalized env getter in kernel for correct container compile. #25915
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
Conversation
Regex can be changed for something like |
Thanks for the report. Envs have implicit requirements, good idea to enforce them. |
Good catch, the format should be enforced, this kind of issues is a pain to debug, especially for newcomers. I suggest to throw an exception specifying the valid characters instead of normalizing (the normalization introduces some complexity, and probably some more WTF later). |
@dunglas, @nicolas-grekas I suggest to normalize environment value instead of exception. So, it would be strangeous behaviour when in one place would be normalization and in another one - exception. Can I extract normalization for this two places in separate private method and then update this PR ? |
@ed-fruty go on my side for normalization, but with a BC-safe regular expression: |
wait, actually this patch would be better: --- a/src/Symfony/Component/HttpKernel/Kernel.php
+++ b/src/Symfony/Component/HttpKernel/Kernel.php
@@ -480,7 +480,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
*/
protected function getContainerClass()
{
- return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
+ return $this->name.ucfirst(preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $this->environment)).($this->debug ? 'Debug' : '').'ProjectContainer';
}
/** |
Updated PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me at the fix side. Tests need to be implemented, and this PR should be retargetted/rebased at branch 2.7, where the issue also exists. As PHP 5.3 is the minimum version there, PHP 7 syntax cannot be used.
@@ -523,6 +523,44 @@ public function testProjectDirExtension() | |||
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir')); | |||
} | |||
|
|||
/** | |||
* @param $env | |||
* @param $expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pleas remove both @param
$kernel = new class($env, true) extends Kernel { | ||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
// TODO: Implement registerContainerConfiguration() method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO :) (same below)
The environment is also used for the cache folder. So certain special characters will make this fail as well, esp. on Windows. So that sohuld be fixed as well if we want make env chars failure tolerant. |
I create my branch from |
sure, if you're more comfortable this way no pb! |
Closing as this needs to be submitted on 2.7 (and tests be updated to work on PHP 5.3) |
I don't think it's a big bug, but it's a case when symfony wasn't work properly.
When you have a specific env name, you can't even install symfony correctly.
Steps to reproduce:
export APP_ENV=dev-server composer create-project symfony/skeleton symfony_will_crash
And you will get an error
[KO] [KO] Script cache:clear returned with error code 255 !! PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Undefined constant 'ContainerCPr692s\srcDev' in /home/project/symfony_will_crash/var/cache/dev-server/srcDev-serverDebugProjectContainer.php:5
.Full installation log will be like this:
The main thing is compiler tries to create container with filename and classname uses our $APP_ENV and in this case it will be
srcDev-serverDebugProjectContainer
which is not valid for php syntax.One of suggestions is always to use
normalized
environment name. In our case it will bedevserver
.Another one is throw an exception if env is not valid.
What do think ?