anax / configure
Anax 配置模块,用于读取配置文件。
v2.0.1
2020-11-19 21:51 UTC
Requires
- php: ^7.2
Requires (Dev)
- anax/di: ^2.0.4
- phpstan/phpstan: ^0.12.56
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-20 06:16:49 UTC
README
读取 Anax 和 Anax 模块的配置文件。
模块的配置文件可以存储在几个基本目录之一中。配置类扫描所有有效的基本目录,并在找到第一个包含配置项的目录时停止。
配置项可以存储在文件中,也可以存储在包含多个文件的目录中。所有文件都被加载并合并到一个数组中,该数组包含模块配置的每个部分。
安装
$ composer require anax/configure
相关类
这些是本模块中包含的类,以及它们的主要用途。
作为 DI 服务使用
您可以将配置对象创建为 $di 服务。Anax 就是这样做。
示例用法
创建一个可以读取配置文件的对象。
首先创建对象,并将其指向一组目录。
$config = new \Anax\Configure\Configuration(); $dirs = ["path1", "path2"]; $config->setBaseDirectories($dirs);
现在使用该对象查找并加载项目的配置文件,在示例中我们使用 "router" 模块作为示例。
$config = $di->get("configuration")->load("route")
现在 $config
将包含从文件或文件中找到的配置项。您现在可以将数组提供给应该使用它的模块或对象。
配置文件
模块 "route" 的配置文件可以是以下之一,或者它们的组合。
文件应该返回一个值,这将作为其对配置的贡献。
配置数组
生成的配置数组看起来像这样,仍然使用 "route" 作为模块名称的示例。
$config = [ "file" => filename for route.php, "config" => result returned from route.php, "items" => [ [ "file" => filename for route/file1.php, "config" => result returned from route/file1.php, ], [ "file" => filename for route/file2.php, "config" => result returned from route/file2.php, ], ]. ];
"route" 模块可以决定如何使用实际的配置细节。
依赖关系
没有依赖关系。
许可
此软件附带 MIT 许可证。有关详细信息,请参阅 LICENSE.txt。
.
..: Copyright (c) 2013 - 2018 Mikael Roos, mos@dbwebb.se