/** * This action will decide what controllers will be called and in which order * * Note: this can change the expected dispatch behaviour! * * @param $request * @return void */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { //Check if the module is registered for HMVC if (!$this->isActiveModule($request->getModuleName())) { return; } //For some reason, unknown to me at this time, Zend_Controller_Request has lost all relevant info. //Rebuild it from scratch. $params = explode('/', trim($request->getPathInfo(), '/')); if ($params[0] === $request->getModuleName()) { //Unset the module if the same, not needed further unset($params[0]); } $action = $request->getActionName(); $module = $request->getModuleName(); //Clear all params as new ones are on the way $request->clearParams(); //Filter strings only $names = array_filter($params, 'ctype_alpha'); //Filter digits only $ids = array_filter($params, 'ctype_digit'); if (0 === count($names) && 0 === count($ids)) { //We have nothing here to work with.. Assume default actions take over return; } $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher(); //Set some default params $request->setParam('collection', false)->setParam('resource', true)->setParam('passthrough', true); if (count($names) !== count($ids)) { $ids = array_pad($ids, count($names), null); $request->setParam('collection', true)->setParam('resource', false); //Possible fix for crappy Zend_Rest_Route as the action is set to index //Example: /rest/car should point to Hmvc/Controller/Car/"METHOD" to get a collection if (!in_array($action, array('get', 'put', 'post', 'delete'))) { $action = strtolower($request->getMethod()); } } //Combine all data $params = array_combine($names, $ids); $params['module'] = $module; $params['action'] = $action; $params['controller'] = $dispatcher->formatModuleName(current($names)); //Register with the request so the controllers can work with them $request->setModuleName($module)->setActionName($action)->setParams($params); $delimiter = $dispatcher->getPathDelimiter(); if (!Glitch_Registry::getConfig()->resources->hmvc->redispatch) { $controller = $dispatcher->formatModuleName(implode($delimiter, $names)); $request->setControllerName($controller)->setParam('controller', $controller)->setDispatched(false)->setParam('passthrough', false); return; } $nextController = ''; foreach ($names as $controller) { //Collect the new controller string $nextController .= $delimiter . $controller; //Modify so it fits our structure and append to the controllers we want to handle //We use formatModuleName as we already figured out our own structure $this->_controllers[] = $dispatcher->formatModuleName(trim($nextController, $delimiter)); } }