andersundsehr/unleash
最新稳定版本:1.0.1
Composer 安装命令:
composer require andersundsehr/unleash
包简介
TYPO3 extension to integrate the getunleash.io feature toggle service.
README 文档
README
TYPO3 extension to integrate the Unleash feature toggle service.
installation
composer require andersundsehr/unleash
Set configuration in the extension settings:
Configuration
Required are the appUrl and in most cases authorization (if you use the hosted unleash service)
Usage
TypoScript Condition
you can use the custom TypoScript condition unleash to check if a feature is enabled.
page.19 = TEXT page.19.value = Feature 0 is disabled<br> [unleash('feature0', false)] page.19.value = Feature 0 is enabled<br> [end] page.20 = TEXT page.20.value = Feature 1 is disabled<br> [unleash('feature1')] page.20.value = Feature 1 is enabled<br> [end] page.21 = TEXT page.21.value = Feature 2 is disabled<br> [unleash('feature2', true)] page.21.value = Feature 2 is enabled<br> [end]
if you want to check A/B/n flags, you can use the unleashVariant condition.
page.22 = TEXT [unleashVariant('feature3') === 'A'] page.22.value = Feature 3 is set to A enabled<br> [end] [unleashVariant('feature3') === 'B'] page.22.value = Feature 3 is set to B enabled<br> [end] [!unleashVariant('feature3')] page.22.value = Feature 3 is disabled<br> [end]
Fluid ViewHelper
if you want to check if a feature is enabled in your Fluid templates, you can use the unleash:isEnabled ViewHelper.
{namespace unleash=Andersundsehr\Unleash\ViewHelpers}
<unleash:isEnabled feature="my-feature" default="false">
<f:then>
<p>Feature is enabled</p>
</f:then>
<f:else>
<p>Feature is disabled</p>
</f:else>
</unleash:isEnabled>
{unleash:isEnabled(feature: 'my-feature', default: false, then: 'Feature is enabled', else: 'Feature is disabled')}
if you want to check A/B/n flags, you can use the unleash:getVariant ViewHelper.
{namespace unleash=Andersundsehr\Unleash\ViewHelpers}
<f:switch expression="{unleash:getVariant(feature: 'my-feature')}">
<f:case value="A"><f:render section="A"/></f:case>
<f:case value="B"><f:render section="B"/></f:case>
<f:defaultCase>If is disabled</f:defaultCase>
</f:switch>
PHP
you can inject the Unleash service into your classes and use it like this:
The configuration and Context will already be set up for you.
for more detailed usage information, please refer to the Unleash PHP SDK Documentation
use Unleash\Client\Unleash; class Controller { public function __construct(private Unleash $unleash) {} public function index() { if ($this->unleash->isEnabled('my-feature')) { // do something } } }
or you can use GeneralUtility to get the Unleash instance
use TYPO3\CMS\Core\Utility\GeneralUtility; use Unleash\Client\Unleash; GeneralUtility::makeInstance(Unleash::class)->isEnabled('my-feature');
CustomContext
with this extension you have the possiblity to constrain the feature toggles to specific users, or admins, or logged in users.
backend and frontend:
backendUser.isLoggedInbackendUser.idbackendUser.usernamebackendUser.isAdminfrontendUser.isLoggedInfrontendUser.idfrontendUser.usernamefrontendUser.isAdmin
Extending with Events
you can extend the functionality of the Extension by using the following events.
UnleashBuilderBeforeBuildEvent
Event that is dispatched right before the UnleashBuilder is built (->build()).
use Andersundsehr\Unleash\Event\UnleashBuilderBeforeBuildEvent; class UnleashBuilderBeforeBuildEventListener { public function __invoke(UnleashBuilderBeforeBuildEvent $event) { $event->builder = $event->builder ->withAppName('my-custom-app-name'); } }
UnleashCustomContextEvent
This event is dispatched when the Unleash context is created.
use this if you only want to overwrite or add customContext data
if you want to change anything else, use the UnleashContextCreatedEvent
use Andersundsehr\Unleash\Event\UnleashCustomContextEvent; class UnleashCustomContextEventListener { public function __invoke(UnleashCustomContextEvent $event) { $event->customContext['fair'] = 'value'; } }
UnleashContextCreatedEvent
Event that is dispatched right after the UnleashContext is created with all the default values.
Will be called multiple times, once per ->isEnabled or ->getVariant call.
use Andersundsehr\Unleash\Event\UnleashContextCreatedEvent; class UnleashContextCreatedEventListener { public function __invoke(UnleashContextCreatedEvent $event) { $event->context->setHostname('my-custom-hostname'); } }
with ♥️ from anders und sehr GmbH
If something did not work 😮
or you appreciate this Extension 🥰 let us know.
We are hiring https://www.andersundsehr.com/karriere/
andersundsehr/unleash 适用场景与选型建议
andersundsehr/unleash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 andersundsehr/unleash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andersundsehr/unleash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2024-08-03
