/** * call an handler to parse the url. * * @return \jUrlAction or null if the handler does not accept the url */ protected function parseWithHandler($infoparsing, \jUrl $url) { list($module, $action, $reg, $selectorHandler, $secondariesActions, $needsHttps) = $infoparsing; if ($reg != '') { // if the path info match the regexp, we have the right handler if (preg_match($reg, $url->pathInfo, $m)) { $url->pathInfo = isset($m[1]) ? $m[1] : '/'; } else { return; } } // load the handler $s = new SelectorUrlHandler($selectorHandler); include_once $s->getPath(); $c = $s->className . 'UrlsHandler'; $handler = new $c(); $params = $url->params; $url->params['module'] = $module; // if the action parameter exists in the current url // and if it is one of secondaries actions, then we keep it // else we take the action indicated in the url mapping if ($secondariesActions && isset($params['action'])) { if (strpos($params['action'], ':') === false) { $params['action'] = 'default:' . $params['action']; } if (in_array($params['action'], $secondariesActions)) { // there is a secondary action in parameters, let's use it. $url->params['action'] = $params['action']; } else { $url->params['action'] = $action; } } else { $url->params['action'] = $action; } // call the url handler $urlact = $handler->parse($url); $urlact->needsHttps = $needsHttps; return $urlact; }
/** * @param UrlMapData $u * @param SimpleXmlElement $url */ protected function newHandler(UrlMapData $u, \SimpleXmlElement $url, $rootPathInfo = '/') { $class = (string) $url['handler']; // we must have a module name in the selector, because, during the parsing of // the url in the request process, we are not still in a module context $p = strpos($class, '~'); if ($p === false) { $selclass = $u->module . '~' . $class; } elseif ($p == 0) { $selclass = $u->module . $class; } else { $selclass = $class; } $s = new SelectorUrlHandler($selclass); if (!isset($url['action'])) { $u->action = '*'; } $this->checkStaticPathInfo($url); $pathinfo = $this->getFinalPathInfo($url, $rootPathInfo); if ($pathinfo != '/') { $regexp = '!^' . preg_quote($pathinfo, '!') . '(/.*)?$!'; } else { if ($u->isDefault) { if ($this->parseInfos[0]['startModule'] != '') { throw new MapParserException($this->getErrorMsg($url, 'There is already a default url for this entrypoint')); } if ($u->action == '*') { throw new MapParserException($this->getErrorMsg($url, '"default" attribute is not allowed on url handler without specific action')); } $this->parseInfos[0]['startModule'] = $u->module; $this->parseInfos[0]['startAction'] = $u->action; } $regexp = ''; } $this->createUrlContentInc .= "include_once('" . $s->getPath() . "');\n"; $this->parseInfos[] = array($u->module, $u->action, $regexp, $selclass, $u->actionOverride, $u->isHttps); $this->createUrlInfos[$u->getFullSel()] = array(0, $u->entryPointUrl, $u->isHttps, $selclass, $pathinfo); if ($u->actionOverride) { foreach ($u->actionOverride as $ao) { $u->action = $ao; $this->createUrlInfos[$u->getFullSel()] = array(0, $u->entryPointUrl, $u->isHttps, $selclass, $pathinfo); } } }