FeatureToggleViewHelperFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 3
crap 2
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 Interop\Container\ContainerInterface;
22
use Interop\Container\Exception\ContainerException;
23
use MehrAlsNix\FeatureToggle\View\Helper\FeatureToggle;
24
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
25
use Zend\ServiceManager\Exception\ServiceNotFoundException;
26
use Zend\ServiceManager\FactoryInterface;
27
use Zend\ServiceManager\ServiceLocatorInterface;
28
29
class FeatureToggleViewHelperFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
30
{
31
    /**
32
     * Create an object
33
     *
34
     * @param  ContainerInterface $container
35
     * @param  string $requestedName
36
     * @param  null|array $options
37
     * @return object
38
     * @throws ServiceNotFoundException if unable to resolve the service.
39
     * @throws ServiceNotCreatedException if an exception is raised when
40
     *     creating a service.
41
     * @throws ContainerException if any other error occurs
42
     */
43
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
44
    {
45
        $toggleManager = $container->get('ToggleManagerFactory');
46
        $toggleContext = $container->get('ToggleContextFactory');
47
48
        $helper = new FeatureToggle();
49
        $helper->setToggleManager($toggleManager);
50
        $helper->setContext($toggleContext);
51
52
        return $helper;
53
    }
54
55
    /**
56
     * Create service
57
     *
58
     * @param ServiceLocatorInterface $serviceLocator
59
     *
60
     * @return FeatureToggle
61
     *
62
     * @throws ServiceNotFoundException
63
     */
64
    public function createService(ServiceLocatorInterface $serviceLocator)
65
    {
66
        return $this($serviceLocator->getServiceLocator());
67
    }
68
}
69