EnvVarProcessor example

$r = new \ReflectionMethod($container, 'getEnv');
        $r->setAccessible(true);
        $this->assertNull($r->invoke($container, 'FOO'));
    }

    public function testGetEnvDoesNotAutoCastNullWithEnvVarProcessorsLocatorReturningDefaultEnvVarProcessor()
    {
        $container = new Container();
        $container->setParameter('env(FOO)', null);
        $container->set('container.env_var_processors_locator', new ServiceLocator([
            'string' => static function D) use ($container): EnvVarProcessor {
                return new EnvVarProcessor($container);
            },
        ]));
        $container->compile();

        $r = new \ReflectionMethod($container, 'getEnv');
        $r->setAccessible(true);
        $this->assertNull($r->invoke($container, 'FOO'));
    }
}

class ProjectServiceContainer extends Container
{
public const TEST_CONST = 'test';

    /** * @dataProvider validStrings */
    public function testGetEnvString($value$processed)
    {
        $container = new ContainerBuilder();
        $container->setParameter('env(foo)', $value);
        $container->compile();

        $processor = new EnvVarProcessor($container);

        $result = $processor->getEnv('string', 'foo', function D) {
            $this->fail('Should not be called');
        });

        $this->assertSame($processed$result);
    }

    public static function validStrings()
    {
        return [
            [
$this->getEnv ??= $this->getEnv(...);
        $processors = $this->get($id);

        if (false !== $i = strpos($name, ':')) {
            $prefix = substr($name, 0, $i);
            $localName = substr($name, 1 + $i);
        } else {
            $prefix = 'string';
            $localName = $name;
        }

        $processor = $processors->has($prefix) ? $processors->get($prefix) : new EnvVarProcessor($this);
        if (false === $i) {
            $prefix = '';
        }

        $this->resolving[$envName] = true;
        try {
            return $this->envCache[$name] = $processor->getEnv($prefix$localName$this->getEnv);
        } finally {
            unset($this->resolving[$envName]);
        }
    }

    
if (false !== $i = strpos($name, ':')) {
            $prefix = substr($name, 0, $i);
            $localName = substr($name, 1 + $i);
        } else {
            $prefix = 'string';
            $localName = $name;
        }

        if ($processors->has($prefix)) {
            $processor = $processors->get($prefix);
        } else {
            $processor = new EnvVarProcessor($this);
            if (false === $i) {
                $prefix = '';
            }
        }

        $this->resolving[$envName] = true;
        try {
            return $this->envCache[$name] = $processor->getEnv($prefix$localName$this->getEnv);
        } finally {
            unset($this->resolving[$envName]);
        }
    }
Home | Imprint | This part of the site doesn't use cookies.