Serves as a base class for commands.
Example #1
0
 /**
  * Invoke a command by calling all the registered callbacks
  *
  * @param  string|CommandInterface  $command    The command name or a CommandInterface object
  * @param  array|\Traversable       $attributes An associative array or a Traversable object
  * @param  ObjectInterface          $subject    The command subject
  * @return mixed|null If a callback break, returns the break condition. NULL otherwise.
  */
 public function invokeCallbacks($command, $attributes = null, $subject = null)
 {
     //Make sure we have an command object
     if (!$command instanceof CommandInterface) {
         if ($attributes instanceof CommandInterface) {
             $name = $command;
             $command = $attributes;
             $command->setName($name);
         } else {
             $command = new Command($command, $attributes, $subject);
         }
     }
     foreach ($this->getCommandCallbacks($command->getName()) as $handler) {
         $method = $handler['method'];
         $params = $handler['params'];
         if (is_string($method)) {
             $result = $this->invokeCommandCallback($method, $command->append($params));
         } else {
             $result = $method($command->append($params));
         }
         if ($result !== null && $result === $this->getBreakCondition()) {
             return $result;
         }
     }
 }
Example #2
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     if (strtolower($command->getName()) == "popup") {
         if ($sender->hasPermission("joinpopup") || $sender->hasPermission("joinpopup.command")) {
             if (isset($args[0]) == "off") {
                 if (isset($this->playersEnabled[$sender->getName()])) {
                     unset($this->playersEnabled[$sender->getName()]);
                     $sender->sendMessage("Popups disabled");
                     return true;
                 } else {
                     $sender->sendMessage("Popups aren't enabled for you");
                     return true;
                 }
             } elseif ($args[0] == "on") {
                 if (isset($this->playersEnabled[$sender->getName()])) {
                     $sender->sendMessage("Popups are already enabled for you");
                     return true;
                 } else {
                     $this->playersEnabled[$sender->getName] = $sender->getName();
                     $sender->sendMessage("Popups has been enabled for you");
                     return true;
                 }
             } else {
                 $sender->sendMessage("Unknown argument: " . $args[0]);
                 return true;
             }
         } else {
             $sender->sendMessage("You don't have permission to use that command!");
             return true;
         }
     }
 }
 private static function shellCommandString($string)
 {
     $command = new Command();
     $command->configure($string);
     $shellCommand = new ShellCommand($command);
     return strval($shellCommand);
 }
Example #4
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     $article = (yield from $this->fetchArticleFromArgs($context, ...$command->args()));
     if ($article) {
         yield from $context->writeResponse(new Response(223, '%d %s Article exists', $article->number(), $article->id()));
     }
 }
 /**
  * @param Command $command
  *
  * @return string
  */
 public function generate(Command $command)
 {
     $origMethodName = $command->getMethod() ?: $command->getName();
     $methodNameParts = explode('-', $origMethodName);
     $methodNameStart = array_shift($methodNameParts);
     $methodNameEnd = implode('', array_map('ucfirst', $methodNameParts));
     return $methodNameStart . $methodNameEnd . 'Cmd';
 }
Example #6
0
 /**
  * Test that the default value is overwritten when the parameter
  * 	is defined.
  */
 public function testParseDefaultValueIsDefined()
 {
     $config = ['default' => ['test' => 'testing1234']];
     $arguments = ['script-name.php', '--test=foobar'];
     $cmd = new Command();
     $result = $cmd->execute($arguments, $config);
     $this->assertEquals('foobar', $result['test']);
 }
Example #7
0
 /**
  * Add a command to this collection.
  *
  * @param  Command $command  The command to add
  *
  * @return CommandCollection Returns $this for chainability
  *
  * @throws \InvalidArgumentException If a command with the same name has
  *                                   already been set on this collection
  */
 public function add(Command $command)
 {
     if (isset($this->_commands[$command->getName()])) {
         throw new \InvalidArgumentException(sprintf('Command `%s` is already defined', $command->getName()));
     }
     $this->_commands[$command->getName()] = $command;
     return $this;
 }
Example #8
0
 /**
  * adds message to command
  *
  * @param	mixed	$message
  * @return	void
  */
 protected function addMessage($message)
 {
     // vsetky prechecky su od systemu urcene pre aktualneho usera
     if (!$message['toUser']) {
         $loggedUser = $this->command->getLoggedUser();
         $message['toUser'] = $loggedUser['id'];
     }
     $this->command->addMessage($message);
 }
 /**
  * Ask the user is they wish to overwrite an existing file
  *
  * @param string    $path   The path that already exists
  */
 public function doesTheUserWantToOverwriteExistingFile($path)
 {
     if (false !== $this->command->confirm("This form validator at:\n" . $path . "\nalready exists: Do you want to overwrite it? (y|N)", false)) {
         // The user wants to overwrite the file so fire the process again with the force option set to true
         $this->command->fire(true);
         exit;
     }
     $this->command->error('You have chosen NOT to overwrite the file...Good choice!');
     exit;
 }
Example #10
0
 public function postCommandRun(Command $command, $method, $args)
 {
     $mode = Current::$config->get('mode');
     $packages = $command->getCSS();
     if ($mode == 'production') {
         $this->packageForProduction($packages);
     } else {
         $this->packageForDevelopment($packages);
     }
 }
Example #11
0
 /**
  * Queries the google analytics service.
  *
  * @param Command $command The command with the query params
  *
  * @return Response If an error occurred when querying the google analytics service.
  *
  * @throws GoogleAnalyticsException If Query is invalid
  *
  */
 public function query(Command $command)
 {
     $accessToken = $this->getClient()->getAccessToken();
     $uri = $command->build($accessToken);
     $content = $this->getClient()->getHttpAdapter()->getContent($uri);
     $json = json_decode($content, true);
     if (!is_array($json) || isset($json['error'])) {
         throw GoogleAnalyticsException::invalidQuery(isset($json['error']) ? $json['error']['message'] : 'Invalid json');
     }
     return new Response($json, $command);
 }
Example #12
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch (strtolower($command->getName())) {
         case "changepw":
             //Change password...
             break;
         case "unregister":
             //Unregister...
             break;
     }
 }
Example #13
0
 /**
  * @param  Context $context
  * @return boolean
  **/
 public function execute(Context $context)
 {
     if ($context->getCurrentCommand() != 'begin') {
         throw new \Exception('構文が正しくありません');
     }
     if (is_null($this->next_command)) {
         throw new \Exception('次のコマンドが指定されていません');
     }
     $this->next_command->execute($context->next());
     return true;
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $filesystem
  * @param Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $reference = $this->command->option('shared') ? 'shared' : $application->getReference();
     $path = base_path("addons/{$reference}/{$this->vendor}/{$this->slug}-{$this->type}");
     $modulePath = __DIR__ . '/../../../resources/assets/module';
     $data = $this->getTemplateData();
     /* Make module's folder */
     $filesystem->makeDirectory($path, 0755, true, true);
     /* Copy module template files */
     $filesystem->parseDirectory($modulePath . "/template", $path . '/', $data);
     return $path;
 }
Example #15
0
File: Sh.php Project: gonzalo123/sh
 /**
  * @param string             $name
  * @param null|string|array  $comandArgument
  * @param null|Callable      $lineCallback
  * @return null|string
  */
 public function runCommand($name, $comandArgument = null, $lineCallback = null)
 {
     $output = null;
     $command = new Command($name, $comandArgument);
     $command->setSh($this);
     if (is_null($lineCallback)) {
         return $command;
     } else {
         $command->setLineCallback($lineCallback);
         return $command->doCallback();
     }
 }
Example #16
0
 /**
  * Zpracuje command a nastavi vlastnosti objektu.
  *
  * @return Bobr_AbstractModule
  */
 protected function assignCommand()
 {
     $command = $this->command->toArray();
     array_shift($command);
     if (isset($command[0])) {
         $this->setAction($command[0]);
         array_shift($command);
         if (isset($command[0])) {
             $this->setParams($command);
         }
     } else {
         $this->action = 'default';
     }
     return $this;
 }
Example #17
0
 public function handle(Command $command, ClientContext $context) : Generator
 {
     if ($command->argCount() === 0) {
         $group = $this->currentGroup;
     }
     $name = $command->arg(0);
     $group = (yield from $context->getAccessLayer()->getGroupByName($name));
     if (!$group) {
         yield from $context->writeResponse(new Response(411, 'No such newsgroup'));
         return;
     }
     $context->setCurrentGroup($group->name());
     $context->setCurrentArticle($group->lowWaterMark());
     yield from $context->writeResponse(new Response(211, $group->count() . ' ' . $group->lowWaterMark() . ' ' . $group->highWaterMark() . ' ' . $group->name() . ' Group successfully selected'));
 }
 /**
  * Overrides ITC\Weixin\Payment\Command\Command#validateParams.
  *
  * @param void
  *
  * @return array
  */
 protected function validateParams(array $params, array &$errors)
 {
     parent::validateParams($params, $errors);
     if ($params['trade_type'] === 'JSAPI' && empty($params['openid'])) {
         $errors[] = 'openid parameter is required if trade_type is JSAPI';
     }
 }
Example #19
0
 public function __construct()
 {
     global $verbose;
     parent::__construct();
     $this->_add_commands();
     $verbose = $this->option('verbose');
 }
 public function __construct($page = null, $action = null)
 {
     parent::__construct();
     $this->page = $page ? ucfirst($page) : 'Main';
     $this->action = $action ? ucfirst($action) : 'Index';
     $this->command = $this->klassenName = null;
 }
Example #21
0
 /**
  * Setup the application container as we'll need this for running migrations.
  */
 public function __construct(Container $app)
 {
     parent::__construct();
     $this->app = $app;
     $this->RoutesGenerator = $this->app->make('Devise\\Pages\\RoutesGenerator');
     $this->Config = Config::getFacadeRoot();
 }
Example #22
0
 public function __construct($workingDir = '.', $info, $commandsSeq = array())
 {
     parent::__construct($workingDir, $info, $commandsSeq);
     Console::initCore();
     $this->root_dir = Config::get('ROOT_DIR');
     $this->models_dir = Config::get('models_dir');
 }
Example #23
0
 public function play()
 {
     $command = '';
     if ($this->game['status'] == Game::GAME_STATUS_INITIALIZED) {
         $command = $this->selectCharacter();
     } elseif ($this->player['phase'] == Player::PHASE_DRAW_HIGH_NOON) {
         $command = $this->drawOneTurnCard();
     } elseif ($this->player['phase'] == Player::PHASE_DYNAMITE) {
         $command = $this->drawDynamite();
     } elseif ($this->player['phase'] == Player::PHASE_JAIL) {
         $command = $this->drawJail();
     } elseif ($this->player['phase'] == Player::PHASE_RATTLESNAKE) {
         $command = $this->drawRattlesnake();
     } elseif ($this->player['phase'] == Player::PHASE_DRAW) {
         $command = $this->draw();
     } elseif ($this->player['phase'] == Player::PHASE_PLAY) {
         if ($this->player['possible_choices'] != '') {
             $command = $this->chooseCards();
         } else {
             $command = $this->playCards();
         }
     } elseif ($this->player['phase'] == Player::PHASE_UNDER_ATTACK) {
         $command = $this->reactToAttack();
     } elseif ($this->player['phase'] == Player::PHASE_HIGH_NOON) {
         $command = $this->takeLifeDown();
     } else {
         $this->whatToDo();
     }
     if ($command) {
         Log::logAiAction('ai player ' . $this->player['id'] . ': ' . $command);
         Command::setup($command, $this->game, $this->player);
     }
 }
 /**
  * @return ScriptInfo
  */
 public static function fromArray($array)
 {
     $object = parent::fromArray($array);
     $object->paramDescs = ScriptSettings::fromArrayOfArray($object->paramDescs);
     $object->commandDescs = Command::fromArrayOfArray($object->commandDescs);
     return $object;
 }
Example #25
0
 /**
  * ページを表示する。
  *
  * @param	array(string => string)	$value	スキンに渡す値。bodyとtitleは必須。
  */
 function render($value)
 {
     $command = array();
     foreach (Command::getCommands() as $c) {
         $html = $c->getbody();
         if ($html != '') {
             $command[substr(get_class($c), 8)] = $html;
         }
     }
     $plugin = array();
     foreach (Plugin::getPlugins() as $c) {
         $html = $c->getbody();
         if ($html != '') {
             $plugin[substr(get_class($c), 7)] = $html;
         }
     }
     $this->smarty->assign('command', $command);
     $this->smarty->assign('plugin', $plugin);
     $this->smarty->assign('option', $this->option);
     $this->smarty->assign('headeroption', $this->headeroption);
     $this->smarty->assign('theme', $this->theme);
     $this->smarty->assign($value);
     header('Content-Type: text/html; charset=UTF-8');
     $this->smarty->assign('runningtime', sprintf('%.3f', mtime() - STARTTIME));
     $this->smarty->display(SKINFILE);
 }
 public function getAll()
 {
     if (!isset($this->Elements) || $this->countElements() < 0) {
         return Command::getEmptyInstance();
     }
     return $this->Elements;
 }
Example #27
0
 /**
  * Overrides ITC\Weixin\Payment\Command\Command#validateParams
  * @param void
  * @return array
  */
 protected function validateParams(array $params, array &$errors)
 {
     parent::validateParams($params, $errors);
     if (empty($params['transaction_id']) && empty($params['out_trade_no'])) {
         $errors[] = 'transaction_id and out_trade_no cannot *both* be empty';
     }
 }
 public function upMigration()
 {
     echo PHP_EOL;
     Command::run(array('migrate:install'));
     echo PHP_EOL;
     Command::run(array('migrate'));
 }
Example #29
0
 protected function _to_client()
 {
     $web_format = config('settings', 'web_format');
     header('Content-type: application/' . $web_format);
     echo Format::converter(Command::get_report(), $web_format);
     exit;
 }
Example #30
-4
File: help.php Project: demental/m
 public function execute($params)
 {
     if (is_array($params) && count($params) > 0) {
         $command = array_shift($params);
         $exec = Command::factory($command);
         $exec->longHelp($params);
     } else {
         $this->line('This command displays global help text or specific help text for a command if provided');
         $this->line('Usage:');
         $this->line('help');
         $this->line('  Displays this help');
         $this->line('help [COMMAND_NAME]');
         $this->line('  Displays specific and longer help for [COMMAND_NAME]');
         $this->line('help [COMMAND_NAME] [SUBCOMMAND_NAME] and so on....');
         $this->line('  Displays specific and longer help for [SUBCOMMAND_NAME] if [COMMAND_NAME] contains some subcommands (e.g. the plugin command)');
         $this->line('==========');
         $this->line('Here is the list of available root commands:');
         $dir = dirname(realpath(__FILE__));
         foreach (FileUtils::getAllFiles($dir, 'php') as $afile) {
             $subcname = basename($afile, '.php');
             $subc = Command::factory($subcname);
             $this->line('====== ' . $subcname . ' ======');
             $subc->shortHelp();
         }
     }
 }