tsslabs / toggle-bundle
0.1.0
2014-09-02 15:43 UTC
Requires
- qandidate/toggle: ~0.1
- symfony/framework-bundle: ~2.3
Requires (Dev)
- symfony/browser-kit: ~2.3
- symfony/framework-bundle: ~2.3
- symfony/twig-bundle: ~2.3
- twig/twig: ~1.14
This package is not auto-updated.
Last update: 2024-09-14 16:44:20 UTC
README
此Bundle提供了与我们的切换库的集成。它提供了实现应用中功能切换所需的服务和配置。
关于
在以下链接阅读关于此仓库的博客系列文章:
- http://labs.qandidate.com/blog/2014/08/18/a-new-feature-toggling-library-for-php/
- http://labs.qandidate.com/blog/2014/08/19/open-sourcing-our-feature-toggle-api-and-ui/
安装
将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。