承接 dlapps/consul-php-envvar 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dlapps/consul-php-envvar

Composer 安装命令:

composer require dlapps/consul-php-envvar

包简介

Define missing environment variables from Consul KV and expose them in Symfony 3.2+ containers

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score SensioLabsInsight Total Downloads

The library enables developers to retrieve missing environment variables from a Consul KV store and make them available in a running PHP process, and also in a Symfony 3.2+ container.

The package supports PSR-4 autoloading, is PSR-2 compliant and has been well tested through automated tests. The library is also actively used within the Dreamlabs ecosystem.

Install

Via Composer

$ composer require dlapps/consul-php-envvar

Usage

In order to be able to interact with the library, an instance of the ConsulEnvManager class is required. One can easily be obtained through the dedicated builder, like so:

$manager = (new ConsulEnvManagerBuilder())->build();

The same builder can be customised:

  • By setting the overwrite flag to true, even if an environment variable has been previously defined, it will still be updated with the latest from Consul.
  • By setting the URL of the Consul server.
$manager = (new ConsulEnvManagerBuilder())
    ->withOverwriteEvenIfDefined(true)
    ->withConsulServer('https://consul.example.com:9123')
    ->build();

Once a ConsulEnvManager instance has been obtained, the ConsulEnvManager::getEnvVarsFromConsul($mappings) method can be used to provide an array of environment variable mappings to Consul KV paths. An example can be seen below:

$manager = (new ConsulEnvManagerBuilder())->build();

$manager->getEnvVarsFromConsul([
    'MYSQL_HOST' => 'dreamlabs/mysql/host',
    'MYSQL_PORT' => 'dreamlabs/mysql/port',
    'MYSQL_DB'   => 'dreamlabs/mysql/db',
    'MYSQL_USER' => 'dreamlabs/mysql/user',
    'MYSQL_PASS' => 'dreamlabs/mysql/pass',
]);

After running the snippet above, the currently running PHP process will have access to the MYSQL_HOST, MYSQL_PORT, MYSQL_DB, MYSQL_USER and MYSQL_PASS environment variables.

In order to also register the environment variables within a Symfony 3.2+ container as default values, the ConsulEnvManager::exposeEnvironmentIntoContainer($container, $mappings) method can be used.

An example of parameters.php and parameters.yml can be found below:

declare(strict_types = 1);

$manager = (new \DL\ConsulPhpEnvVar\Builder\ConsulEnvManagerBuilder())->build();

$mappings = [
    'MYSQL_HOST'          => 'dreamlabs/mysql/host',
    'MYSQL_PORT'          => 'dreamlabs/mysql/port',
    'MYSQL_DB'            => 'dreamlabs/mysql/db',
    'MYSQL_USER'          => 'dreamlabs/mysql/user',
    'MYSQL_PASS'          => 'dreamlabs/mysql/pass',
];

$manager->getEnvVarsFromConsul($mappings);
$manager->exposeEnvironmentIntoContainer($container, $mappings);
parameters:
    database_host: '%env(MYSQL_HOST)%'
    database_port: '%env(MYSQL_PORT)%'
    database_name: '%env(MYSQL_DB)%'
    database_user: '%env(MYSQL_USER)%'
    database_password: '%env(MYSQL_PASS)%'

Testing

$ composer test

PSR-2 Compatibility

$ composer check-styles
$ composer fix-styles

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email petre [at] dreamlabs.ro instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 117
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 6
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固