skyline / settings
此软件包已被废弃,不再维护。作者建议使用skyline/default-setting软件包代替。
v0.8.0
2020-08-22 12:01 UTC
Requires
- php: >=7.2
- skyline/kernel: ^0.8
- skyline/pdo: ^0.9
Requires (Dev)
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2022-04-11 05:38:04 UTC
README
此软件包通过提供持久化设置存储工具扩展了Skyline应用程序。
安装
$ composer require skyline/settings
使用方法
使用Skyline编译,此软件包添加了一个settingManager
服务。
<?php use TASoft\Service\ServiceManager; use Skyline\Setting\SettingManagerInterface; $sm = ServiceManager::generalServiceManager()->get( SettingManagerInterface::SERVICE_NAME ); // or $sm = ServiceManager::generalServiceManager()->get( "settingManager" ); // In an action controller method, just use: $sm = $this->settingManager;
设置
设置被设计为键值对形式,其中键是设置名称,值是其值。
<?php use Skyline\Setting\SettingManagerInterface; /** @var SettingManagerInterface $sm */ $width = $sm->getSetting("width");
设置机制知道三个位置,其中设置可以被定义:
- 默认设置范围。
一旦声明,设置在整个应用程序中都是有效的(如上面的示例所示) - 分组设置范围。
设置是某个组的一部分(例如 VIEW.width 或 EDITOR.width) - 用户设置范围。
任何分组或默认设置都可以与用户关联,因此用户A的 VIEW.width 与用户B的 VIEW.width 不同。
如果没有选择范围或设置不存在于该范围中,设置管理器将尝试在父范围中寻找。
示例:我在用户A的 DASHBOARD
组中寻找设置 itemsPerPage
设置管理器将返回第一个存在的设置
- 为USER_A设置 DASHBOARD.itemsPerPage
- 设置 DASHBOARD.itemsPerPage
- 为USER_A设置 itemsPerPage
- 设置 itemsPerPage
- NULL
示例:我在用户A中寻找设置 itemsPerPage
(无分组)
- 为USER_A设置 itemsPerPage
- 设置 itemsPerPage
- NULL
请注意,设置组和用户组是不同的。
管理器还允许声明设置
<?php use Skyline\Setting\SettingManagerInterface; /** @var SettingManagerInterface $sm */ // Declare width only in default scope $sm->declareSetting('width', 250); // Declare width only in group VIEW $sm->declareSetting("width", 250, 'VIEW'); // Declare width only for USER_A $sm->declareSetting("width", 250, NULL, 'USER_A'); // Declare width only in group VIEW for USER_A $sm->declareSetting("width", 250, 'VIEW', 'USER_A');
同样,您也可以删除设置
<?php use Skyline\Setting\SettingManagerInterface; /** @var SettingManagerInterface $sm */ // Removes width only from default scope $sm->removeSetting('width'); // Removes width only from group VIEW $sm->removeSetting("width", 'VIEW'); // Removes width only for USER_A $sm->removeSetting("width", NULL, 'USER_A'); // Removes width only from group VIEW for USER_A $sm->removeSetting("width", 'VIEW', 'USER_A'); // Removes all settings with name width $sm->removeSettingAll("width");