本文整理汇总了PHP中CommandContext::getSubject方法的典型用法代码示例。如果您正苦于以下问题:PHP CommandContext::getSubject方法的具体用法?PHP CommandContext::getSubject怎么用?PHP CommandContext::getSubject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandContext
的用法示例。
在下文中一共展示了CommandContext::getSubject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Command handler
*
* This functions returns void to prevent is from breaking the chain.
*
* @param string $name The command name
* @param object $context The command context
* @return void
*/
public function execute($name, CommandContext $context)
{
$type = '';
if ($context->getSubject()) {
$identifier = clone $context->getSubject()->getIdentifier();
if ($identifier->path) {
$type = array_shift($identifier->path);
} else {
$type = $identifier->name;
}
}
$parts = explode('.', $name);
$name = 'on' . ucfirst(array_shift($parts)) . ucfirst($type) . StringInflector::implode($parts);
$event = new Event(clone $context);
$event->setTarget($context->getSubject());
$this->getEventDispatcher()->dispatchEvent($name, $event);
}
示例2: execute
/**
* Command handler
*
* This function translates the command name to a command handler function of the format '_beforeController[Command]'
* or '_afterController[Command]. Command handler functions should be declared protected.
*
* @param string $name The command name
* @param CommandContext $context The command context
* @return boolean Always returns TRUE
*/
public final function execute($name, CommandContext $context)
{
$identifier = clone $context->getSubject()->getIdentifier();
$type = array_shift($identifier->path);
$parts = explode('.', $name);
$method = '_' . $parts[0] . ucfirst($type) . ucfirst($parts[1]);
if (method_exists($this, $method)) {
$this->{$method}($context);
}
return true;
}
示例3: execute
/**
* Command handler
*
* @param string $name The command name
* @param CommandContext $context The command context
*
* @return mixed Method result if the method exsist, NULL otherwise.
*/
public function execute($name, CommandContext $context)
{
$type = '';
$result = null;
if ($context->getSubject()) {
$identifier = clone $context->getSubject()->getIdentifier();
if ($identifier->path) {
$type = array_shift($identifier->path);
} else {
$type = $identifier->name;
}
}
$parts = explode('.', $name);
$method = !empty($type) ? '_' . $type . ucfirst(StringInflector::implode($parts)) : '_' . lcfirst(StringInflector::implode($parts));
//If the method exists call the method and return the result
if (in_array($method, $this->getMethods())) {
$result = $this->{$method}($context);
}
return $result;
}
示例4: execute
/**
* Command handler
*
* This function translated the command name to a command handler function of the format '_before[Command]' or
* '_after[Command]. Command handler functions should be declared protected.
*
* @param string $name The command name
* @param CommandContext $context The command context
*
* @return mixed Method result if the method exists, NULL otherwise.
*/
public function execute($name, CommandContext $context)
{
$result = null;
$identifier = clone $context->getSubject()->getIdentifier();
$type = array_pop($identifier->path);
$parts = explode('.', $name);
$method = '_' . $parts[0] . ucfirst($type) . ucfirst($parts[1]);
//If the method exists call the method and return the result
if (method_exists($this, $method)) {
$result = $this->{$method}($context);
}
return $result;
}