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('*****@*****.**', $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']); } }
/** * _getShell * * @param string $plugin * * @return mixed */ protected function _getShell($shell) { if (isset($this->TestShell)) { return $this->TestShell; } return parent::_getShell($shell); }
/** * Outputs usage text on the standard output. Implement it in subclasses. * * @access public */ function help() { if ($this->command != null) { $this->err("Unknown {$this->name} command '{$this->command}'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); } else { $this->Dispatch->help(); } }
/** * Displays detailed help about a HeavyMetal shell command. * * @usage ./metal help your/command/uri * @param $uri The URI of the shell command to display help about. */ public function index($uri) { try { try { $s = new ShellDispatcher($uri); $f = $s->find(); } catch (Exception $ex) { $s = new SysShellDispatcher($uri); $f = $s->find(); } } catch (Exception $ex) { vomit($ex->getTrace()); echo "Could not find a suitable controller for {$uri} - are you sure you got it right?"; } $method = new ReflectionMethod($f['classname'], $f['found_action']); $help = $method->getDocComment(); $help = explode("\n", $help); $description = ''; $switches = array(); $params = array(); $usage = ''; foreach ($help as $line) { if (strpos(trim($line, "\t \n"), '/**') === FALSE && strpos(trim($line, "\t \n"), '*/') === FALSE) { $line = trim($line, "\t* "); if (strpos($line, '@') === FALSE) { $description .= $line; } else { if (strpos($line, '@usage') === 0) { $usage = substr($line, 6); } else { $matches = array(); preg_match_all('#([@a-z0-9]*) ([$a-z0-9]*) (.*)#', $line, $matches); switch ($matches[1][0]) { case '@switch': $switches[$matches[2][0]] = $matches[3][0]; break; case '@param': $params[trim($matches[2][0], '$')] = $matches[3][0]; break; } } } } } return array('description' => $description, 'usage' => $usage, 'switches' => $switches, 'params' => $params); }
/** * Outputs usage text on the standard output. Implement it in subclasses. * * @access public */ function help() { if ($this->command != null) { $this->err("Unknown {$this->name} command `{$this->command}`."); $this->err("For usage, try `cake {$this->shell} help`.", 2); } else { $this->Dispatch->help(); } }
/** * Constructor * * @param $path * @param $controller_root * @param $view_root * @param $use_routes * @param $force_routes */ public function __construct($path = null, $controller_root = null, $view_root = null, $use_routes = true, $force_routes = false) { $args = parse_args(); $switches = parse_switches(); $path = $path ? $path : $args[0]; array_shift($args); $controller_root = $controller_root ? $controller_root : PATH_SYS . 'shell/controller/'; $view_root = $view_root ? $view_root : PATH_SYS . 'shell/view/'; $this->segments = $args; parent::__construct($path, $controller_root, $view_root, $use_routes, $force_routes); }
#!/usr/bin/php -q <?php /** * Command-line code generation utility to automate programmer chores. * * PHP 5 * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright 2005-2012, Cake Software Foundation, Inc. * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package app.Console * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ $ds = DIRECTORY_SEPARATOR; $dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php'; if (function_exists('ini_set')) { $root = dirname(dirname(dirname(__FILE__))); ini_set('include_path', $root . PATH_SEPARATOR . 'C:' . $ds . 'webroot' . $ds . 'cakephp' . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path')); } if (!(include $dispatcher)) { trigger_error('Could not locate CakePHP core files.', E_USER_ERROR); } unset($paths, $path, $dispatcher, $root, $ds); return ShellDispatcher::run($argv);
/** * 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); }
/** * 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(); }
/** * _getShell * * @param mixed $plugin * @return mixed * @access protected */ function _getShell($plugin = null) { if (isset($this->TestShell)) { return $this->TestShell; } return parent::_getShell($plugin); }
/** * 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); }
#!/usr/bin/php -q <?php $ds = DIRECTORY_SEPARATOR; require_once dirname(dirname(dirname(__FILE__))) . $ds . 'vendor' . $ds . 'autoload.php'; // start profiling xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); register_shutdown_function('saveXhprof'); $result = ShellDispatcher::run($argv); function saveXhprof() { global $argv; $_SERVER['REQUEST_URI'] = implode(' ', $argv); // stop profiler $xhprof_data = xhprof_disable(); $xhprofConfig = Configure::read('Environment.xhprof'); include_once $xhprofConfig['utils'] . "xhprof_lib.php"; include_once $xhprofConfig['utils'] . "xhprof_runs.php"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default($xhprofConfig['storage']); // save the run under a namespace "xhprof_foo" $runId = $xhprof_runs->save_run($xhprof_data, $xhprofConfig['tag']); echo "\n{$xhprofConfig['host']}?run={$runId}&source={$xhprofConfig['tag']}\n"; }