orchestra / config
Laravel 和 Orchestra 平台配置组件
v6.0.0
2021-04-18 13:16 UTC
Requires
- php: ^7.3 || ^8.0
- illuminate/filesystem: ^8.0
- orchestra/contracts: ^6.0
- dev-master / 7.0.x-dev
- 6.x-dev
- v6.0.0
- 5.x-dev
- v5.1.0
- v5.0.0
- 4.x-dev
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.1
- v4.0.0
- 3.8.x-dev
- v3.8.4
- v3.8.3
- v3.8.2
- v3.8.1
- v3.8.0
- 3.7.x-dev
- v3.7.1
- v3.7.0
- 3.6.x-dev
- v3.6.2
- v3.6.1
- v3.6.0
- v3.6.0-BETA1
- 3.5.x-dev
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- 3.4.x-dev
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.4.0-BETA2
- v3.4.0-BETA1
- 3.3.x-dev
- v3.3.6
- v3.3.5
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.16
- v3.1.15
- v3.1.14
- v3.1.13
- v3.1.12
- v3.1.11
- v3.1.10
- v3.1.9
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
This package is auto-updated.
Last update: 2024-09-18 21:20:02 UTC
README
Config 组件为 Laravel 5 及以上版本提供基于环境的配置支持。该组件实际上基于 Laravel 4 的配置。
目录
版本兼容性
安装
要通过 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" ], ];