/**
  * @param InputInterface $input
  * @param Container $services
  * @return ITask
  */
 public function create(InputInterface $input, Container $services)
 {
     if (!$input->getArgument('action')) {
         throw new \InvalidArgumentException(sprintf('An action param is required: %s', json_encode(AliasCommand::$actions)));
     }
     if ($input->getArgument('action') === 'list') {
         return new Listing($services);
     }
     if ($input->getArgument('action') === 'save') {
         if (!$input->getArgument('name')) {
             throw new \InvalidArgumentException('name param is mandatory for this action');
         }
         if (!$input->getArgument('bootstrap')) {
             throw new \InvalidArgumentException('bootstrap param is mandatory for this action');
         }
         return new Saving($services);
     }
     if ($input->getArgument('action') === 'rm' || $input->getArgument('action') === 'remove') {
         if (!$input->getArgument('name')) {
             throw new \InvalidArgumentException('name param is mandatory for this action');
         }
         return new Removing($services);
     }
     $textFinder = new Finder($input->getArgument('action'), AliasCommand::$actions);
     throw new \InvalidArgumentException(sprintf('Action "%s" not supported. Did you mean "%s"?', $input->getArgument('action'), $textFinder->first()));
 }
Esempio n. 2
0
 /**
  * @param $moduleName
  * @param OutputInterface $output
  * @return int
  */
 private function listModule($moduleName, OutputInterface $output)
 {
     if (!$this->getService('module_manager')->has($moduleName)) {
         $textFinder = new Finder($moduleName, array_keys($this->getService('module_manager')->getAll()->getArrayCopy()));
         $output->writeln(sprintf('<error>Module "%s" not found! Did you mean "%s"?</error>', $moduleName, $textFinder->first()));
         return ITask::BLOCKING_ERROR_CODE;
     }
     $output->writeln($this->mapModule($this->getService('module_manager')->get($moduleName)));
     return ITask::NO_ERROR_CODE;
 }
Esempio n. 3
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $moduleName = $input->getArgument('name');
     if (!$this->getService('module_manager')->has($moduleName)) {
         $textFinder = new Finder($moduleName, array_keys($this->getService('module_manager')->getAll()->getArrayCopy()));
         $output->writeln(sprintf('<error>Module "%s" not found! Did you mean "%s"?</error>', $moduleName, $textFinder->first()));
         return ITask::BLOCKING_ERROR_CODE;
     }
     $module = $this->getService('module_manager')->get($moduleName);
     $module->setIsEnable($input->getArgument('action') === 'enable');
     $this->getService('module_manager')->modify($moduleName, $module);
     $output->writeln(sprintf('<info>Module "%s" modified</info>', $moduleName));
     return ITask::NO_ERROR_CODE;
 }
 /**
  * @param InputInterface $input
  * @param Container $services
  * @return ITask
  */
 public static function create(InputInterface $input, Container $services)
 {
     if (!$input->getArgument('action')) {
         throw new \InvalidArgumentException(sprintf('An action param is required: %s', json_encode(ModuleCommand::$actions)));
     }
     if ($input->getArgument('action') === 'list') {
         return new Listing($services);
     }
     if ($input->getArgument('action') === 'install') {
         return new Installing($services);
     }
     if ($input->getArgument('action') === 'update') {
         return new Updating($services);
     }
     if ($input->getArgument('action') === 'rm' || $input->getArgument('action') === 'remove') {
         if (!$input->getArgument('name')) {
             throw new \InvalidArgumentException('name param is mandatory for this action');
         }
         return new Removing($services);
     }
     if ($input->getArgument('action') === 'enable') {
         if (!$input->getArgument('name')) {
             throw new \InvalidArgumentException('name param is mandatory for this action');
         }
         return new Enabling($services);
     }
     if ($input->getArgument('action') === 'disable') {
         if (!$input->getArgument('name')) {
             throw new \InvalidArgumentException('name param is mandatory for this action');
         }
         return new Enabling($services);
     }
     if ($input->getArgument('action') === 'run') {
         return new Running($services);
     }
     $textFinder = new Finder($input->getArgument('action'), ModuleCommand::$actions);
     throw new \InvalidArgumentException(sprintf('Action "%s" not supported. Did you mean "%s"?', $input->getArgument('action'), $textFinder->first()));
 }
 /**
  * Test hasExactMatch() method
  */
 public function testHasNotExactMatch()
 {
     $text_finder = new Finder('banana', ['apple', 'kiwi']);
     $this->assertFalse($text_finder->hasExactMatch());
 }