mprince / laravel-config-writer
Laravel提供器,允许重写配置
1.1
2022-04-30 15:39 UTC
Requires
- php: ^7.4|^8.0
- illuminate/config: 8.*
Requires (Dev)
- phpunit/phpunit: ^9.0
README
写入Laravel配置文件并维护文件完整性。
这个库是Laravel使用的Config组件的扩展。它增加了写入配置文件的能力。
您可以在返回单个数组定义的基本配置文件(如Laravel配置文件)内部重写数组值,同时保持文件完整性,保留注释和高级设置。
支持以下值类型进行写入:字符串、整数、布尔值和单维数组。
支持
此提供器旨在从5.4
版本开始使用Laravel。
设置
通过composer安装
composer require mprince/laravel-config-writer
在app/config/app.php
中的'providers'键下添加此内容
October\Rain\Config\ServiceProvider::class,
Lumen情况
在'服务提供者'声明部分的bootstrap/app.php
中添加此内容
$app->register(October\Rain\Config\ServiceProvider::class);
用法
您可以这样写入配置文件
Config::write('app.url', 'http://domain.com'); app('config')->write('app.url', 'http://domain.com');
在Laravel外部
Rewrite
类可以在任何地方使用。
$writeConfig = new October\Rain\Config\DataWriter\Rewrite; $writeConfig->toFile('path/to/config.php', [ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]);