famelo/features

此包的最新版本(dev-master)没有可用的许可证信息。

安装: 81

依赖关系: 0

建议者: 0

安全性: 0

星标: 3

关注者: 3

分支: 2

开放性问题: 2

类型:typo3-flow-package

dev-master 2014-05-01 22:25 UTC

This package is auto-updated.

Last update: 2024-09-05 18:33:39 UTC


README

此包提供了一种服务和视图助手,可以帮助您轻松推出新功能。

创建新功能

功能在名为 "Features.yaml" 的独立配置文件中指定

以下是一个示例

-
  name: OnyForAdminstators
  condition: hasRole('My.Package:Administrator')

-
  name: OnlyForMneuhaus
  condition: isUser('mneuhaus')

-
  name: OnlyAfterThisDate
  condition: afterDate('22.11.2013')

-
  name: onlyGuests
  condition: isGuest()

-
  name: onlyLoggedIn
  condition: isNotGuest()

-
  name: only25PercentOfTheUsers
  condition: userPercentage(25)

-
  name: onlyWithMatchingClientIp
  condition: clientIp('127.0.0.1')

-
  name: combination
  condition: hasRole('My.Package:Administrator') && userPercentage(25)

-
  name: combination2
  condition: hasRole('My.Package:Administrator') || afterDate('22.11.2013')

使用 FeatureService

您可以轻松地像这样注入 featureService

	/**
	 * The featureService
	 *
	 * @var \Famelo\Features\FeatureService
	 * @Flow\Inject
	 */
	protected $featureService;

然后,您可以询问它您想要操作的功能是否对当前用户已启用

if ($this->featureService->isFeatureActive("myFeature")) {
	do some cool stuff
}

使用 ActiveViewHelper

为了方便起见,为 fluid 提供了 featureService 的包装器

{namespace feature=Famelo\Features\ViewHelpers}
<feature:active feature="myFeature">
	show my cool feature
</feature:active>

或者,您也可以像 ifViewHelper 一样使用它,带有 then/else

<feature:active feature="myFeature">
	<f:then>
		show my cool feature
	</f:then>
	<f:else>
		show some other stuff
	</f:else>
</feature:active>

设置

Famelo:
  Features:
    # You can change this setting to use your own ConditionMatcher with more specific functions
    # you might need
    conditionMatcher: \Famelo\Features\Core\ConditionMatcher

    # What should happen if the service is asked about a feature it doesn't now?
    # can be: active, inactive, exception
    # exception is the default and will throw an exception because you probably
    # mistyped some feature name
    noMatchBehavior: exception

其他 ConditionMatchers

您可以添加任意数量的自定义 conditionMatches。您只需实现一个基于 "\Famelo\Features\Core\ConditionMatcherInterface" 的 ConditionMatcher。您可以为这些方法添加任意数量的方法和注入属性。该类中的任何方法都将作为名为 NAME 常量指定的变量下的 eel 方法可用。您还可以为这些方法添加任意数量的参数。

示例

<?php
namespace My\Package\Features;
use TYPO3\Flow\Annotations as Flow;

class MyConditionMatcher implements \Famelo\Features\Core\ConditionMatcherInterface{
    /**
     * contains short name for this matcher used
     * for reference in the eel expression
     */
    const NAME = 'my';

    /**
     * @param string $foo
     * @return boolean
     */
    public function someCondition($foo) {
        return $foo == 'bar';
    }

}

此匹配器将自动可用,如下所示

-
  name: MyCustomMatcher
  condition: my.someCondition('bar')
  # will be true

-
  name: MyCustomMatcher2
  condition: my.someCondition('guz')
  # will be false