定制 jameswmcnab/config-yaml 二次开发

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

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

jameswmcnab/config-yaml

最新稳定版本:v3.0.0

Composer 安装命令:

composer require jameswmcnab/config-yaml

包简介

A simple YAML config file loader for Laravel, taking inspiration from illuminate/config.

README 文档

README

This package is abandoned and no longer maintained. The author suggests using the pragmarx/yaml package instead.

YAML Config Loader for Laravel

Build Status

This provides simple YAML config loading to Laravel. It takes a lot of inspiration from the illuminate/config package and uses the Symfony YAML parser.

This is not a replacement for the built-in PHP config file system in Laravel but is intended as an extra 'layer' of configuration. This allows you to have one or more Ruby-like config.yaml files containing user-configurable config for your application.

By default the package assumes your YAML files are in the base_path() directory, but you can customise this by publishing the package config file (config-yaml.php) to your application and changing the yaml_path key.

Installation

Installation is via Composer:

$ composer require jameswmcnab/config-yaml

Publish package config (optional)

If you want to customise the package config, publish the package config then edit the newly created config/config-yaml.php file:

$ php artisan vendor:publish --provider=ConfigYamlServiceProvider

Usage

Example YAML file:

# Example YAML config.yaml file
app:
  name: "Great App"
  version: 1.0.2

log:
  dir: /var/log/vendor/app
  level: debug

database:
  adapter: mysql
  database: app_live
  username: user
  password: password

Using the facade

Note: Remember to register the facade in your app.php config.

ConfigYaml::get('config.database.adapter'); // mysql

Using dependency injection

If you don't want to use the facade just directly inject Jameswmcnab\ConfigYaml\RepositoryInterface wherever dependency injection is supported and use it directly:

<?php

namespace App\Foo;

use Jameswmcnab\ConfigYaml\RepositoryInterface;

class FooBar
{
    /**
     * @var RepositoryInterface
     */
    private $yamlConfig;

    /**
     * FooBar constructor.
     *
     * @param RepositoryInterface $yamlConfig
     */
    public function __construct(RepositoryInterface $yamlConfig)
    {
        $this->yamlConfig = $yamlConfig;
    }

    /**
     * @return array|string
     */
    private function getDatabaseAdapter()
    {
        return $this->yamlConfig->get('config.database.adapter');  // mysql
    }
}

Running Tests

To run the package tests:

$ vendor/bin/phpspec run
$ vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

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