Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

eguvenc
Copy link

@eguvenc eguvenc commented Jun 15, 2018

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
Copy link
Member

Xerkus commented May 16, 2019

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
Copy link
Member

Xerkus commented May 20, 2019

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
Copy link
Member

This repository has been closed and moved to laminas/laminas-config; a new issue has been opened at laminas/laminas-config#2.

@weierophinney
Copy link
Member

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:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-config to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-config.
  • In your clone of laminas/laminas-config, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants