/** * 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; }
/** * 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; } } }
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; } } }
/** * @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'; }
public function testCommand() { $cmd = new Command('cmd', 'description', ['cmd1', 'cmd2'], true, 'cmdMethod'); $this->assertSame('cmd', $cmd->getName()); $this->assertSame('description', $cmd->getDescription()); $this->assertSame(['cmd1', 'cmd2'], $cmd->getAliases()); $this->assertTrue($cmd->isDefault()); $this->assertSame('cmdMethod', $cmd->getMethod()); }
public function onCommand(CommandSender $sender, Command $command, $label, array $args) { switch (strtolower($command->getName())) { case "changepw": //Change password... break; case "unregister": //Unregister... break; } }
/** * @param SmartyHelper $smartyHelper * @param Command $cmd */ public static function displayCommand(SmartyHelper $smartyHelper, Command $cmd, $isManager, $selectedFilters = '') { if ($isManager) { $smartyHelper->assign('isManager', true); } $smartyHelper->assign('cmdid', $cmd->getId()); $smartyHelper->assign('cmdName', $cmd->getName()); $smartyHelper->assign('cmdReference', $cmd->getReference()); $smartyHelper->assign('cmdVersion', $cmd->getVersion()); $smartyHelper->assign('cmdReporter', $cmd->getReporter()); $smartyHelper->assign('cmdStateList', self::getCommandStateList($cmd)); $smartyHelper->assign('cmdState', Command::$stateNames[$cmd->getState()]); $smartyHelper->assign('cmdAverageDailyRate', $cmd->getAverageDailyRate()); $smartyHelper->assign('cmdCurrency', $cmd->getCurrency()); if (!is_null($cmd->getStartDate())) { $smartyHelper->assign('cmdStartDate', date("Y-m-d", $cmd->getStartDate())); } if (!is_null($cmd->getDeadline())) { $smartyHelper->assign('cmdDeadline', date("Y-m-d", $cmd->getDeadline())); } $smartyHelper->assign('cmdDesc', $cmd->getDesc()); $smartyHelper->assign('cmdProvisionList', self::getProvisionList($cmd)); $smartyHelper->assign('cmdProvisionTypeMngt', CommandProvision::provision_mngt); $smartyHelper->assign('cmdProvisionTotalList', self::getProvisionTotalList($cmd)); $cmdTotalSoldDays = $cmd->getTotalSoldDays(); $smartyHelper->assign('cmdTotalSoldDays', $cmdTotalSoldDays); // -------------- // TODO math should not be in here ! $mgrEE = $cmd->getIssueSelection()->mgrEffortEstim; $cmdProvAndMeeCost = $mgrEE * $cmd->getAverageDailyRate() + $cmd->getProvisionBudget(TRUE); $smartyHelper->assign('cmdProvAndMeeCost', round($cmdProvAndMeeCost, 2)); $cmdProvAndMeeDays = $mgrEE + $cmd->getProvisionDays(TRUE); $smartyHelper->assign('cmdProvAndMeeDays', round($cmdProvAndMeeDays, 2)); // TODO math should not be in here ! $cmdTotalReestimated = $cmd->getIssueSelection()->getReestimated(); $smartyHelper->assign('cmdTotalReestimated', $cmdTotalReestimated); $cmdTotalReestimatedCost = $cmdTotalReestimated * $cmd->getAverageDailyRate(); $smartyHelper->assign('cmdTotalReestimatedCost', $cmdTotalReestimatedCost); // TODO math should not be in here ! #$cmdTotalElapsed = $cmd->getIssueSelection()->getElapsed(); #$cmdOutlayCost = $cmdTotalElapsed * $cmd->getAverageDailyRate(); #$smartyHelper->assign('cmdOutlayCost',$cmdOutlayCost); #$smartyHelper->assign('cmdTotalElapsed',$cmdTotalElapsed); // TODO math should not be in here ! $cmdTotalDrift = round($cmdTotalReestimated - $cmdProvAndMeeDays, 2); $cmdTotalDriftCost = round($cmdTotalReestimatedCost - $cmdProvAndMeeCost, 2); $cmdTotalDriftPercent = 0 == $cmdProvAndMeeDays ? 0 : round($cmdTotalDrift * 100 / $cmdProvAndMeeDays, 2); $smartyHelper->assign('cmdTotalDrift', $cmdTotalDrift); $smartyHelper->assign('cmdTotalDriftCost', $cmdTotalDriftCost); $smartyHelper->assign('cmdTotalDriftPercent', $cmdTotalDriftPercent); #$color1 = ($cmdOutlayCost > $cmdProvAndMeeCost) ? "fcbdbd" : "bdfcbd"; #$smartyHelper->assign('cmdOutlayCostColor', $color1); #$color2 = ($cmdTotalElapsed > $cmdProvAndMeeDays) ? "fcbdbd" : "bdfcbd"; #$smartyHelper->assign('cmdTotalElapsedColor',$color2); $color3 = $cmdTotalReestimated > $cmdProvAndMeeDays ? "fcbdbd" : "bdfcbd"; $smartyHelper->assign('cmdTotalReestimatedColor', $color3); $color4 = $cmdTotalReestimatedCost > $cmdProvAndMeeCost ? "fcbdbd" : "bdfcbd"; $smartyHelper->assign('cmdTotalReestimatedCostColor', $color4); $color5 = $cmdTotalDrift >= 0 ? "fcbdbd" : "bdfcbd"; $smartyHelper->assign('cmdTotalDriftColor', $color5); // -------------- // set CommandSets I belong to $smartyHelper->assign('parentCmdSets', self::getParentCommandSets($cmd)); // set task list $cmdIssueSel = $cmd->getIssueSelection(); $smartyHelper->assign('cmdNbIssues', $cmdIssueSel->getNbIssues()); $smartyHelper->assign('cmdIssues', self::getCommandIssues($cmd)); // used to create mantis link to view_all_bug_page.php: // view_all_set.php?type=1&temporary=y&FilterBugList_list=5079,5073,5108,5107,49396,5006 $mantisFilterBugList = implode(',', array_keys($cmdIssueSel->getIssueList())); $smartyHelper->assign('mantisFilterBugList', $mantisFilterBugList); // -------------- // Indicators & statistics // DetailedChargesIndicator $data = self::getDetailedCharges($cmd, $isManager, $selectedFilters); foreach ($data as $smartyKey => $smartyVariable) { $smartyHelper->assign($smartyKey, $smartyVariable); } }
protected function addCommand(Command $command) { $command->setDeps($this); $this->commands[$command->getName()] = $command; }
/** * Adds command to te stack * * Adds command with name (if possible) * to allow to override the command with the same name * * @param Command $command A Command object * * @return Command The registered command */ public function add(Command $command) { $command->setTransaction($this); if ($command->getName()) { $this->commands[$command->getName()] = $command; } else { $this->commands[] = $command; } return $command; }
/** * Safe comparator. * @param Command $command The commande to compare to. * @return boolean True if the compared command is the same of command parameter, false otherwise. */ public function equals($command) { return $command->getName() == $this->name; }
public function addCommand(Command $cmd) { $this->commands[$cmd->getName()] = $cmd; }