originphp / configurable
OriginPHP 可配置
2.0.0
2021-01-03 20:38 UTC
Requires
- php: >=7.3.0
Requires (Dev)
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2024-09-04 20:06:08 UTC
README
提供可配置特性以添加默认配置、设置器和获取器。
安装
要安装此软件包
$ composer require originphp/configurable
使用方法
实例和静态特性都可用。
设置 defaultConfig 属性
use Origin\Configurable\InstanceConfigurable as Configurable; class MyObject { use Configurable; protected $defaultConfig = [ 'foo' => 'bar' ]; }
从配置中获取值
$value = $this->config('foo'); // bar
获取所有配置值
$array = $this->config();
在配置中设置值
$this->config('foo','bar'); $this->config(['foo'=>'bar']);
设置多个值(合并配置)
$this->config(['foo'=>'bar']);