mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved and simplified all installation process thanks to symfony style
This commit is contained in:
parent
5de845c258
commit
4dffc9f0c1
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Shlinkio\Shlink\CLI\Factory\InstallApplicationFactory;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\DatabaseConfigCustomizerPlugin;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
use Zend\ServiceManager\Factory\InvokableFactory;
|
||||
@ -17,12 +17,11 @@ $container = new ServiceManager([
|
||||
'factories' => [
|
||||
Application::class => InstallApplicationFactory::class,
|
||||
Filesystem::class => InvokableFactory::class,
|
||||
QuestionHelper::class => InvokableFactory::class,
|
||||
],
|
||||
'services' => [
|
||||
'config' => [
|
||||
ConfigAbstractFactory::class => [
|
||||
DatabaseConfigCustomizerPlugin::class => [QuestionHelper::class, Filesystem::class]
|
||||
DatabaseConfigCustomizerPlugin::class => [Filesystem::class]
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Shlinkio\Shlink\CLI\Factory\InstallApplicationFactory;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\DatabaseConfigCustomizerPlugin;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
use Zend\ServiceManager\Factory\InvokableFactory;
|
||||
@ -17,12 +17,11 @@ $container = new ServiceManager([
|
||||
'factories' => [
|
||||
Application::class => InstallApplicationFactory::class,
|
||||
Filesystem::class => InvokableFactory::class,
|
||||
QuestionHelper::class => InvokableFactory::class,
|
||||
],
|
||||
'services' => [
|
||||
'config' => [
|
||||
ConfigAbstractFactory::class => [
|
||||
DatabaseConfigCustomizerPlugin::class => [QuestionHelper::class, Filesystem::class]
|
||||
DatabaseConfigCustomizerPlugin::class => [Filesystem::class]
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -3,6 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Command\Install;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManagerInterface;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin;
|
||||
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
||||
@ -10,11 +12,9 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Zend\Config\Writer\WriterInterface;
|
||||
@ -24,17 +24,9 @@ class InstallCommand extends Command
|
||||
const GENERATED_CONFIG_PATH = 'config/params/generated_config.php';
|
||||
|
||||
/**
|
||||
* @var InputInterface
|
||||
* @var SymfonyStyle
|
||||
*/
|
||||
private $input;
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
/**
|
||||
* @var QuestionHelper
|
||||
*/
|
||||
private $questionHelper;
|
||||
private $io;
|
||||
/**
|
||||
* @var ProcessHelper
|
||||
*/
|
||||
@ -60,6 +52,7 @@ class InstallCommand extends Command
|
||||
* InstallCommand constructor.
|
||||
* @param WriterInterface $configWriter
|
||||
* @param Filesystem $filesystem
|
||||
* @param ConfigCustomizerPluginManagerInterface $configCustomizers
|
||||
* @param bool $isUpdate
|
||||
* @throws LogicException
|
||||
*/
|
||||
@ -83,30 +76,35 @@ class InstallCommand extends Command
|
||||
->setDescription('Installs or updates Shlink');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int|null|void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
$this->questionHelper = $this->getHelper('question');
|
||||
$this->io = new SymfonyStyle($input, $output);
|
||||
$this->processHelper = $this->getHelper('process');
|
||||
|
||||
$output->writeln([
|
||||
$this->io->writeln([
|
||||
'<info>Welcome to Shlink!!</info>',
|
||||
'This will guide you through the installation process.',
|
||||
]);
|
||||
|
||||
// Check if a cached config file exists and drop it if so
|
||||
if ($this->filesystem->exists('data/cache/app_config.php')) {
|
||||
$output->write('Deleting old cached config...');
|
||||
$this->io->write('Deleting old cached config...');
|
||||
try {
|
||||
$this->filesystem->remove('data/cache/app_config.php');
|
||||
$output->writeln(' <info>Success</info>');
|
||||
$this->io->writeln(' <info>Success</info>');
|
||||
} catch (IOException $e) {
|
||||
$output->writeln(
|
||||
$this->io->writeln(
|
||||
' <error>Failed!</error> You will have to manually delete the data/cache/app_config.php file to get'
|
||||
. ' new config applied.'
|
||||
);
|
||||
if ($output->isVerbose()) {
|
||||
if ($this->io->isVerbose()) {
|
||||
$this->getApplication()->renderException($e, $output);
|
||||
}
|
||||
return;
|
||||
@ -130,28 +128,37 @@ class InstallCommand extends Command
|
||||
|
||||
// Generate config params files
|
||||
$this->configWriter->toFile(self::GENERATED_CONFIG_PATH, $config->getArrayCopy(), false);
|
||||
$output->writeln(['<info>Custom configuration properly generated!</info>', '']);
|
||||
$this->io->writeln(['<info>Custom configuration properly generated!</info>', '']);
|
||||
|
||||
// If current command is not update, generate database
|
||||
if (! $this->isUpdate) {
|
||||
$this->output->writeln('Initializing database...');
|
||||
$this->io->writeln('Initializing database...');
|
||||
if (! $this->runCommand(
|
||||
'php vendor/bin/doctrine.php orm:schema-tool:create',
|
||||
'Error generating database.'
|
||||
'Error generating database.',
|
||||
$output
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Run database migrations
|
||||
$output->writeln('Updating database...');
|
||||
if (! $this->runCommand('php vendor/bin/doctrine-migrations migrations:migrate', 'Error updating database.')) {
|
||||
$this->io->writeln('Updating database...');
|
||||
if (! $this->runCommand(
|
||||
'php vendor/bin/doctrine-migrations migrations:migrate',
|
||||
'Error updating database.',
|
||||
$output
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate proxies
|
||||
$output->writeln('Generating proxies...');
|
||||
if (! $this->runCommand('php vendor/bin/doctrine.php orm:generate-proxies', 'Error generating proxies.')) {
|
||||
$this->io->writeln('Generating proxies...');
|
||||
if (! $this->runCommand(
|
||||
'php vendor/bin/doctrine.php orm:generate-proxies',
|
||||
'Error generating proxies.',
|
||||
$output
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -160,14 +167,14 @@ class InstallCommand extends Command
|
||||
* @return CustomizableAppConfig
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function importConfig()
|
||||
private function importConfig(): CustomizableAppConfig
|
||||
{
|
||||
$config = new CustomizableAppConfig();
|
||||
|
||||
// Ask the user if he/she wants to import an older configuration
|
||||
$importConfig = $this->questionHelper->ask($this->input, $this->output, new ConfirmationQuestion(
|
||||
$importConfig = $this->io->confirm(
|
||||
'<question>Do you want to import previous configuration? (Y/n):</question> '
|
||||
));
|
||||
);
|
||||
if (! $importConfig) {
|
||||
return $config;
|
||||
}
|
||||
@ -182,10 +189,10 @@ class InstallCommand extends Command
|
||||
$configExists = $this->filesystem->exists($configFile);
|
||||
|
||||
if (! $configExists) {
|
||||
$keepAsking = $this->questionHelper->ask($this->input, $this->output, new ConfirmationQuestion(
|
||||
$keepAsking = $this->io->confirm(
|
||||
'Provided path does not seem to be a valid shlink root path. '
|
||||
. '<question>Do you want to try another path? (Y/n):</question> '
|
||||
));
|
||||
);
|
||||
}
|
||||
} while (! $configExists && $keepAsking);
|
||||
|
||||
@ -206,18 +213,16 @@ class InstallCommand extends Command
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function ask($text, $default = null, $allowEmpty = false)
|
||||
private function ask($text, $default = null, $allowEmpty = false): string
|
||||
{
|
||||
if ($default !== null) {
|
||||
$text .= ' (defaults to ' . $default . ')';
|
||||
}
|
||||
|
||||
do {
|
||||
$value = $this->questionHelper->ask($this->input, $this->output, new Question(
|
||||
'<question>' . $text . ':</question> ',
|
||||
$default
|
||||
));
|
||||
$value = $this->io->ask('<question>' . $text . ':</question> ', $default);
|
||||
if (empty($value) && ! $allowEmpty) {
|
||||
$this->output->writeln('<error>Value can\'t be empty</error>');
|
||||
$this->io->writeln('<error>Value can\'t be empty</error>');
|
||||
}
|
||||
} while (empty($value) && $default === null && ! $allowEmpty);
|
||||
|
||||
@ -227,21 +232,22 @@ class InstallCommand extends Command
|
||||
/**
|
||||
* @param string $command
|
||||
* @param string $errorMessage
|
||||
* @param OutputInterface $output
|
||||
* @return bool
|
||||
*/
|
||||
private function runCommand($command, $errorMessage)
|
||||
private function runCommand($command, $errorMessage, OutputInterface $output): bool
|
||||
{
|
||||
$process = $this->processHelper->run($this->output, $command);
|
||||
$process = $this->processHelper->run($output, $command);
|
||||
if ($process->isSuccessful()) {
|
||||
$this->output->writeln(' <info>Success!</info>');
|
||||
$this->io->writeln(' <info>Success!</info>');
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->output->isVerbose()) {
|
||||
if ($this->io->isVerbose()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->output->writeln(
|
||||
$this->io->writeln(
|
||||
' <error>' . $errorMessage . '</error> Run this command with -vvv to see specific error info.'
|
||||
);
|
||||
return false;
|
||||
|
@ -8,7 +8,6 @@ use Interop\Container\Exception\ContainerException;
|
||||
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
|
||||
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManager;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\Factory\DefaultConfigCustomizerPluginFactory;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
@ -17,6 +16,7 @@ use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||
use Zend\ServiceManager\Factory\InvokableFactory;
|
||||
|
||||
class InstallApplicationFactory implements FactoryInterface
|
||||
{
|
||||
@ -43,9 +43,9 @@ class InstallApplicationFactory implements FactoryInterface
|
||||
$container->get(Filesystem::class),
|
||||
new ConfigCustomizerPluginManager($container, ['factories' => [
|
||||
Plugin\DatabaseConfigCustomizerPlugin::class => ConfigAbstractFactory::class,
|
||||
Plugin\UrlShortenerConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
|
||||
Plugin\LanguageConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
|
||||
Plugin\ApplicationConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
|
||||
Plugin\UrlShortenerConfigCustomizerPlugin::class => InvokableFactory::class,
|
||||
Plugin\LanguageConfigCustomizerPlugin::class => InvokableFactory::class,
|
||||
Plugin\ApplicationConfigCustomizerPlugin::class => InvokableFactory::class,
|
||||
]]),
|
||||
$isUpdate
|
||||
);
|
||||
|
@ -3,66 +3,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Install\Plugin;
|
||||
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
abstract class AbstractConfigCustomizerPlugin implements ConfigCustomizerPluginInterface
|
||||
{
|
||||
/**
|
||||
* @var QuestionHelper
|
||||
*/
|
||||
protected $questionHelper;
|
||||
|
||||
public function __construct(QuestionHelper $questionHelper)
|
||||
{
|
||||
$this->questionHelper = $questionHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @param SymfonyStyle $io
|
||||
* @param string $text
|
||||
* @param string|null $default
|
||||
* @param bool $allowEmpty
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function ask(InputInterface $input, OutputInterface $output, $text, $default = null, $allowEmpty = false)
|
||||
protected function ask(SymfonyStyle $io, $text, $default = null, $allowEmpty = false): string
|
||||
{
|
||||
if ($default !== null) {
|
||||
$text .= ' (defaults to ' . $default . ')';
|
||||
}
|
||||
do {
|
||||
$value = $this->questionHelper->ask($input, $output, new Question(
|
||||
'<question>' . $text . ':</question> ',
|
||||
$default
|
||||
));
|
||||
$value = $io->ask('<question>' . $text . ':</question> ', $default);
|
||||
if (empty($value) && ! $allowEmpty) {
|
||||
$output->writeln('<error>Value can\'t be empty</error>');
|
||||
$io->writeln('<error>Value can\'t be empty</error>');
|
||||
}
|
||||
} while (empty($value) && $default === null && ! $allowEmpty);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
* @param string $text
|
||||
*/
|
||||
protected function printTitle(OutputInterface $output, $text)
|
||||
{
|
||||
$text = trim($text);
|
||||
$length = strlen($text) + 4;
|
||||
$header = str_repeat('*', $length);
|
||||
|
||||
$output->writeln([
|
||||
'',
|
||||
'<info>' . $header . '</info>',
|
||||
'<info>* ' . strtoupper($text) . ' *</info>',
|
||||
'<info>' . $header . '</info>',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
||||
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
{
|
||||
@ -22,18 +22,18 @@ class ApplicationConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
*/
|
||||
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
|
||||
{
|
||||
$this->printTitle($output, 'APPLICATION');
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('APPLICATION');
|
||||
|
||||
if ($appConfig->hasApp() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion(
|
||||
if ($appConfig->hasApp() && $io->confirm(
|
||||
'<question>Do you want to keep imported application config? (Y/n):</question> '
|
||||
))) {
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$appConfig->setApp([
|
||||
'SECRET' => $this->ask(
|
||||
$input,
|
||||
$output,
|
||||
$io,
|
||||
'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one)',
|
||||
null,
|
||||
true
|
||||
|
@ -3,14 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Install\Plugin;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
|
||||
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
@ -27,16 +24,8 @@ class DatabaseConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* DatabaseConfigCustomizerPlugin constructor.
|
||||
* @param QuestionHelper $questionHelper
|
||||
* @param Filesystem $filesystem
|
||||
*
|
||||
* @DI\Inject({QuestionHelper::class, Filesystem::class})
|
||||
*/
|
||||
public function __construct(QuestionHelper $questionHelper, Filesystem $filesystem)
|
||||
public function __construct(Filesystem $filesystem)
|
||||
{
|
||||
parent::__construct($questionHelper);
|
||||
$this->filesystem = $filesystem;
|
||||
}
|
||||
|
||||
@ -50,11 +39,12 @@ class DatabaseConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
*/
|
||||
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
|
||||
{
|
||||
$this->printTitle($output, 'DATABASE');
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('DATABASE');
|
||||
|
||||
if ($appConfig->hasDatabase() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion(
|
||||
if ($appConfig->hasDatabase() && $io->confirm(
|
||||
'<question>Do you want to keep imported database config? (Y/n):</question> '
|
||||
))) {
|
||||
)) {
|
||||
// If the user selected to keep DB config and is configured to use sqlite, copy DB file
|
||||
if ($appConfig->getDatabase()['DRIVER'] === self::DATABASE_DRIVERS['SQLite']) {
|
||||
try {
|
||||
@ -74,20 +64,20 @@ class DatabaseConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
// Select database type
|
||||
$params = [];
|
||||
$databases = array_keys(self::DATABASE_DRIVERS);
|
||||
$dbType = $this->questionHelper->ask($input, $output, new ChoiceQuestion(
|
||||
$dbType = $io->choice(
|
||||
'<question>Select database type (defaults to ' . $databases[0] . '):</question>',
|
||||
$databases,
|
||||
0
|
||||
));
|
||||
);
|
||||
$params['DRIVER'] = self::DATABASE_DRIVERS[$dbType];
|
||||
|
||||
// Ask for connection params if database is not SQLite
|
||||
if ($params['DRIVER'] !== self::DATABASE_DRIVERS['SQLite']) {
|
||||
$params['NAME'] = $this->ask($input, $output, 'Database name', 'shlink');
|
||||
$params['USER'] = $this->ask($input, $output, 'Database username');
|
||||
$params['PASSWORD'] = $this->ask($input, $output, 'Database password');
|
||||
$params['HOST'] = $this->ask($input, $output, 'Database host', 'localhost');
|
||||
$params['PORT'] = $this->ask($input, $output, 'Database port', $this->getDefaultDbPort($params['DRIVER']));
|
||||
$params['NAME'] = $this->ask($io, 'Database name', 'shlink');
|
||||
$params['USER'] = $this->ask($io, 'Database username');
|
||||
$params['PASSWORD'] = $this->ask($io, 'Database password');
|
||||
$params['HOST'] = $this->ask($io, 'Database host', 'localhost');
|
||||
$params['PORT'] = $this->ask($io, 'Database port', $this->getDefaultDbPort($params['DRIVER']));
|
||||
}
|
||||
|
||||
$appConfig->setDatabase($params);
|
||||
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Install\Plugin\Factory;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Interop\Container\Exception\ContainerException;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||
|
||||
class DefaultConfigCustomizerPluginFactory 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)
|
||||
{
|
||||
return new $requestedName($container->get(QuestionHelper::class));
|
||||
}
|
||||
}
|
@ -7,8 +7,7 @@ use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
{
|
||||
@ -23,27 +22,28 @@ class LanguageConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
*/
|
||||
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
|
||||
{
|
||||
$this->printTitle($output, 'LANGUAGE');
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('LANGUAGE');
|
||||
|
||||
if ($appConfig->hasLanguage() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion(
|
||||
if ($appConfig->hasLanguage() && $io->confirm(
|
||||
'<question>Do you want to keep imported language? (Y/n):</question> '
|
||||
))) {
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$appConfig->setLanguage([
|
||||
'DEFAULT' => $this->questionHelper->ask($input, $output, new ChoiceQuestion(
|
||||
'DEFAULT' => $io->choice(
|
||||
'<question>Select default language for the application in general (defaults to '
|
||||
. self::SUPPORTED_LANGUAGES[0] . '):</question>',
|
||||
self::SUPPORTED_LANGUAGES,
|
||||
0
|
||||
)),
|
||||
'CLI' => $this->questionHelper->ask($input, $output, new ChoiceQuestion(
|
||||
),
|
||||
'CLI' => $io->choice(
|
||||
'<question>Select default language for CLI executions (defaults to '
|
||||
. self::SUPPORTED_LANGUAGES[0] . '):</question>',
|
||||
self::SUPPORTED_LANGUAGES,
|
||||
0
|
||||
)),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
{
|
||||
@ -22,35 +21,31 @@ class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
|
||||
*/
|
||||
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
|
||||
{
|
||||
$this->printTitle($output, 'URL SHORTENER');
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('URL SHORTENER');
|
||||
|
||||
if ($appConfig->hasUrlShortener() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion(
|
||||
if ($appConfig->hasUrlShortener() && $io->confirm(
|
||||
'<question>Do you want to keep imported URL shortener config? (Y/n):</question> '
|
||||
))) {
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask for URL shortener params
|
||||
$appConfig->setUrlShortener([
|
||||
'SCHEMA' => $this->questionHelper->ask($input, $output, new ChoiceQuestion(
|
||||
'SCHEMA' => $io->choice(
|
||||
'<question>Select schema for generated short URLs (defaults to http):</question>',
|
||||
['http', 'https'],
|
||||
0
|
||||
)),
|
||||
'HOSTNAME' => $this->ask($input, $output, 'Hostname for generated URLs'),
|
||||
),
|
||||
'HOSTNAME' => $this->ask($io, 'Hostname for generated URLs'),
|
||||
'CHARS' => $this->ask(
|
||||
$input,
|
||||
$output,
|
||||
$io,
|
||||
'Character set for generated short codes (leave empty to autogenerate one)',
|
||||
null,
|
||||
true
|
||||
) ?: str_shuffle(UrlShortener::DEFAULT_CHARS),
|
||||
'VALIDATE_URL' => $this->questionHelper->ask(
|
||||
$input,
|
||||
$output,
|
||||
new ConfirmationQuestion(
|
||||
'<question>Do you want to validate long urls by 200 HTTP status code on response (Y/n):</question>'
|
||||
)
|
||||
'VALIDATE_URL' => $io->confirm(
|
||||
'<question>Do you want to validate long urls by 200 HTTP status code on response (Y/n):</question>'
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\CLI\Install\Plugin\Factory;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\ApplicationConfigCustomizerPlugin;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\Factory\DefaultConfigCustomizerPluginFactory;
|
||||
use Shlinkio\Shlink\CLI\Install\Plugin\LanguageConfigCustomizerPlugin;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
class DefaultConfigCustomizerPluginFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DefaultConfigCustomizerPluginFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->factory = new DefaultConfigCustomizerPluginFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function createsProperService()
|
||||
{
|
||||
$instance = $this->factory->__invoke(new ServiceManager(['services' => [
|
||||
QuestionHelper::class => $this->prophesize(QuestionHelper::class)->reveal(),
|
||||
]]), ApplicationConfigCustomizerPlugin::class);
|
||||
$this->assertInstanceOf(ApplicationConfigCustomizerPlugin::class, $instance);
|
||||
|
||||
$instance = $this->factory->__invoke(new ServiceManager(['services' => [
|
||||
QuestionHelper::class => $this->prophesize(QuestionHelper::class)->reveal(),
|
||||
]]), LanguageConfigCustomizerPlugin::class);
|
||||
$this->assertInstanceOf(LanguageConfigCustomizerPlugin::class, $instance);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user