本文整理汇总了PHP中Command类的典型用法代码示例。如果您正苦于以下问题:PHP Command类的具体用法?PHP Command怎么用?PHP Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invokeCallbacks
/**
* 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;
}
}
}
示例2: onCommand
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;
}
}
}
示例3: shellCommandString
private static function shellCommandString($string)
{
$command = new Command();
$command->configure($string);
$shellCommand = new ShellCommand($command);
return strval($shellCommand);
}
示例4: handle
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()));
}
}
示例5: generate
/**
* @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';
}
示例6: testParseDefaultValueIsDefined
/**
* 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']);
}
示例7: add
/**
* 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;
}
示例8: postCommandRun
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);
}
}
示例9: query
/**
* 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);
}
示例10: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch (strtolower($command->getName())) {
case "changepw":
//Change password...
break;
case "unregister":
//Unregister...
break;
}
}
示例11: execute
/**
* @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;
}
示例12: runCommand
/**
* @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();
}
}
示例13: assignCommand
/**
* 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;
}
示例14: handle
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'));
}
示例15: validateParams
/**
* 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';
}
}