zendframework / zend-config

Config component from Zend Framework
BSD 3-Clause "New" or "Revised" License
90 stars 38 forks source link

Added Env processor to allows users to read the value of the getenv() function in static configuration files. #52

Open eguvenc opened 6 years ago

eguvenc commented 6 years ago

This feature will allow getenv function to be run from static files like yaml.

Using Zend\Config\Processor\Env

This example illustrates the basic usage of Zend\Config\Processor\Env:

putenv('AMQP_PASSWORD=guest');

use Zend\Config\Config;
use Zend\Config\Factory;
use Zend\Config\Processor\Env as EnvProcessor;

$config = new Config([
            'host' => '127.0.0.1',
            'port' => 5672,
            'username' => 'guest',
            'password' => 'env(AMQP_PASSWORD)',
            'vhost' => '/',
        ], true);

$processor = new EnvProcessor;
$processor->process($config);
$config->setReadOnly();

echo $config->amqp->password;

This example returns the output: guest.

Xerkus commented 5 years ago

This functionality is already covered by Token processor:


use Zend\Config\Config;
use Zend\Config\Processor\Token;

putenv('AMQP_PASSWORD=guest');

$config = new Config([
            'host' => '127.0.0.1',
            'port' => 5672,
            'username' => 'guest',
            'password' => 'env(AMQP_PASSWORD)',
            'vhost' => '/',
        ], true);

$processor = new Token(getenv(), 'env(', ')');
$processor->process($config);
$config->setReadOnly();

echo $config->amqp->password;

What Token does not provide is detecting request for missing environment variable and throwing exception. But neither is this PR.

Xerkus commented 5 years ago

This PR is redundant as it is. Would you like to provide additional features that are not covered by existing options already or should I close it?

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-config; a new issue has been opened at https://github.com/laminas/laminas-config/issues/2.

weierophinney commented 4 years ago

This repository has been moved to laminas/laminas-config. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow: