makinacorpus/preferences-bundle
Composer 安装命令:
composer require makinacorpus/preferences-bundle
包简介
Preferences are configuration variables that are user-managed for which we cannot rely upon container parameters or environment variables.
README 文档
README
Preferences are configuration variables that are meant to be user managed for which we cannot rely upon container parameters or environment variables.
This bundle provides a simple API for:
-
Defining a preferences variable schema, with variable name, type, and description.
-
Reading them as environment variables by the container, in order to allow using those variables as services parameters.
-
A form type which handles all basic types (int, type, string) as collections or single-values variables, which you can use in any form.
-
An implementation for storing user values in database using
makinacorpus/goat-query. -
Bus handlers and messages for
symfony/messenger,makinacorpus/goatandmakinacorpus/corebus. -
An interface for reading the schema defined in project configuration.
-
An interface for reading values.
Setup
This package is depends on makinacorpus/goat-query.
Simply install this package:
composer require makinacorpus/preferences-bundle
Then add the bundle into your config/bundles.php file:
<?php return [ // ... Your other bundles. MakinaCorpus\Preferences\PreferencesBundle::class => ['all' => true], ];
Define a custom schema
You can define a schema:
preferences: schema: app.domain.some_variable: label: Some variable description: Uncheck this value to deactive this feature type: bool collection: false default: true
Where the number of entries is unlimited. Only limit is your memory because the whole definition will be injected as a bare PHP array into the default array schema implementation.
Please note that because Symfony environment variables processor validates
strictly the variables names, all non alpha-numeric and non _ characters
will make the environment variable processor fail. If you plan to inject
your variables into services using environment variables, you must name
your variables accordingly, such as:
preferences: schema: app_domain_some_variable: label: Some variable description: Uncheck this value to deactive this feature type: bool collection: false default: true
All options are optional. Defaults are:
preferences: enabled: true schema: app_domain_some_variable: label: null description: null type: string allowed_values: null collection: false hashmap: false default: null
Parameters you can set on each variable definition:
label: is a human readable short name,description: is a human readable long description,type: can be either of:string,bool,int,float,allowed_values: is an array of arbitrary values, for later validation,collection: if set totrue, multiple values are allowed for this variable,hashmap: if set to true, keys are allowed, this is ignored ifcollectionisfalse,default: arbitrary default value if not configured by the user.
Usage
Inject preferences as service arguments
This package defines a EnvVarProcessorInterface implementation allowing to
inject preferences like environment variables, such as:
services: my_service: class: App\Some\Class arguments: ["%env(preference:app_domain_some_variable)%"]
Use Preferences service into other services.
Type hint your injected parameters using MakinaCorpus\Preferences\Preferences
then use the get(string $name): mixed method to fetch values.
Long term roadmap
- Add new repository implementations (Redis, PDO, other...).
- Implement correctly bus handlers.
- Implement PHP schema dumper.
makinacorpus/preferences-bundle 适用场景与选型建议
makinacorpus/preferences-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.56k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「configuration」 「preferences」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 makinacorpus/preferences-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 makinacorpus/preferences-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 makinacorpus/preferences-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
The bundle for easy using json-rpc api on your project
A Laravel Nova Tool to let users manage global settings created from code.
Lightweight settings management for CodeIgniter 4
Per-model preferences for Laravel with defaults and validation.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 4.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2022-02-07