1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* zf2-featureflags. |
4
|
|
|
* |
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
11
|
|
|
* SOFTWARE. |
12
|
|
|
* |
13
|
|
|
* @copyright 2016 MehrAlsNix (http://www.mehralsnix.de) |
14
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
15
|
|
|
* |
16
|
|
|
* @link http://github.com/MehrAlsNix/zf2-featureflags |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace MehrAlsNix\FeatureToggle\Factory; |
20
|
|
|
|
21
|
|
|
use Qandidate\Toggle\Context; |
22
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
23
|
|
|
use Zend\ServiceManager\FactoryInterface; |
24
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
25
|
|
|
|
26
|
|
|
class ToggleContextFactory implements FactoryInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Create service |
30
|
|
|
* |
31
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
32
|
|
|
* |
33
|
|
|
* @return Context |
34
|
|
|
* |
35
|
|
|
* @throws ServiceNotFoundException |
36
|
|
|
*/ |
37
|
1 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
38
|
|
|
{ |
39
|
1 |
|
$toggleConfig = (array) $serviceLocator->get('config'); |
40
|
|
|
|
41
|
1 |
|
$hasDefaultGlobalContextFactory = isset($toggleConfig['zf2_featureflags']['qandidate_toggle']['context_factory']); |
|
|
|
|
42
|
|
|
|
43
|
1 |
|
$factory = null; |
44
|
|
|
|
45
|
1 |
|
if ($hasDefaultGlobalContextFactory) { |
46
|
1 |
|
$factory = $toggleConfig['zf2_featureflags']['qandidate_toggle']['context_factory']; |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
$context = new Context(); |
50
|
|
|
|
51
|
1 |
|
if ($factory !== null && $serviceLocator->has($factory)) { |
52
|
|
|
/** @var Context $context */ |
53
|
|
|
$context = $serviceLocator->get($factory); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
return $context; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.