|
| 1 | +<?php |
| 2 | + |
| 3 | +use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; |
| 4 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
| 5 | +use Symfony\Component\DependencyInjection\Container; |
| 6 | +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 7 | +use Symfony\Component\DependencyInjection\Exception\LogicException; |
| 8 | +use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
| 9 | +use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; |
| 10 | + |
| 11 | +/** |
| 12 | + * This class has been auto-generated |
| 13 | + * by the Symfony Dependency Injection Component. |
| 14 | + * |
| 15 | + * @final since Symfony 3.3 |
| 16 | + */ |
| 17 | +class Symfony_DI_PhpDumper_Test_UrlParameters extends Container |
| 18 | +{ |
| 19 | + private $parameters; |
| 20 | + private $targetDirs = []; |
| 21 | + |
| 22 | + public function __construct() |
| 23 | + { |
| 24 | + $this->parameters = $this->getDefaultParameters(); |
| 25 | + |
| 26 | + $this->services = $this->privates = []; |
| 27 | + |
| 28 | + $this->aliases = []; |
| 29 | + } |
| 30 | + |
| 31 | + public function compile() |
| 32 | + { |
| 33 | + throw new LogicException('You cannot compile a dumped container that was already compiled.'); |
| 34 | + } |
| 35 | + |
| 36 | + public function isCompiled() |
| 37 | + { |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + public function getRemovedIds() |
| 42 | + { |
| 43 | + return [ |
| 44 | + 'Psr\\Container\\ContainerInterface' => true, |
| 45 | + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, |
| 46 | + ]; |
| 47 | + } |
| 48 | + |
| 49 | + public function getParameter($name) |
| 50 | + { |
| 51 | + $name = (string) $name; |
| 52 | + |
| 53 | + if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) { |
| 54 | + throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); |
| 55 | + } |
| 56 | + if (isset($this->loadedDynamicParameters[$name])) { |
| 57 | + return $this->loadedDynamicParameters[$name] ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); |
| 58 | + } |
| 59 | + |
| 60 | + return $this->parameters[$name]; |
| 61 | + } |
| 62 | + |
| 63 | + public function hasParameter($name) |
| 64 | + { |
| 65 | + $name = (string) $name; |
| 66 | + |
| 67 | + return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters); |
| 68 | + } |
| 69 | + |
| 70 | + public function setParameter($name, $value) |
| 71 | + { |
| 72 | + throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); |
| 73 | + } |
| 74 | + |
| 75 | + public function getParameterBag() |
| 76 | + { |
| 77 | + if (null === $this->parameterBag) { |
| 78 | + $parameters = $this->parameters; |
| 79 | + foreach ($this->loadedDynamicParameters as $name => $loaded) { |
| 80 | + $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); |
| 81 | + } |
| 82 | + $this->parameterBag = new FrozenParameterBag($parameters); |
| 83 | + } |
| 84 | + |
| 85 | + return $this->parameterBag; |
| 86 | + } |
| 87 | + |
| 88 | + private $loadedDynamicParameters = [ |
| 89 | + 'hello' => false, |
| 90 | + ]; |
| 91 | + private $dynamicParameters = []; |
| 92 | + |
| 93 | + /** |
| 94 | + * Computes a dynamic parameter. |
| 95 | + * |
| 96 | + * @param string $name The name of the dynamic parameter to load |
| 97 | + * |
| 98 | + * @return mixed The value of the dynamic parameter |
| 99 | + * |
| 100 | + * @throws InvalidArgumentException When the dynamic parameter does not exist |
| 101 | + */ |
| 102 | + private function getDynamicParameter($name) |
| 103 | + { |
| 104 | + switch ($name) { |
| 105 | + case 'hello': $value = $this->getEnv('url:foo'); break; |
| 106 | + default: throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); |
| 107 | + } |
| 108 | + $this->loadedDynamicParameters[$name] = true; |
| 109 | + |
| 110 | + return $this->dynamicParameters[$name] = $value; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Gets the default parameters. |
| 115 | + * |
| 116 | + * @return array An array of the default parameters |
| 117 | + */ |
| 118 | + protected function getDefaultParameters() |
| 119 | + { |
| 120 | + return [ |
| 121 | + 'env(foo)' => 'postgres://user@localhost:5432/database?sslmode=disable', |
| 122 | + ]; |
| 123 | + } |
| 124 | +} |
0 commit comments