本文整理汇总了PHP中Command::setSubject方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::setSubject方法的具体用法?PHP Command::setSubject怎么用?PHP Command::setSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command::setSubject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute a command by executing all registered handlers
*
* If a command handler returns the 'break condition' the executing is halted. If no break condition is specified the
* the command chain will execute all command handlers, regardless of the handler result returned.
*
* @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 handler breaks, returns the break condition. NULL otherwise.
*/
public function execute($command, $attributes = null, $subject = null)
{
$result = null;
if ($this->isEnabled()) {
$this->__stack->push(clone $this->__queue);
//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);
}
}
//Set the command subject
if ($subject) {
$command->setSubject($subject);
}
foreach ($this->__stack->peek() as $handler) {
$result = $handler->execute($command, $this);
if ($result === $this->getBreakCondition()) {
break;
}
}
$this->__stack->pop();
}
return $result;
}