function getCommand(Request $req) { $previous = $req->getLastCommand(); if (is_null($previous)) { $cmd = $req->getProperty('cmd'); if (is_null($cmd)) { $req->setProperty('cmd', 'default'); return self::$default_cmd; } } else { $cmd = $this->getForward($req); if (is_null($cmd)) { return null; } } $cmd_obj = $this->resolveCommand($cmd); if (is_null($cmd_obj)) { throw new core\AppException("couldn't resolve '{$cmd}'"); } $cmd_class = get_class($cmd_obj); if (isset($this->invoked[$cmd_class])) { throw new core\AppException("circular forwarding"); } $this->invoked[$cmd_class] = 1; return $cmd_obj; }