|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Commander project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Daniel Schröder <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace GravityMedia\Commander\Console; |
|
9
|
|
|
|
|
10
|
|
|
use GravityMedia\Commander\Console\Command; |
|
11
|
|
|
use GravityMedia\Commander\Console\Helper; |
|
12
|
|
|
use Interop\Container\ContainerInterface; |
|
13
|
|
|
use Interop\Container\Exception\ContainerException; |
|
14
|
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException; |
|
15
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
|
16
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Application factory class. |
|
20
|
|
|
* |
|
21
|
|
|
* @package GravityMedia\Commander\Console |
|
22
|
|
|
*/ |
|
23
|
|
|
class ApplicationFactory implements FactoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Create application object. |
|
27
|
|
|
* |
|
28
|
|
|
* @param ContainerInterface $container |
|
29
|
|
|
* @param string $requestedName |
|
30
|
|
|
* @param null|array $options |
|
31
|
|
|
* |
|
32
|
|
|
* @return Application |
|
33
|
|
|
* |
|
34
|
|
|
* @throws ServiceNotFoundException if unable to resolve the service. |
|
35
|
|
|
* @throws ServiceNotCreatedException if an exception is raised when creating a service. |
|
36
|
|
|
* @throws ContainerException if any other error occurs. |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
39
|
|
|
{ |
|
40
|
2 |
|
$application = new Application(); |
|
41
|
2 |
|
$application->add($container->get(Command\NewCommand::class)); |
|
42
|
2 |
|
$application->add($container->get(Command\PruneCommand::class)); |
|
43
|
2 |
|
$application->add($container->get(Command\RunCommand::class)); |
|
44
|
2 |
|
$application->add($container->get(Command\ShowCommand::class)); |
|
45
|
|
|
|
|
46
|
2 |
|
$helperSet = $application->getHelperSet(); |
|
47
|
2 |
|
$helperSet->set($container->get(Helper\ConfigLoaderHelper::class)); |
|
48
|
|
|
|
|
49
|
2 |
|
return $application; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|