定制 techsterx/slim-config-yaml 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

techsterx/slim-config-yaml

最新稳定版本:v1.0.6

Composer 安装命令:

composer require techsterx/slim-config-yaml

包简介

README 文档

README

Build Status StyleCI Total Downloads Latest Stable Version License

Parses YAML files and adds them into Slim's config singleton. Uses Symfony's YAML Component to parse files (http://github.com/symfony/Yaml). Allows other YAML files to be imported and parameters to be set and used.

Getting Started

Installation

Composer

Install composer in your project.

curl -s https://getcomposer.org/installer | php

Create a composer.json file in your project root:

{
	"require": {
		"techsterx/slim-config-yaml": "1.*"
	}
}

Install via composer:

php composer.phar install

Add this line to your application's index.php file:

<?php
require 'vendor/autoload.php';

Manual Install

Download and extract src/ directory into your project directory and require it in your application's index.php file.

<?php
require 'Slim\Slim.php';
require 'Yaml.php';

$app = new \Slim\Slim();

\BurningDiode\Slim\Config\Yaml::getInstance()->addFile('/path/to/some/file');

Methods

Slim Config - YAML uses a static method to get the currenct instance. If an instance doesn't exist, a new one will be created. Use the getInstance() method to get the current instance.

$slimYaml = \BurningDiode\Slim\Config\Yaml::getInstance();

_() is the shorthand equivalent of getInstance().

$slimYaml = \BurningDiode\Slim\Config\Yaml::_();

To add a single file, use the addFile() method.

\BurningDiode\Slim\Config\Yaml::getInstance()->addFile('/path/to/some/file.yaml');

You can also chain multiple addFile() methods togethor.

\BurningDiode\Slim\Config\Yaml::getInstance()
    ->addFile('/path/to/some/file.yaml')
    ->addFile('/path/to/another/file.yaml');

You can import a whole directory of YAML files.

\BurningDiode\Slim\Config\Yaml::getInstance()->addDirectory('/path/to/directory');

You can chain with the addDirectory() method as well.

\BurningDiode\Slim\Config\Yaml::getInstance()
    ->addDirectory('/path/to/directory')
    ->addFile('/path/to/some/file.yaml');

Specify some global parameters to be used by all YAML files processed.

\BurningDiode\Slim\Config\Yaml::_()
    ->addParameters(array('app.root' => dirname(__FILE__)))
    ->addDirectory('/path/to/config/directory')
    ->addFile('/path/to/file/outside/of/config/directory.yml');

Using Parameters

You can specify parameters in YAML files that will be replaced using keywords. Parameters are only available to the resource currently being processed.

config.yaml

parameters:
    key1: value1
    key2: value2
    
application:
    keya: %key1%
    keyb: %key2%

app.php

\BurningDiode\Slim\Config\Yaml::_()->addFile('config.yml');

$config = $app->config('application');

print_r($config);

Output:

Array
(
    [key1] => value1
    [key2] => value2
)

Importing Files

You can import other YAML files which can be useful to keep all your common parameters in one file and used in others.

parameters.yml

parameters:
    db_host:  localhost
    db_user:  username
    db_pass:  password
    db_dbase: database

database.yml

imports:
    - { resource: parameters.yml }
    
database:
    hostname: %db_host%
    username: %db_user%
    password: %db_pass%
    database: %db_dbase%

app.php

\BurningDiode\Slim\Config\Yaml::_()->addFile('database.yml');

$db_config = $app->config('database');

print_r($db_config);

Output:

Array
(
    [hostname] => localhost
    [username] => username
    [password] => password
    [database] => database
)

License

Slim Config - YAML is released under the [MIT public license] (https://raw.githubusercontent.com/techsterx/slim-config-yaml/master/LICENSE).

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固