mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 00:47:25 -06:00
Moved command and app creation logic to a factory for install scripts
This commit is contained in:
parent
dcc09975a9
commit
2368b634e3
@ -2,6 +2,7 @@
|
||||
namespace PHPSTORM_META;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
/**
|
||||
* PhpStorm Container Interop code completion
|
||||
@ -16,4 +17,7 @@ $STATIC_METHOD_TYPES = [
|
||||
ContainerInterface::get('') => [
|
||||
'' == '@',
|
||||
],
|
||||
ServiceManager::build('') => [
|
||||
'' == '@',
|
||||
],
|
||||
];
|
||||
|
14
bin/install
14
bin/install
@ -1,16 +1,14 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
|
||||
use Shlinkio\Shlink\CLI\Factory\InstallApplicationFactory;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\Config\Writer\PhpArray;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
chdir(dirname(__DIR__));
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$app = new Application();
|
||||
$command = new InstallCommand(new PhpArray(), new Filesystem());
|
||||
$app->add($command);
|
||||
$app->setDefaultCommand($command->getName());
|
||||
$app->run();
|
||||
$container = new ServiceManager(['factories' => [
|
||||
Application::class => InstallApplicationFactory::class,
|
||||
]]);
|
||||
$container->build(Application::class)->run();
|
||||
|
14
bin/update
14
bin/update
@ -1,16 +1,14 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
|
||||
use Shlinkio\Shlink\CLI\Factory\InstallApplicationFactory;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\Config\Writer\PhpArray;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
chdir(dirname(__DIR__));
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$app = new Application();
|
||||
$command = new InstallCommand(new PhpArray(), new Filesystem(), true);
|
||||
$app->add($command);
|
||||
$app->setDefaultCommand($command->getName());
|
||||
$app->run();
|
||||
$container = new ServiceManager(['factories' => [
|
||||
Application::class => InstallApplicationFactory::class,
|
||||
]]);
|
||||
$container->build(Application::class, ['isUpdate' => true])->run();
|
||||
|
41
module/CLI/src/Factory/InstallApplicationFactory.php
Normal file
41
module/CLI/src/Factory/InstallApplicationFactory.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Factory;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Interop\Container\Exception\ContainerException;
|
||||
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\Config\Writer\PhpArray;
|
||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||
|
||||
class InstallApplicationFactory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Create an object
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
* @param string $requestedName
|
||||
* @param null|array $options
|
||||
* @return object
|
||||
* @throws ServiceNotFoundException if unable to resolve the service.
|
||||
* @throws ServiceNotCreatedException if an exception is raised when
|
||||
* creating a service.
|
||||
* @throws ContainerException if any other error occurs
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
||||
{
|
||||
$isUpdate = $options !== null && isset($options['isUpdate']) ? (bool) $options['isUpdate'] : false;
|
||||
|
||||
$app = new Application();
|
||||
$command = new InstallCommand(new PhpArray(), new Filesystem(), $isUpdate);
|
||||
$app->add($command);
|
||||
$app->setDefaultCommand($command->getName());
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user