mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-02 06:58:49 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -29,28 +29,19 @@ final class Dotenv
|
||||
public const STATE_VARNAME = 0;
|
||||
public const STATE_VALUE = 1;
|
||||
|
||||
private $path;
|
||||
private $cursor;
|
||||
private $lineno;
|
||||
private $data;
|
||||
private $end;
|
||||
private $values;
|
||||
private $envKey;
|
||||
private $debugKey;
|
||||
private $prodEnvs = ['prod'];
|
||||
private $usePutenv = false;
|
||||
private string $path;
|
||||
private int $cursor;
|
||||
private int $lineno;
|
||||
private string $data;
|
||||
private int $end;
|
||||
private array $values = [];
|
||||
private string $envKey;
|
||||
private string $debugKey;
|
||||
private array $prodEnvs = ['prod'];
|
||||
private bool $usePutenv = false;
|
||||
|
||||
/**
|
||||
* @param string $envKey
|
||||
*/
|
||||
public function __construct($envKey = 'APP_ENV', string $debugKey = 'APP_DEBUG')
|
||||
public function __construct(string $envKey = 'APP_ENV', string $debugKey = 'APP_DEBUG')
|
||||
{
|
||||
if (\in_array($envKey = (string) $envKey, ['1', ''], true)) {
|
||||
trigger_deprecation('symfony/dotenv', '5.1', 'Passing a boolean to the constructor of "%s" is deprecated, use "Dotenv::usePutenv()".', __CLASS__);
|
||||
$this->usePutenv = (bool) $envKey;
|
||||
$envKey = 'APP_ENV';
|
||||
}
|
||||
|
||||
$this->envKey = $envKey;
|
||||
$this->debugKey = $debugKey;
|
||||
}
|
||||
@@ -58,7 +49,7 @@ final class Dotenv
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setProdEnvs(array $prodEnvs): self
|
||||
public function setProdEnvs(array $prodEnvs): static
|
||||
{
|
||||
$this->prodEnvs = $prodEnvs;
|
||||
|
||||
@@ -67,11 +58,11 @@ final class Dotenv
|
||||
|
||||
/**
|
||||
* @param bool $usePutenv If `putenv()` should be used to define environment variables or not.
|
||||
* Beware that `putenv()` is not thread safe, that's why this setting defaults to false
|
||||
* Beware that `putenv()` is not thread safe, that's why it's not enabled by default
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function usePutenv(bool $usePutenv = true): self
|
||||
public function usePutenv(bool $usePutenv = true): static
|
||||
{
|
||||
$this->usePutenv = $usePutenv;
|
||||
|
||||
@@ -81,8 +72,8 @@ final class Dotenv
|
||||
/**
|
||||
* Loads one or several .env files.
|
||||
*
|
||||
* @param string $path A file to load
|
||||
* @param string[] ...$extraPaths A list of additional files to load
|
||||
* @param string $path A file to load
|
||||
* @param string ...$extraPaths A list of additional files to load
|
||||
*
|
||||
* @throws FormatException when a file has a syntax error
|
||||
* @throws PathException when a file does not exist or is not readable
|
||||
@@ -98,10 +89,11 @@ final class Dotenv
|
||||
* .env.local is always ignored in test env because tests should produce the same results for everyone.
|
||||
* .env.dist is loaded when it exists and .env is not found.
|
||||
*
|
||||
* @param string $path A file to load
|
||||
* @param string $envKey|null The name of the env vars that defines the app env
|
||||
* @param string $defaultEnv The app env to use when none is defined
|
||||
* @param array $testEnvs A list of app envs for which .env.local should be ignored
|
||||
* @param string $path A file to load
|
||||
* @param string|null $envKey The name of the env vars that defines the app env
|
||||
* @param string $defaultEnv The app env to use when none is defined
|
||||
* @param array $testEnvs A list of app envs for which .env.local should be ignored
|
||||
* @param bool $overrideExistingVars Whether existing environment variables set by the system should be overridden
|
||||
*
|
||||
* @throws FormatException when a file has a syntax error
|
||||
* @throws PathException when a file does not exist or is not readable
|
||||
@@ -161,14 +153,14 @@ final class Dotenv
|
||||
|
||||
$k = $this->debugKey;
|
||||
$debug = $_SERVER[$k] ?? !\in_array($_SERVER[$this->envKey], $this->prodEnvs, true);
|
||||
$_SERVER[$k] = $_ENV[$k] = (int) $debug || (!\is_bool($debug) && filter_var($debug, \FILTER_VALIDATE_BOOLEAN)) ? '1' : '0';
|
||||
$_SERVER[$k] = $_ENV[$k] = (int) $debug || (!\is_bool($debug) && filter_var($debug, \FILTER_VALIDATE_BOOL)) ? '1' : '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads one or several .env files and enables override existing vars.
|
||||
*
|
||||
* @param string $path A file to load
|
||||
* @param string[] ...$extraPaths A list of additional files to load
|
||||
* @param string $path A file to load
|
||||
* @param string ...$extraPaths A list of additional files to load
|
||||
*
|
||||
* @throws FormatException when a file has a syntax error
|
||||
* @throws PathException when a file does not exist or is not readable
|
||||
@@ -182,7 +174,7 @@ final class Dotenv
|
||||
* Sets values as environment variables (via putenv, $_ENV, and $_SERVER).
|
||||
*
|
||||
* @param array $values An array of env variables
|
||||
* @param bool $overrideExistingVars true when existing environment variables must be overridden
|
||||
* @param bool $overrideExistingVars Whether existing environment variables set by the system should be overridden
|
||||
*/
|
||||
public function populate(array $values, bool $overrideExistingVars = false): void
|
||||
{
|
||||
@@ -190,7 +182,7 @@ final class Dotenv
|
||||
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));
|
||||
|
||||
foreach ($values as $name => $value) {
|
||||
$notHttpName = 0 !== strpos($name, 'HTTP_');
|
||||
$notHttpName = !str_starts_with($name, 'HTTP_');
|
||||
if (isset($_SERVER[$name]) && $notHttpName && !isset($_ENV[$name])) {
|
||||
$_ENV[$name] = $_SERVER[$name];
|
||||
}
|
||||
@@ -268,8 +260,7 @@ final class Dotenv
|
||||
return $this->values;
|
||||
} finally {
|
||||
$this->values = [];
|
||||
$this->data = null;
|
||||
$this->path = null;
|
||||
unset($this->path, $this->cursor, $this->lineno, $this->data, $this->end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +305,7 @@ final class Dotenv
|
||||
throw $this->createFormatException('Whitespace are not supported before the value');
|
||||
}
|
||||
|
||||
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? ($_ENV['SYMFONY_DOTENV_VARS'] ?? '')));
|
||||
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));
|
||||
unset($loadedVars['']);
|
||||
$v = '';
|
||||
|
||||
@@ -420,7 +411,7 @@ final class Dotenv
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function skipEmptyLines()
|
||||
private function skipEmptyLines(): void
|
||||
{
|
||||
if (preg_match('/(?:\s*+(?:#[^\n]*+)?+)++/A', $this->data, $match, 0, $this->cursor)) {
|
||||
$this->moveCursor($match[0]);
|
||||
@@ -429,7 +420,7 @@ final class Dotenv
|
||||
|
||||
private function resolveCommands(string $value, array $loadedVars): string
|
||||
{
|
||||
if (false === strpos($value, '$')) {
|
||||
if (!str_contains($value, '$')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -453,19 +444,14 @@ final class Dotenv
|
||||
}
|
||||
|
||||
if (!class_exists(Process::class)) {
|
||||
throw new \LogicException('Resolving commands requires the Symfony Process component.');
|
||||
throw new \LogicException('Resolving commands requires the Symfony Process component. Try running "composer require symfony/process".');
|
||||
}
|
||||
|
||||
$process = method_exists(Process::class, 'fromShellCommandline') ? Process::fromShellCommandline('echo '.$matches[0]) : new Process('echo '.$matches[0]);
|
||||
|
||||
if (!method_exists(Process::class, 'fromShellCommandline') && method_exists(Process::class, 'inheritEnvironmentVariables')) {
|
||||
// Symfony 3.4 does not inherit env vars by default:
|
||||
$process->inheritEnvironmentVariables();
|
||||
}
|
||||
$process = Process::fromShellCommandline('echo '.$matches[0]);
|
||||
|
||||
$env = [];
|
||||
foreach ($this->values as $name => $value) {
|
||||
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
|
||||
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')))) {
|
||||
$env[$name] = $value;
|
||||
}
|
||||
}
|
||||
@@ -473,7 +459,7 @@ final class Dotenv
|
||||
|
||||
try {
|
||||
$process->mustRun();
|
||||
} catch (ProcessException $e) {
|
||||
} catch (ProcessException) {
|
||||
throw $this->createFormatException(sprintf('Issue expanding a command (%s)', $process->getErrorOutput()));
|
||||
}
|
||||
|
||||
@@ -483,7 +469,7 @@ final class Dotenv
|
||||
|
||||
private function resolveVariables(string $value, array $loadedVars): string
|
||||
{
|
||||
if (false === strpos($value, '$')) {
|
||||
if (!str_contains($value, '$')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -518,7 +504,7 @@ final class Dotenv
|
||||
$value = $this->values[$name];
|
||||
} elseif (isset($_ENV[$name])) {
|
||||
$value = $_ENV[$name];
|
||||
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
|
||||
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
|
||||
$value = $_SERVER[$name];
|
||||
} elseif (isset($this->values[$name])) {
|
||||
$value = $this->values[$name];
|
||||
@@ -549,7 +535,7 @@ final class Dotenv
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function moveCursor(string $text)
|
||||
private function moveCursor(string $text): void
|
||||
{
|
||||
$this->cursor += \strlen($text);
|
||||
$this->lineno += substr_count($text, "\n");
|
||||
|
||||
Reference in New Issue
Block a user