gokure/hyperf-settings
Composer 安装命令:
composer require gokure/hyperf-settings
包简介
Persistent settings package for Hyperf
README 文档
README
This package allows you to save settings in a more persistent way. You can use the database and/or json file to save your settings.
Installation
- Require the
gokure/hypref-settingspackage in yourcomposer.jsonand update your dependencies:
composer require gokure/hypref-settings
- Publish the config and migration files:
php bin/hyperf.php vendor:publish gokure/hypref-settings
Usage
$store = $container->get(\Gokure\Settings\SettingManager::class)->getDriver(); $store->set('foo', 'bar'); $store->get('foo', 'default value'); $store->get('nested.element'); $store->forget('foo'); $stores = $store->all();
Call $store->save() explicitly to save changes made.
You can also to use the setting() helper:
// Get the `default` store instance setting(); // Get values setting('foo'); setting('foo.bar'); setting('foo', 'default value'); setting()->get('foo'); // Set values setting(['foo' => 'bar']); setting(['foo.bar' => 'baz']); setting()->set('foo', 'bar'); // Method chaining setting(['foo' => 'bar'])->save();
Configuration
You can change config/autoload/settings.php
return [ 'default' => [ /** * Default Store Driver * * This option controls the default setting connection that gets used while * using this setting library. * * Supported: `FileSystemStore::class` and `DatabaseStore::class` */ 'driver' => Gokure\Settings\FileSystemStore::class, /** * FileSystem Store * * This option used when the driver is set `FileSystemStore::class`, and * make sure the path is writable. */ 'path' => BASE_PATH . '/runtime/settings.json', /** * Database Store * * This option used when the driver is set DatabaseStore::class. */ 'database' => [ // If set to null, the default connection will be used. 'connection' => null, // Table name. 'table' => 'settings', // Column names in database store. 'key_column' => 'key', 'value_column' => 'value', ], ], ];
Auto Saving
if you add the middleware Gokure\Settings\SaveMiddleware to your middlewares list in config/autoload/middlewares.php, settings will be saved automatically at the end of all HTTP requests, but you'll still need to call $store->save() explicitly in commands, queue workers etc.
FileSystem Store
You can modify the path used on run-time using $store->setPath($path).
Database Store
If you want to use the database as settings storage then you should run the php bin/hyperf.php migrate. You can modify the table fields from the create_settings_table file in the migrations directory.
Extra Columns
If you want to store settings for multiple users/clients in the same database you can do so by specifying extra columns:
$store->setExtraColumns(['user_id' => 1]);
where user_id = 1 will now be added to the database query when settings are retrieved, and when new settings are saved, the user_id will be populated.
If you need more fine-tuned control over which data gets queried, you can use the setConstraint method which takes a closure with two arguments:
$queryis the query builder instance$insertis a boolean telling you whether the query is an insert or not. If it is an insert, you usually don't need to do anything to$query.
$store->setConstraint(function($query, $insert) { if (!$insert) { $query->where(/* ... */); } });
License
Released under the MIT License, see LICENSE.
gokure/hyperf-settings 适用场景与选型建议
gokure/hyperf-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 330 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 「Settings」 「persistent」 「hyperf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gokure/hyperf-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gokure/hyperf-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gokure/hyperf-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
A Zend Framework module to quickly and easily set PHP settings.
Persistent settings package for Laravel framework.
Settings Card for Laravel Nova.
Persistent settings for ARCANESOFT CMS.
Persistent settings package for Laravel
统计信息
- 总下载量: 330
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-05