wilbur-yu/hyperf-options

数据库中的全局键值存储

3.0.0 2023-01-15 10:03 UTC

This package is auto-updated.

Last update: 2024-09-17 12:42:04 UTC


README

该组件移植自 appstract/laravel-options,感谢 原作者 的开源作品

安装

composer require wilbur-yu/hyperf-options
php ./bin/hyperf.php vendor:publish wilbur-yu/hyperf-options
php ./bin/hyperf.php migarte

说明

<?php
use WilburYu\HyperfOptions\OptionService;
// 使用全局函数
options()->set('key', 'value', 'desc'); // 创建或更新
options()->get('key');
options()->exists('key');
options()->remove('key');

// 使用服务类
$options = make(OptionService::class);
$options->set('key', 'value', 'desc');
$options->get('key');
$options->exists('key');
$options->remove('key');

得益于 hyperf 完善的组件生态,监听 Option 模型的 Deleted 和 Saved 事件,搭配 Cache 注解,可以很容易地完成 option 键值对 的缓存生命周期的维护。