疯狂252 / typo3_features
TYPO3的功能标志
0.1.0
2024-07-29 18:35 UTC
Requires
- typo3/cms-core: ^7 || ^8 || ^9 || ^10 || ^11 || ^12
README
介绍专为TYPO3设计的新开源软件包,旨在通过使用功能标志来简化功能管理。此软件包为开发人员和网站管理员提供灵活直观的后端界面,用于创建和管理功能标志,使功能部署具有细粒度控制。无论您是逐步推出新功能、运行A/B测试还是定制用户体验,我们的软件包都支持标准标志和自定义标志,为TYPO3内直接的功能切换提供强大解决方案。解锁流畅的功能控制,确保您的网站功能平稳高效地部署。
设置
通过composer安装
composer require crazy252/typo3_features
用法
您可以使用TYPO3的原始功能核心类。此类由本软件包扩展,添加了许多新功能。
use TYPO3\CMS\Core\Configuration\Features; $features = GeneralUtility::makeInstance(Features::class); $isFeatureEnabled = $features->isFeatureEnabled('dummy-feature');
多个功能
如果您想的话,也可以检查多个功能。
$isFeatureEnabled = $features->isFeatureEnabled('dummy-feature,other-feature');
自定义功能类
您还可以通过在后台功能中添加类命名空间来为功能检查创建自己的逻辑。在后台创建功能后,您可以使用软件包中的接口创建功能类。
namespace Vendor\Extension\Features; class DummyFeature implements \Crazy252\Typo3Features\Contracts { public function verdict(): bool { // Custom feature check } }
功能视图助手
此软件包还提供了一个视图助手来在模板中检查功能。TYPO3 13.1有一个视图助手用于此目的。在此之前,我们将视图助手回滚到旧版本。
<f:feature name="dummy-feature"> This is being shown if the flag is enabled </f:feature> <f:feature name="dummy-feature,other-feature"> This is being shown if both flags are enabled </f:feature>
用法(TYPO3 9.0或以下)
您需要使用功能类,这些类可以在更高版本中轻松替换为功能核心类。
use Crazy252\Typo3Features\Legacy\Features; $features = GeneralUtility::makeInstance(Features::class); $isFeatureEnabled = $features->isFeatureEnabled('dummy-feature');