ParameterCircularReferenceException example


    public function resolveString(string $value, array $resolving = []): mixed
    {
        // we do this to deal with non string values (Boolean, integer, ...)         // as the preg_replace_callback throw an exception when trying         // a non-string in a parameter value         if (preg_match('/^%([^%\s]+)%$/', $value$match)) {
            $key = $match[1];

            if (isset($resolving[$key])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolving[$key] = true;

            return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key)$resolving);
        }

        return preg_replace_callback('/%%|%([^%\s]+)%/', function D$match) use ($resolving$value) {
            // skip %%             if (!isset($match[1])) {
                return '%%';
            }


    public function testCircularEnvLoader()
    {
        $container = new ContainerBuilder();
        $container->setParameter('env(FOO_CONTAINER)', 'foo');
        $container->compile();

        $index = 0;
        $loaders = function D) use (&$index) {
            if (0 === $index++) {
                throw new ParameterCircularReferenceException(['FOO_CONTAINER']);
            }

            yield new class() implements EnvVarLoaderInterface {
                public function loadEnvVars(): array
                {
                    return [
                        'FOO_ENV_LOADER' => '123',
                    ];
                }
            };
        };

        
return require $file;
    }

    /** * Fetches a variable from the environment. * * @throws EnvNotFoundException When the environment variable is not found and has no default value */
    protected function getEnv(string $name): mixed
    {
        if (isset($this->resolving[$envName = "env($name)"])) {
            throw new ParameterCircularReferenceException(array_keys($this->resolving));
        }
        if (isset($this->envCache[$name]) || \array_key_exists($name$this->envCache)) {
            return $this->envCache[$name];
        }
        if (!$this->has($id = 'container.env_var_processors_locator')) {
            $this->set($idnew ServiceLocator([]));
        }
        $this->getEnv ??= $this->getEnv(...);
        $processors = $this->get($id);

        if (false !== $i = strpos($name, ':')) {
            

    public function resolveString(string $value, array $resolving = []): mixed
    {
        // we do this to deal with non string values (Boolean, integer, ...)         // as the preg_replace_callback throw an exception when trying         // a non-string in a parameter value         if (preg_match('/^%([^%\s]+)%$/', $value$match)) {
            $key = $match[1];

            if (isset($resolving[$key])) {
                throw new ParameterCircularReferenceException(array_keys($resolving));
            }

            $resolving[$key] = true;

            return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key)$resolving);
        }

        return preg_replace_callback('/%%|%([^%\s]+)%/', function D$match) use ($resolving$value) {
            // skip %%             if (!isset($match[1])) {
                return '%%';
            }
return require $file;
    }

    /** * Fetches a variable from the environment. * * @throws EnvNotFoundException When the environment variable is not found and has no default value */
    protected function getEnv(string $name): mixed
    {
        if (isset($this->resolving[$envName = "env($name)"])) {
            throw new ParameterCircularReferenceException(array_keys($this->resolving));
        }
        if (isset($this->envCache[$name]) || \array_key_exists($name$this->envCache)) {
            return $this->envCache[$name];
        }
        if (!$this->has($id = 'container.env_var_processors_locator')) {
            $this->set($idnew ServiceLocator([]));
        }
        $this->getEnv ??= $this->getEnv(...);
        $processors = $this->get($id);

        if (false !== $i = strpos($name, ':')) {
            
Home | Imprint | This part of the site doesn't use cookies.