duelistrag3 / laravel-config-writer
Laravel 提供器,可用于重写配置
v2.0.8
2022-04-01 18:02 UTC
Requires
- php: >=7.1.0
- illuminate/config: 5.*|6.*|7.*|8.*|9.*
Requires (Dev)
- phpunit/phpunit: ^7.0
README
向 Laravel 配置文件写入内容并保持文件完整性。
该库是 Laravel 使用的 Config 组件的扩展。它增加了写入配置文件的能力。
在保持文件完整性、保留注释和高级设置的同时,您可以重写基本配置文件中的数组值,该文件返回单个数组定义(如 Laravel 配置文件)。
支持以下值类型进行写入:字符串、整数、布尔值和单维数组。
来自 tekreme73\laravel-config-writer
的分支。
支持
此提供器旨在从 5.4
版本的 Laravel 中使用。
设置
通过 composer 安装
composer require "duelistrag3/laravel-config-writer"
将以下内容添加到 app/config/app.php
中的 'providers' 键下
DuelistRag3\ConfigWriter\ServiceProvider::class,
Lumen 的情况
将以下内容添加到 bootstrap/app.php
中的 'service providers' 部分声明
$app->register(DuelistRag3\ConfigWriter\ServiceProvider::class);
使用方法
您可以像这样向配置文件写入内容
Config::write('app.url', 'http://domain.com'); app('config')->write('app.url', 'http://domain.com');
在 Laravel 之外
Rewrite
类可以在任何地方使用。
$writeConfig = new DuelistRag3\ConfigWriter\DataWriter\Rewrite; $writeConfig->toFile('path/to/config.php', [ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]);