/** * Tries to resolve a route string. If it matches one of the connected routes * (the firt one) the request object is updated with all neccessary parameters * and the method returns TRUE. * * If no route can be matched, the method returns FALSE * * @param string $routeString The requested route as string * @return boolean The result */ public function resolveRouteString($routeString) { if (empty($routeString)) { return false; } foreach ($this->routes as $route) { $matches = array(); $res = preg_match_all($route->getPattern(), '/' . $routeString, $matches); $verbs = $route->getVerbs(); if ($res !== false && $res > 0 && (empty($verbs) || in_array($this->request->getMethod(), $verbs))) { $this->request->addParameter('resource', $route->getResource()); $this->request->addParameter('action', $route->getAction()); $this->request->addParameter('cmd', $route->getCommandName()); $parameters = $route->getParameters(); for ($i = 1; $len = count($parameters), $i <= $len; $i++) { $this->request->addParameter($parameters[$i - 1], $matches[$i][0]); } return true; } } return false; }
public function getControllerClassName(Sonata_Request $request) { $resource = $request->getParameter('resource'); if (!$resource) { return null; } return ucfirst(Sonata_Utils::camelize($resource)) . 'Controller'; }