Skip to content

Commit f502a5c

Browse files
laudecotonivdv
authored andcommitted
add support for describing features (#5)
1 parent 39b2912 commit f502a5c

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ return [
3838
// Required configuration if storage service is Adlogix\Zf2Rollout\Storage\Doctrine\DoctrineORMStorage
3939
'doctrine_storage' => [
4040
'class_name' => SomeFeatureEntity::class
41+
],
42+
43+
// (Optional) Describes the features with a description
44+
'features' => [
45+
'feature_1' => [
46+
'description' => 'The description of the feature.'
47+
]
4148
]
4249
],
4350
]
@@ -55,6 +62,31 @@ $rollout = $this->getServiceLocator()->get('zf2_rollout');
5562

5663
Refer to the documentation of [opensoft/rollout](https://github.com/opensoft/rollout) for more information on how to use the library.
5764

65+
## Describe the features
66+
67+
Since the Rollout library doesn't have (yet) a functionality to describe its feature flags, you can define them through this module. To do so, simply add your feature flag identifier in the 'features' sections of the rollout configuration as shown here:
68+
69+
```php
70+
<?php
71+
return [
72+
'rollout' => [
73+
74+
// (Optional) Describes the features with a description
75+
'features' => [
76+
'feature_1' => [
77+
'description' => ''
78+
]
79+
]
80+
],
81+
];
82+
```
83+
84+
To display the description in a view you have to call the view helper : **rollout_description**. If the description is not found in the configuration, an empty string will be returned.
85+
86+
```php
87+
echo $this->rollout_description('feature_1');
88+
```
89+
5890
## Zend Developer Toolbar
5991

6092
The module comes with support for the zend developer toolbar.

config/module.config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
'doctrine_storage' => [
2727
'class_name' => ''
28-
]
28+
],
29+
30+
'features' => []
2931
],
3032

3133
'router' => array(

src/Module.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function getViewHelperConfig()
4040
/** @var Rollout $rollout */
4141
$rollout = $serviceLocator->get('zf2_rollout');
4242
return new View\Helper\IsActive($rollout);
43+
},
44+
'rollout_description' => function (AbstractPluginManager $pluginManager) {
45+
$serviceLocator = $pluginManager->getServiceLocator();
46+
$rolloutConfig = $serviceLocator->get('zf2_rollout_config');
47+
return new View\Helper\Description($rolloutConfig['features']);
4348
}
4449
],
4550
];

src/View/Helper/Description.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* This file is part of the Adlogix package.
4+
*
5+
* (c) Allan Segebarth <[email protected]>
6+
* (c) Jean-Jacques Courtens <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Adlogix\Zf2Rollout\View\Helper;
13+
14+
15+
use Zend\View\Helper\AbstractHelper;
16+
17+
/**
18+
* Returns the description of a given feature.
19+
*
20+
* @package Adlogix\Zf2Rollout\View\Helper
21+
* @author Laurent De Coninck <[email protected]>
22+
*/
23+
class Description extends AbstractHelper
24+
{
25+
/**
26+
* @var array
27+
*/
28+
private $features;
29+
30+
public function __construct(array $features = [])
31+
{
32+
$this->features = $features;
33+
}
34+
35+
/**
36+
* Returns the description of a feature.
37+
*
38+
* @param string $feature
39+
*
40+
* @return string|null
41+
*/
42+
public function __invoke($feature)
43+
{
44+
if (!isset($this->features[$feature]['description'])) {
45+
return '';
46+
}
47+
48+
return $this->features[$feature]['description'];
49+
}
50+
51+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/*
3+
* This file is part of the Adlogix package.
4+
*
5+
* (c) Allan Segebarth <[email protected]>
6+
* (c) Jean-Jacques Courtens <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Adlogix\Zf2Rollout\Test\View\Helper;
13+
14+
use Adlogix\Zf2Rollout\View\Helper\Description;
15+
16+
/**
17+
* @package Adlogix\Zf2Rollout\Test\View\Helper
18+
* @author Laurent De Coninck <[email protected]>
19+
*/
20+
class DescriptionTest extends \PHPUnit_Framework_TestCase
21+
{
22+
23+
/**
24+
* @return Description
25+
*/
26+
private function createHelper()
27+
{
28+
$features = [
29+
'feature_1' => [
30+
'description' => 'description for test'
31+
],
32+
'feature_2' => [
33+
],
34+
];
35+
36+
return new Description($features);
37+
}
38+
39+
/**
40+
* @test
41+
*/
42+
public function invoke_WithDescriptions_CorrectDescriptionReturned()
43+
{
44+
$this->assertEquals('description for test', $this->createHelper()->__invoke('feature_1'));
45+
}
46+
47+
/**
48+
* @test
49+
*/
50+
public function invoke_NoDescriptionKey_NullReturned()
51+
{
52+
$this->assertEquals('', $this->createHelper()->__invoke('feature_2'));
53+
}
54+
55+
/**
56+
* @test
57+
*/
58+
public function invoke_NoDescriptionFound_NullReturned()
59+
{
60+
$this->assertEquals('', $this->createHelper()->__invoke('feature_3'));
61+
}
62+
}

0 commit comments

Comments
 (0)