|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Shlinkio\Shlink\Installer\Factory; |
|
5
|
|
|
|
|
6
|
|
|
use Interop\Container\ContainerInterface; |
|
7
|
|
|
use Interop\Container\Exception\ContainerException; |
|
8
|
|
|
use Shlinkio\Shlink\Installer\Command\InstallCommand; |
|
9
|
|
|
use Shlinkio\Shlink\Installer\Config\ConfigCustomizerManager; |
|
10
|
|
|
use Shlinkio\Shlink\Installer\Config\Plugin; |
|
11
|
|
|
use Symfony\Component\Console\Application; |
|
12
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
|
13
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
14
|
|
|
use Zend\Config\Writer\PhpArray; |
|
15
|
|
|
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; |
|
16
|
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException; |
|
17
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
|
18
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
|
19
|
|
|
use Zend\ServiceManager\Factory\InvokableFactory; |
|
20
|
|
|
|
|
21
|
|
|
class InstallApplicationFactory implements FactoryInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Create an object |
|
25
|
|
|
* |
|
26
|
|
|
* @param ContainerInterface $container |
|
27
|
|
|
* @param string $requestedName |
|
28
|
|
|
* @param null|array $options |
|
29
|
|
|
* @return object |
|
30
|
|
|
* @throws LogicException |
|
31
|
|
|
* @throws ServiceNotFoundException if unable to resolve the service. |
|
32
|
|
|
* @throws ServiceNotCreatedException if an exception is raised when |
|
33
|
|
|
* creating a service. |
|
34
|
|
|
* @throws ContainerException if any other error occurs |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
37
|
|
|
{ |
|
38
|
|
|
$isUpdate = $options !== null && isset($options['isUpdate']) ? (bool) $options['isUpdate'] : false; |
|
39
|
|
|
|
|
40
|
|
|
$app = new Application(); |
|
41
|
|
|
$command = new InstallCommand( |
|
42
|
|
|
new PhpArray(), |
|
43
|
|
|
$container->get(Filesystem::class), |
|
44
|
|
|
new ConfigCustomizerManager($container, ['factories' => [ |
|
45
|
|
|
Plugin\DatabaseConfigCustomizer::class => ConfigAbstractFactory::class, |
|
46
|
|
|
Plugin\UrlShortenerConfigCustomizer::class => InvokableFactory::class, |
|
47
|
|
|
Plugin\LanguageConfigCustomizer::class => InvokableFactory::class, |
|
48
|
|
|
Plugin\ApplicationConfigCustomizer::class => InvokableFactory::class, |
|
49
|
|
|
]]), |
|
50
|
|
|
$isUpdate |
|
51
|
|
|
); |
|
52
|
|
|
$app->add($command); |
|
53
|
|
|
$app->setDefaultCommand($command->getName(), true); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
return $app; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|