Completed
Push — master ( c11d86...d758ed )
by Gianluca
13:50
created

CliFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 3
crap 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineModule\Service;
21
22
use DoctrineModule\Version;
23
use Interop\Container\ContainerInterface;
24
use Symfony\Component\Console\Application;
25
use Symfony\Component\Console\Helper\HelperSet;
26
use Zend\ServiceManager\FactoryInterface;
27
use Zend\ServiceManager\ServiceLocatorInterface;
28
29
/**
30
 * CLI Application ServiceManager factory responsible for instantiating a Symfony CLI application
31
 *
32
 * @license MIT
33
 * @link    http://www.doctrine-project.org/
34
 * @author  Kyle Spraggs <[email protected]>
35
 */
36
class CliFactory 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...
37
{
38
    /**
39
     * @var \Zend\EventManager\EventManagerInterface
40
     */
41
    protected $events;
42
43
    /**
44
     * @var \Symfony\Component\Console\Helper\HelperSet
45
     */
46
    protected $helperSet;
47
48
    /**
49
     * @var array
50
     */
51
    protected $commands = array();
52
53
    /**
54
     * @param  ContainerInterface $container
55
     * @return \Zend\EventManager\EventManagerInterface
56
     */
57
    public function getEventManager(ContainerInterface $container)
58
    {
59
        if (null === $this->events) {
60
            /* @var $events \Zend\EventManager\EventManagerInterface */
61
            $events = $container->get('EventManager');
62
63
            $events->addIdentifiers(array(__CLASS__, 'doctrine'));
64
65
            $this->events = $events;
66
        }
67
68
        return $this->events;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     * @return Application
74
     */
75
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
76
    {
77
        $cli = new Application;
78
        $cli->setName('DoctrineModule Command Line Interface');
79
        $cli->setVersion(Version::VERSION);
80
        $cli->setHelperSet(new HelperSet);
81
        $cli->setCatchExceptions(true);
82
        $cli->setAutoExit(false);
83
84
        // Load commands using event
85
        $this->getEventManager($container)->trigger('loadCli.post', $cli, array('ServiceManager' => $container));
86
87
        return $cli;
88
    }
89
90
    /**
91
     * {@inheritDoc}
92
     * @return Application
93
     */
94
    public function createService(ServiceLocatorInterface $container)
95
    {
96
        return $this($container, Application::class);
97
    }
98
}
99