mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-01 14:38:47 +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:
@@ -19,17 +19,14 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
*/
|
||||
class EnvPlaceholderParameterBag extends ParameterBag
|
||||
{
|
||||
private $envPlaceholderUniquePrefix;
|
||||
private $envPlaceholders = [];
|
||||
private $unusedEnvPlaceholders = [];
|
||||
private $providedTypes = [];
|
||||
private string $envPlaceholderUniquePrefix;
|
||||
private array $envPlaceholders = [];
|
||||
private array $unusedEnvPlaceholders = [];
|
||||
private array $providedTypes = [];
|
||||
|
||||
private static $counter = 0;
|
||||
private static int $counter = 0;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get(string $name)
|
||||
public function get(string $name): array|bool|string|int|float|\UnitEnum|null
|
||||
{
|
||||
if (str_starts_with($name, 'env(') && str_ends_with($name, ')') && 'env()' !== $name) {
|
||||
$env = substr($name, 4, -1);
|
||||
@@ -44,15 +41,15 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
return $placeholder; // return first result
|
||||
}
|
||||
}
|
||||
if (!preg_match('/^(?:[-.\w]*+:)*+\w++$/', $env)) {
|
||||
if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w*+$/', $env)) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
|
||||
}
|
||||
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
|
||||
throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', get_debug_type($defaultValue), $name));
|
||||
}
|
||||
|
||||
$uniqueName = md5($name.'_'.self::$counter++);
|
||||
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.', '___'), $uniqueName);
|
||||
$uniqueName = hash('xxh128', $name.'_'.self::$counter++);
|
||||
$placeholder = sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), strtr($env, ':-.\\', '____'), $uniqueName);
|
||||
$this->envPlaceholders[$env][$placeholder] = $placeholder;
|
||||
|
||||
return $placeholder;
|
||||
@@ -66,10 +63,10 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
*/
|
||||
public function getEnvPlaceholderUniquePrefix(): string
|
||||
{
|
||||
if (null === $this->envPlaceholderUniquePrefix) {
|
||||
if (!isset($this->envPlaceholderUniquePrefix)) {
|
||||
$reproducibleEntropy = unserialize(serialize($this->parameters));
|
||||
array_walk_recursive($reproducibleEntropy, function (&$v) { $v = null; });
|
||||
$this->envPlaceholderUniquePrefix = 'env_'.substr(md5(serialize($reproducibleEntropy)), -16);
|
||||
$this->envPlaceholderUniquePrefix = 'env_'.substr(hash('xxh128', serialize($reproducibleEntropy)), -16);
|
||||
}
|
||||
|
||||
return $this->envPlaceholderUniquePrefix;
|
||||
@@ -80,7 +77,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
*
|
||||
* @return string[][] A map of env var names to their placeholders
|
||||
*/
|
||||
public function getEnvPlaceholders()
|
||||
public function getEnvPlaceholders(): array
|
||||
{
|
||||
return $this->envPlaceholders;
|
||||
}
|
||||
@@ -90,6 +87,9 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
return $this->unusedEnvPlaceholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function clearUnusedEnvPlaceholders()
|
||||
{
|
||||
$this->unusedEnvPlaceholders = [];
|
||||
@@ -97,6 +97,8 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
|
||||
/**
|
||||
* Merges the env placeholders of another EnvPlaceholderParameterBag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mergeEnvPlaceholders(self $bag)
|
||||
{
|
||||
@@ -119,6 +121,8 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
|
||||
/**
|
||||
* Maps env prefixes to their corresponding PHP types.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setProvidedTypes(array $providedTypes)
|
||||
{
|
||||
@@ -130,13 +134,13 @@ class EnvPlaceholderParameterBag extends ParameterBag
|
||||
*
|
||||
* @return string[][]
|
||||
*/
|
||||
public function getProvidedTypes()
|
||||
public function getProvidedTypes(): array
|
||||
{
|
||||
return $this->providedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
public function resolve()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user