slashlead/configuration

使用 league/container 服务提供者的配置读取器

dev-master 2016-12-01 16:29 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:05:07 UTC


README

使用 league/container 服务提供者的配置读取器

安装

yml 扩展名

pecl install yml

composer

composer require slashlead/configuration

配置文件

配置存储路径和环境名称必须在 $_SERVER 中公开。

键名包括

  • application_mode,加载的 yml 文件名称
  • config_dir,存储配置文件的目录

配置文件需要存储为 yml 格式

如何使用

提供的服务

解析后的配置数组将以别名 "configStore" 提供给容器

示例代码

<?php
/*
 For demo use we set $_SERVER parameters in this script
 with this example code the following config will be loaded
 /var/www/html/config/development.yml
 */

$_SERVER['application_mode'] = 'development';
$_SERVER['config_dir']       = '/var/www/html/config';

$container = new \League\Container\Container();
$container->addServiceProvider(new Slashlead\Component\Configuration\ServiceProvider);

print_r($container->get('configStore'));