tsslabs/toggle-bundle

安装: 448

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 27

类型:symfony-bundle

0.1.0 2014-09-02 15:43 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:44:20 UTC


README

此Bundle提供了与我们的切换库的集成。它提供了实现应用中功能切换所需的服务和配置。

Build Status

关于

在以下链接阅读关于此仓库的博客系列文章:

安装

将bundle添加到composer.json文件中

$ composer require qandidate/toggle-bundle ~0.1

将bundle添加到Kernel中

$bundles = array(
    // ..
    new Qandidate\Bundle\ToggleBundle\QandidateToggleBundle(),
);

配置

qandidate_toggle:
    persistence: in_memory|redis
    context_factory: null|your.context_factory.service.id
    redis_namespace: toggle_%kernel.environment% # default, only required when persistence = redis
    redis_client: null|your.redis_client.service.id # only required when persistence = redis

示例用法

用法可能因应用而异。此示例使用提供的UserContextFactory,但您可能需要创建自己的工厂。

<!-- services.xml -->

<service id="acme.controller" class="Acme\Controller">
    <argument type="service" id="qandidate.toggle.manager" />
    <argument type="service" id="qandidate.toggle.user_context_factory" />
</service>
// Acme\Controller

public function __construct(
    /* ArticleRepository, Templating, ..*/ 
    ToggleManager $manager, 
    ContextFactory $contextFactory
) {
    // ..
    $this->manager = $manager;
    $this->context = $contextFactory->createContext();
}

// ..

public function articleAction(Request $request)
{
    $this->article = $this->repository->findBySlug($request->request->get('slug'));

    return $this->templating->render('article.html.twig', array(
        'article'        => $article,
        'enableComments' => $this->manager->active('comments', $this->context),
    ));
}

Twig使用

如果您使用Twig,也可以使用Twig函数

{% if is_active('comments') %}
    {# Awesome comments #}
{% endif %}

许可证

MIT,请参阅LICENSE。