/** * Processes a request and sets its controller and action. If * no route was possible, an exception is thrown. * * @param \Zend_Controller_Request_Abstract * @throws \Zend_Controller_Router_Exception * @return \Zend_Controller_Request_Abstract|boolean */ public function route(\Zend_Controller_Request_Abstract $request) { $options = array('help|h' => 'Show this help', 'org|o=i' => 'The user organization number', 'pwd|p=s' => 'User password', 'user|u=s' => 'The user name'); $getopt = new \Zend_Console_Getopt($options); try { $getopt->parse(); } catch (\Zend_Console_Getopt_Exception $e) { echo $this->_expandMessage($e); exit; } if ($getopt->getOption('h')) { // $getopt->s echo $this->_expandMessage($getopt); exit; } if ($request instanceof \MUtil_Controller_Request_Cli) { $request->setUserLogin($getopt->getOption('u'), $getopt->getOption('o'), $getopt->getOption('p')); } $arguments = $getopt->getRemainingArgs(); if ($arguments) { $controller = array_shift($arguments); $action = array_shift($arguments); if (!$action) { $action = 'index'; } if (preg_match('/^\\w+(-\\w+)*$/', $controller) && preg_match('/^\\w+(-\\w+)*$/', $action)) { $request->setControllerName($controller); $request->setActionName($action); $params[$request->getControllerKey()] = $controller; $params[$request->getActionKey()] = $action; foreach ($arguments as $arg) { if (\MUtil_String::contains($arg, '=')) { list($name, $value) = explode('=', $arg, 2); } else { $name = $arg; $value = ''; } $params[$name] = $value; } $request->setParams($params); return $request; } echo "Invalid command: {$controller}/{$action}.\n", exit; } echo "No command given.\n\n"; echo $this->_expandMessage($getopt), exit; }