. */ namespace SP\Modules\Cli; use DI\DependencyException; use DI\NotFoundException; use Exception; use Psr\Container\ContainerInterface; use SP\Core\Context\ContextException; use SP\Core\Context\StatelessContext; use SP\Core\Language; use SP\Core\ModuleBase; use SP\Modules\Cli\Commands\BackupCommand; use SP\Modules\Cli\Commands\Crypt\UpdateMasterPasswordCommand; use SP\Modules\Cli\Commands\InstallCommand; use SP\Util\VersionUtil; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * Class Init * * @package SP\Modules\Cli */ final class Init extends ModuleBase { private const CLI_COMMANDS = [ InstallCommand::class, BackupCommand::class, UpdateMasterPasswordCommand::class ]; /** * @var StatelessContext */ protected $context; /** * @var Language */ protected $language; /** * @var Application */ protected $application; /** * Module constructor. * * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) { parent::__construct($container); $this->context = $container->get(StatelessContext::class); $this->language = $container->get(Language::class); $this->application = $container->get(Application::class); } /** * @param string $controller * * @throws ContextException * @throws DependencyException * @throws NotFoundException */ public function initialize(string $controller) { logger(__FUNCTION__); // Initialize context $this->context->initialize(); // Load config $this->config->loadConfig(); // Load language $this->language->setLanguage(); $this->initCli(); } /** * @throws DependencyException * @throws NotFoundException * @throws Exception */ private function initCli(): void { $this->application->setName('sysPass CLI'); $this->application->setVersion(implode('.', VersionUtil::getVersionArray())); foreach (self::CLI_COMMANDS as $command) { $this->application->add($this->container->get($command)); } $this->application->run( $this->container->get(InputInterface::class), $this->container->get(OutputInterface::class) ); } }