本文整理汇总了PHP中ShellDispatcher::dispatch方法的典型用法代码示例。如果您正苦于以下问题:PHP ShellDispatcher::dispatch方法的具体用法?PHP ShellDispatcher::dispatch怎么用?PHP ShellDispatcher::dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShellDispatcher
的用法示例。
在下文中一共展示了ShellDispatcher::dispatch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ShellDispatcher
function process_message($msg)
{
$msg_body = json_decode($msg->body, true);
if (isset($msg_body['params']) && is_array($msg_body['params'])) {
$msg_body['params'] = json_encode($msg_body['params']);
}
$msg_body = array_values($msg_body);
$dispatcher = new ShellDispatcher($msg_body, false);
try {
$dispatcher->dispatch();
} catch (Exception $e) {
RabbitMQ::publish(json_decode($msg->body, true), ['exchange' => 'requeueable', 'queue' => 'requeueable_messages']);
$newMessage[] = $msg->body;
$newMessage[] = '==>';
$newMessage[] = $e->getMessage();
$newMessage[] = $e->getFile();
$newMessage[] = $e->getLine();
$newMessage[] = $e->getTraceAsString();
$newMessage[] = $e->getCode();
$newMessage[] = $e->getPrevious();
RabbitMQ::publish($newMessage, ['exchange' => 'unprocessed', 'queue' => 'unprocessed_messages']);
EmailSender::sendEmail('elisio.leonardo@gmail.com', $msg->body, $newMessage);
}
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
// Send a message with the string "quit" to cancel the consumer.
if ($msg->body === 'quit') {
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
}
}
示例2: run
/**
* Run the dispatcher
*
* @param array $argv The argv from PHP
* @return void
*/
public static function run($argv) {
$dispatcher = new ShellDispatcher($argv);
$dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0);
}
示例3: dispatchShell
/**
* Dispatch a command to another Shell. Similar to Object::requestAction()
* but intended for running shells from other shells.
*
* ### Usage:
*
* With a string command:
*
* `return $this->dispatchShell('schema create DbAcl');`
*
* Avoid using this form if you have string arguments, with spaces in them.
* The dispatched will be invoked incorrectly. Only use this form for simple
* command dispatching.
*
* With an array command:
*
* `return $this->dispatchShell('schema', 'create', 'i18n', '--dry');`
*
* @return mixed The return of the other shell.
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::dispatchShell
*/
public function dispatchShell()
{
$args = func_get_args();
if (is_string($args[0]) && count($args) === 1) {
$args = explode(' ', $args[0]);
}
$Dispatcher = new ShellDispatcher($args, false);
return $Dispatcher->dispatch();
}
示例4: run
/**
* Run the dispatcher
*
* @param array $argv The argv from PHP
*
* @return void
*/
public static function run($argv)
{
$dispatcher = new ShellDispatcher($argv);
return $dispatcher->_stop($dispatcher->dispatch() === FALSE ? 1 : 0);
}