Merge branch '3.4' into 4.3
* 3.4: Add plus character `+` to legal mime subtype [Dotenv] search variable values in ENV first then env file [VarDumper] fix resetting the "bold" state in CliDumper SCA: added missing break in a loop
This commit is contained in:
commit
8d8a10c699
@ -281,6 +281,7 @@ trait MemcachedTrait
|
|||||||
foreach ($this->checkResultCode($this->getClient()->deleteMulti($encodedIds)) as $result) {
|
foreach ($this->checkResultCode($this->getClient()->deleteMulti($encodedIds)) as $result) {
|
||||||
if (\Memcached::RES_SUCCESS !== $result && \Memcached::RES_NOTFOUND !== $result) {
|
if (\Memcached::RES_SUCCESS !== $result && \Memcached::RES_NOTFOUND !== $result) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +257,8 @@ final class Dotenv
|
|||||||
throw $this->createFormatException('Whitespace are not supported before the value');
|
throw $this->createFormatException('Whitespace are not supported before the value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$loadedVars = array_flip(explode(',', isset($_SERVER['SYMFONY_DOTENV_VARS']) ? $_SERVER['SYMFONY_DOTENV_VARS'] : (isset($_ENV['SYMFONY_DOTENV_VARS']) ? $_ENV['SYMFONY_DOTENV_VARS'] : '')));
|
||||||
|
unset($loadedVars['']);
|
||||||
$v = '';
|
$v = '';
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -295,8 +297,8 @@ final class Dotenv
|
|||||||
++$this->cursor;
|
++$this->cursor;
|
||||||
$value = str_replace(['\\"', '\r', '\n'], ['"', "\r", "\n"], $value);
|
$value = str_replace(['\\"', '\r', '\n'], ['"', "\r", "\n"], $value);
|
||||||
$resolvedValue = $value;
|
$resolvedValue = $value;
|
||||||
$resolvedValue = $this->resolveVariables($resolvedValue);
|
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
|
||||||
$resolvedValue = $this->resolveCommands($resolvedValue);
|
$resolvedValue = $this->resolveCommands($resolvedValue, $loadedVars);
|
||||||
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
|
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
|
||||||
$v .= $resolvedValue;
|
$v .= $resolvedValue;
|
||||||
} else {
|
} else {
|
||||||
@ -318,8 +320,8 @@ final class Dotenv
|
|||||||
}
|
}
|
||||||
$value = rtrim($value);
|
$value = rtrim($value);
|
||||||
$resolvedValue = $value;
|
$resolvedValue = $value;
|
||||||
$resolvedValue = $this->resolveVariables($resolvedValue);
|
$resolvedValue = $this->resolveVariables($resolvedValue, $loadedVars);
|
||||||
$resolvedValue = $this->resolveCommands($resolvedValue);
|
$resolvedValue = $this->resolveCommands($resolvedValue, $loadedVars);
|
||||||
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
|
$resolvedValue = str_replace('\\\\', '\\', $resolvedValue);
|
||||||
|
|
||||||
if ($resolvedValue === $value && preg_match('/\s+/', $value)) {
|
if ($resolvedValue === $value && preg_match('/\s+/', $value)) {
|
||||||
@ -372,7 +374,7 @@ final class Dotenv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveCommands($value)
|
private function resolveCommands($value, $loadedVars)
|
||||||
{
|
{
|
||||||
if (false === strpos($value, '$')) {
|
if (false === strpos($value, '$')) {
|
||||||
return $value;
|
return $value;
|
||||||
@ -388,7 +390,7 @@ final class Dotenv
|
|||||||
)
|
)
|
||||||
/x';
|
/x';
|
||||||
|
|
||||||
return preg_replace_callback($regex, function ($matches) {
|
return preg_replace_callback($regex, function ($matches) use ($loadedVars) {
|
||||||
if ('\\' === $matches[1]) {
|
if ('\\' === $matches[1]) {
|
||||||
return substr($matches[0], 1);
|
return substr($matches[0], 1);
|
||||||
}
|
}
|
||||||
@ -403,7 +405,15 @@ final class Dotenv
|
|||||||
|
|
||||||
$process = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline('echo '.$matches[0]) : new Process('echo '.$matches[0]);
|
$process = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline('echo '.$matches[0]) : new Process('echo '.$matches[0]);
|
||||||
$process->inheritEnvironmentVariables(true);
|
$process->inheritEnvironmentVariables(true);
|
||||||
$process->setEnv($this->values);
|
|
||||||
|
$env = [];
|
||||||
|
foreach ($this->values as $name => $value) {
|
||||||
|
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
|
||||||
|
$env[$name] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$process->setEnv($env);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$process->mustRun();
|
$process->mustRun();
|
||||||
} catch (ProcessException $e) {
|
} catch (ProcessException $e) {
|
||||||
@ -414,7 +424,7 @@ final class Dotenv
|
|||||||
}, $value);
|
}, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveVariables($value)
|
private function resolveVariables($value, array $loadedVars)
|
||||||
{
|
{
|
||||||
if (false === strpos($value, '$')) {
|
if (false === strpos($value, '$')) {
|
||||||
return $value;
|
return $value;
|
||||||
@ -430,7 +440,7 @@ final class Dotenv
|
|||||||
(?P<closing_brace>\})? # optional closing brace
|
(?P<closing_brace>\})? # optional closing brace
|
||||||
/x';
|
/x';
|
||||||
|
|
||||||
$value = preg_replace_callback($regex, function ($matches) {
|
$value = preg_replace_callback($regex, function ($matches) use ($loadedVars) {
|
||||||
// odd number of backslashes means the $ character is escaped
|
// odd number of backslashes means the $ character is escaped
|
||||||
if (1 === \strlen($matches['backslashes']) % 2) {
|
if (1 === \strlen($matches['backslashes']) % 2) {
|
||||||
return substr($matches[0], 1);
|
return substr($matches[0], 1);
|
||||||
@ -446,14 +456,16 @@ final class Dotenv
|
|||||||
}
|
}
|
||||||
|
|
||||||
$name = $matches['name'];
|
$name = $matches['name'];
|
||||||
if (isset($this->values[$name])) {
|
if (isset($loadedVars[$name]) && isset($this->values[$name])) {
|
||||||
$value = $this->values[$name];
|
$value = $this->values[$name];
|
||||||
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
|
|
||||||
$value = $_SERVER[$name];
|
|
||||||
} elseif (isset($_ENV[$name])) {
|
} elseif (isset($_ENV[$name])) {
|
||||||
$value = $_ENV[$name];
|
$value = $_ENV[$name];
|
||||||
|
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
|
||||||
|
$value = $_SERVER[$name];
|
||||||
|
} elseif (isset($this->values[$name])) {
|
||||||
|
$value = $this->values[$name];
|
||||||
} else {
|
} else {
|
||||||
$value = (string) getenv($name);
|
$value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$matches['opening_brace'] && isset($matches['closing_brace'])) {
|
if (!$matches['opening_brace'] && isset($matches['closing_brace'])) {
|
||||||
|
@ -69,6 +69,7 @@ class DotenvTest extends TestCase
|
|||||||
public function getEnvData()
|
public function getEnvData()
|
||||||
{
|
{
|
||||||
putenv('LOCAL=local');
|
putenv('LOCAL=local');
|
||||||
|
$_ENV['LOCAL'] = 'local';
|
||||||
$_ENV['REMOTE'] = 'remote';
|
$_ENV['REMOTE'] = 'remote';
|
||||||
$_SERVER['SERVERVAR'] = 'servervar';
|
$_SERVER['SERVERVAR'] = 'servervar';
|
||||||
|
|
||||||
@ -413,6 +414,22 @@ class DotenvTest extends TestCase
|
|||||||
$this->assertSame('/var/www', getenv('DOCUMENT_ROOT'));
|
$this->assertSame('/var/www', getenv('DOCUMENT_ROOT'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetVariablesValueFromEnvFirst()
|
||||||
|
{
|
||||||
|
$_ENV['APP_ENV'] = 'prod';
|
||||||
|
$dotenv = new Dotenv(true);
|
||||||
|
|
||||||
|
$test = "APP_ENV=dev\nTEST1=foo1_\${APP_ENV}";
|
||||||
|
$values = $dotenv->parse($test);
|
||||||
|
$this->assertSame('foo1_prod', $values['TEST1']);
|
||||||
|
|
||||||
|
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
||||||
|
$test = "APP_ENV=dev\nTEST2=foo2_\$(php -r 'echo \$_SERVER[\"APP_ENV\"];')";
|
||||||
|
$values = $dotenv->parse($test);
|
||||||
|
$this->assertSame('foo2_prod', $values['TEST2']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation The default value of "$usePutenv" argument of "%s" will be changed from "true" to "false" in Symfony 5.0. You should define its value explicitly.
|
* @expectedDeprecation The default value of "$usePutenv" argument of "%s" will be changed from "true" to "false" in Symfony 5.0. You should define its value explicitly.
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"php": "^7.1.3"
|
"php": "^7.1.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/process": "~3.4|~4.0"
|
"symfony/process": "^3.4.2|^4.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Dotenv\\": "" },
|
"psr-4": { "Symfony\\Component\\Dotenv\\": "" },
|
||||||
|
@ -94,7 +94,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
|
|
||||||
$type = trim(ob_get_clean());
|
$type = trim(ob_get_clean());
|
||||||
|
|
||||||
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
|
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) {
|
||||||
// it's not a type, but an error message
|
// it's not a type, but an error message
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
|
|
||||||
$type = trim(ob_get_clean());
|
$type = trim(ob_get_clean());
|
||||||
|
|
||||||
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
|
if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) {
|
||||||
// it's not a type, but an error message
|
// it's not a type, but an error message
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class CliDumper extends AbstractDumper
|
|||||||
protected $maxStringWidth = 0;
|
protected $maxStringWidth = 0;
|
||||||
protected $styles = [
|
protected $styles = [
|
||||||
// See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
// See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
||||||
'default' => '38;5;208',
|
'default' => '0;38;5;208',
|
||||||
'num' => '1;38;5;38',
|
'num' => '1;38;5;38',
|
||||||
'const' => '1;38;5;208',
|
'const' => '1;38;5;208',
|
||||||
'str' => '1;38;5;113',
|
'str' => '1;38;5;113',
|
||||||
|
Reference in New Issue
Block a user