orchestra/config

Laravel 和 Orchestra 平台配置组件


README

Config 组件为 Laravel 5 及以上版本提供基于环境的配置支持。该组件实际上基于 Laravel 4 的配置。

Latest Stable Version Total Downloads Latest Unstable Version License

目录

版本兼容性

安装

要通过 composer 安装,请在终端中运行以下命令

composer require "orchestra/config"

配置

要替换 Laravel 5 默认配置,您只需将以下代码添加到 bootstrap/app.php

$app->singleton(
    Illuminate\Foundation\Bootstrap\LoadConfiguration::class,
    Orchestra\Config\Bootstrap\LoadConfiguration::class
);

配置缓存支持

Config 组件还带来了增强的 php artisan config:cache 支持,以提高配置加载速度,包括以下功能:

  • 缓存包/namespaced 配置,而不仅仅是应用 config 目录。
  • 通过在 compile.config 中包含包配置键列表来强制懒加载包配置。

为了实现这一点,您需要将 Illuminate\Foundation\Provider\ArtisanServiceProvider 替换为新的 App\Providers\ArtisanServiceProvider

<?php namespace App\Providers;

use Orchestra\Config\Console\ConfigCacheCommand;
use Illuminate\Foundation\Providers\ArtisanServiceProvider as ServiceProvider;

class ArtisanServiceProvider extends ServiceProvider
{
    /**
     * Register the command.
     *
     * @return void
     */
    protected function registerConfigCacheCommand()
    {
        $this->app->singleton('command.config.cache', function ($app) {
            return new ConfigCacheCommand($app['files']);
        });
    }
}

别忘了更新您的 config/app.php,将 Illuminate\Foundation\Provider\ArtisanServiceProvider 替换为 App\Providers\ArtisanServiceProvider

缓存懒加载包文件

为了强制某些包包含在配置缓存中,您可以在 config/compile.php 文件中指定所需包的相对键。

<?php

return [

    // ...

    'config' => [
        'orchestra/foundation::config',  // if package config is group under "config/config.php"
        'orchestra/foundation::roles',   // Using one of the key available in "config/config.php"
        'orchestra/html::form',          // When package contain "config/form.php"
    ],

];