nuvoleweb / robo-config
Robo 的 CI/开发者友好的配置处理器。
3.0.0
2022-12-08 12:04 UTC
Requires
- consolidation/robo: ^4.0
Requires (Dev)
- drupal/coder: ^8.3.16
- phpro/grumphp: ^1.14
- phpunit/phpunit: ^9.5.5
This package is auto-updated.
Last update: 2024-09-08 16:06:45 UTC
README
Robo Config 通过以下特性提供 Robo 的灵活配置处理:
- 在
robo.yml.dist
中定义默认配置,并允许开发者在本地使用robo.yml
进行覆盖。 - 允许配置文件使用与同一配置中定义的属性,类似于 Phing 的方式。
- 允许在命令行中覆盖所有属性,以便在运行持续集成构建时进行调整。
- 通过
$this->config('my.configuration.property
);` 访问任何配置参数。
安装
通过运行以下命令使用 Composer 安装:
$ composer require nuvoleweb/robo-config
用法
安装后,将以下特质添加到您的 RoboFile.php
中:
<?php class RoboFile extends Robo\Tasks { use NuvoleWeb\Robo\Task\Config\loadTasks; }
例如,考虑以下 robo.yml.dist
文件:
site: name: "Default site name" email: "me@example.com" url: "http://localhost" account: name: "admin" password: !account.name email: !site.email
以及以下 robo.yml
文件:
site: name: "My site name"
当运行时:
./vendor/bin/robo my-command -o "site.url: http://127.0.0.1:8888"
生成的配置将是:
site: name: "My site name" email: "me@example.com" url: "http://127.0.0.1:8888" account: name: "admin" password: "admin" email: "me@example.com"
PHP 文件中的 Robo 配置
Robo Config 提供了三个任务,可以将 YAML 配置子集转换为 PHP 数组。然后,此数组将被附加、预添加或写入 PHP 目标文件中作为数组。
这对于部分配置在 PHP 文件中表达的应用程序可能很有用,如 Drupal 或 Silex。
例如,以下 YAML 部分:
settings: config: system.logging: error_level: verbose settings: scan_tests: TRUE
将转换为:
// Start settings processor block. $config["system.logging"] = array('error_level' => 'verbose'); $settings["scan_tests"] = true; // End settings processor block.
并添加到 PHP 文件中。
附加任务
给定现有的 /my/config.php
文件,通过调用
<?php class RoboFile { public function appendTask() { $this->taskAppendConfiguration('/my/config.php')->run(); } }
我们将得到以下结果:
<?php // Content of /my/config.php here... // Start settings processor block. $config["system.logging"] = array('error_level' => 'verbose'); $settings["scan_tests"] = true; // End settings processor block.
预添加任务
给定现有的 /my/config.php
文件,通过调用
<?php class RoboFile { public function appendTask() { $this->taskPrependConfiguration('/my/config.php')->run(); } }
我们将得到以下结果:
<?php // Start settings processor block. $config["system.logging"] = array('error_level' => 'verbose'); $settings["scan_tests"] = true; // End settings processor block. // Content of /my/config.php here...
写入任务
给定不存在的 /my/config.php
文件,通过调用
<?php class RoboFile { public function appendTask() { $this->taskWriteConfiguration('/my/config.php')->run(); } }
我们将得到以下结果:
<?php // Start settings processor block. $config["system.logging"] = array('error_level' => 'verbose'); $settings["scan_tests"] = true; // End settings processor block.
配置任务
以上所有任务的行为可以根据以下方式自定义:
<?php class RoboFile { public function myTask() { $config = $this->getMyConfiguration(); $this->taskAppendConfiguration('/my/config.php', $config) // Use custom configuration. ->setBlockStart('// Start') // Change opening comment. ->setBlockEnd('// End') // Change closing comment. ->setConfigKey('parameters') // Use `parameters:` instead of default `settings:` ->run(); } }
独立使用
如果您只想在自定义 Robo 应用程序中使用上述 PHP 配置文件处理任务,您可以通过包含以下特质来加载它们:
<?php class RoboFile { use \NuvoleWeb\Robo\Task\Config\Php\loadTasks; }