Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
EnvPlaceholderParameterBag.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\DependencyInjection\ParameterBag;
013
014 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
015 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
016
017 /**
018 * @author Nicolas Grekas <p@tchwork.com>
019 */
020 class EnvPlaceholderParameterBag extends ParameterBag
021 {
022 private $envPlaceholders = [];
023 private $providedTypes = [];
024
025 /**
026 * {@inheritdoc}
027 */
028 public function get($name)
029 {
030 if (0 === strpos($name, 'env(') && ')' === substr($name, -1) && 'env()' !== $name) {
031 $env = substr($name, 4, -1);
032
033 if (isset($this->envPlaceholders[$env])) {
034 foreach ($this->envPlaceholders[$env] as $placeholder) {
035 return $placeholder; // return first result
036 }
037 }
038 if (!preg_match('/^(?:\w++:)*+\w++$/', $env)) {
039 throw new InvalidArgumentException(sprintf('Invalid "%s" name: only "word" characters are allowed.', $name));
040 }
041
042 if ($this->has($name)) {
043 $defaultValue = parent::get($name);
044
045 if (null !== $defaultValue && !is_scalar($defaultValue)) {
046 throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
047 }
048 }
049
050 $uniqueName = md5($name.uniqid(mt_rand(), true));
051 $placeholder = sprintf('env_%s_%s', str_replace(':', '_', $env), $uniqueName);
052 $this->envPlaceholders[$env][$placeholder] = $placeholder;
053
054 return $placeholder;
055 }
056
057 return parent::get($name);
058 }
059
060 /**
061 * Returns the map of env vars used in the resolved parameter values to their placeholders.
062 *
063 * @return string[][] A map of env var names to their placeholders
064 */
065 public function getEnvPlaceholders()
066 {
067 return $this->envPlaceholders;
068 }
069
070 /**
071 * Merges the env placeholders of another EnvPlaceholderParameterBag.
072 */
073 public function mergeEnvPlaceholders(self $bag)
074 {
075 if ($newPlaceholders = $bag->getEnvPlaceholders()) {
076 $this->envPlaceholders += $newPlaceholders;
077
078 foreach ($newPlaceholders as $env => $placeholders) {
079 $this->envPlaceholders[$env] += $placeholders;
080 }
081 }
082 }
083
084 /**
085 * Maps env prefixes to their corresponding PHP types.
086 */
087 public function setProvidedTypes(array $providedTypes)
088 {
089 $this->providedTypes = $providedTypes;
090 }
091
092 /**
093 * Gets the PHP types corresponding to env() parameter prefixes.
094 *
095 * @return string[][]
096 */
097 public function getProvidedTypes()
098 {
099 return $this->providedTypes;
100 }
101
102 /**
103 * {@inheritdoc}
104 */
105 public function resolve()
106 {
107 if ($this->resolved) {
108 return;
109 }
110 parent::resolve();
111
112 foreach ($this->envPlaceholders as $env => $placeholders) {
113 if (!$this->has($name = "env($env)")) {
114 continue;
115 }
116 if (is_numeric($default = $this->parameters[$name])) {
117 $this->parameters[$name] = (string) $default;
118 } elseif (null !== $default && !is_scalar($default)) {
119 throw new RuntimeException(sprintf('The default value of env parameter "%s" must be scalar or null, "%s" given.', $env, \gettype($default)));
120 }
121 }
122 }
123 }
124