mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-28 12:32:01 +03:00
Moved console Application creation to factory
This commit is contained in:
parent
12322b7368
commit
25380e4727
4 changed files with 9 additions and 9 deletions
8
bin/cli
8
bin/cli
|
@ -2,16 +2,10 @@
|
||||||
<?php
|
<?php
|
||||||
use Interop\Container\ContainerInterface;
|
use Interop\Container\ContainerInterface;
|
||||||
use Symfony\Component\Console\Application as CliApp;
|
use Symfony\Component\Console\Application as CliApp;
|
||||||
use Symfony\Component\Console\Application;
|
|
||||||
use Zend\I18n\Translator\Translator;
|
|
||||||
|
|
||||||
/** @var ContainerInterface $container */
|
/** @var ContainerInterface $container */
|
||||||
$container = include __DIR__ . '/../config/container.php';
|
$container = include __DIR__ . '/../config/container.php';
|
||||||
|
|
||||||
/** @var Translator $translator */
|
/** @var CliApp $app */
|
||||||
$translator = $container->get('translator');
|
|
||||||
$translator->setLocale(env('CLI_LOCALE', 'en'));
|
|
||||||
|
|
||||||
/** @var Application $app */
|
|
||||||
$app = $container->get(CliApp::class);
|
$app = $container->get(CliApp::class);
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
@ -3,7 +3,7 @@ return [
|
||||||
|
|
||||||
'app_options' => [
|
'app_options' => [
|
||||||
'name' => 'Shlink',
|
'name' => 'Shlink',
|
||||||
'version' => '1.1.0',
|
'version' => '1.2.0',
|
||||||
'secret_key' => env('SECRET_KEY'),
|
'secret_key' => env('SECRET_KEY'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use Shlinkio\Shlink\CLI\Command;
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'cli' => [
|
'cli' => [
|
||||||
|
'locale' => env('CLI_LOCALE', 'en'),
|
||||||
'commands' => [
|
'commands' => [
|
||||||
Command\Shortcode\GenerateShortcodeCommand::class,
|
Command\Shortcode\GenerateShortcodeCommand::class,
|
||||||
Command\Shortcode\ResolveUrlCommand::class,
|
Command\Shortcode\ResolveUrlCommand::class,
|
||||||
|
|
|
@ -3,7 +3,9 @@ namespace Shlinkio\Shlink\CLI\Factory;
|
||||||
|
|
||||||
use Interop\Container\ContainerInterface;
|
use Interop\Container\ContainerInterface;
|
||||||
use Interop\Container\Exception\ContainerException;
|
use Interop\Container\Exception\ContainerException;
|
||||||
|
use Shlinkio\Shlink\Core\Options\AppOptions;
|
||||||
use Symfony\Component\Console\Application as CliApp;
|
use Symfony\Component\Console\Application as CliApp;
|
||||||
|
use Zend\I18n\Translator\Translator;
|
||||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
||||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
||||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||||
|
@ -25,9 +27,12 @@ class ApplicationFactory implements FactoryInterface
|
||||||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
||||||
{
|
{
|
||||||
$config = $container->get('config')['cli'];
|
$config = $container->get('config')['cli'];
|
||||||
$app = new CliApp('Shlink', '1.0.0');
|
$appOptions = $container->get(AppOptions::class);
|
||||||
|
$translator = $container->get(Translator::class);
|
||||||
|
$translator->setLocale($config['locale']);
|
||||||
|
|
||||||
$commands = isset($config['commands']) ? $config['commands'] : [];
|
$commands = isset($config['commands']) ? $config['commands'] : [];
|
||||||
|
$app = new CliApp($appOptions->getName(), $appOptions->getVersion());
|
||||||
foreach ($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
if (! $container->has($command)) {
|
if (! $container->has($command)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue