/** * Parses a URL based on this rule. * * @param CUrlManager $manager the URL manager * @param CHttpRequest $request the request object * @param string $pathInfo path info part of the URL (URL suffix is already removed based on {@link CUrlManager::urlSuffix}) * @param string $rawPathInfo path info that contains the potential URL suffix * * @return mixed the route that consists of the controller ID and action ID. False if this rule does not apply. */ public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { $params = array(); $segments = array(); if (preg_match('/\\.([\\w|-]+)$/', $pathInfo, $matches)) { $params['urlSuffix'] = $matches[1]; $pathInfo = mb_substr($pathInfo, 0, -strlen($matches[0])); } $parts = explode('/', $pathInfo); $partCount = count($parts); if (!$partCount) { return false; } $module = \Yii::app(); /* @var Application $module */ $controllerID = null; $actionID = null; $expectModule = true; $expectController = true; $expectId = false; $expectAction = false; $expectRelation = false; $expectRelationId = false; $expectRelationAction = false; while ($part = array_shift($parts)) { if ($this->useDashes) { $p = String::dashesToCamelCase($part); } else { $p = $part; } if ($expectModule) { if ($module->hasModule($p)) { $segments[] = $p; $module = $module->getModule($p); continue; } else { $expectModule = false; } } if ($expectController) { $expectController = false; $expectModule = false; if (!is_numeric($p) && preg_match('/^(\\w+)$/', $p)) { $controllerID = $p; $expectAction = true; $expectId = true; continue; } } if ($expectAction && $p[0] == '_') { $expectAction = false; $actionID = substr($p, 1); continue; } if ($expectRelationAction && $p[0] == '_') { $expectRelationAction = false; $expectRelationId = false; $actionID = substr($p, 1) . 'Related'; continue; } if ($expectRelation) { $expectRelation = false; if (preg_match('/^(\\w+)$/', $p)) { $params['relation'] = $p; $expectRelationAction = true; continue; } } if ($expectId) { $params[$this->idName] = $part; $expectId = false; $expectAction = true; $expectRelation = true; continue; } if ($expectRelationId) { $params[$this->relationIdName] = $part; $expectRelationId = false; continue; } return false; } if ($controllerID === null) { $controllerID = $module->defaultController; } if ($actionID === null) { $requestType = $request->getRequestType(); if (isset($params['relation'])) { if (isset($params[$this->relationIdName])) { $actionID = isset($this->itemVerbMap[$requestType]) ? $this->itemVerbMap[$requestType] . 'Related' : $this->defaultItemAction . 'Related'; } else { $actionID = isset($this->collectionVerbMap[$requestType]) ? $this->collectionVerbMap[$requestType] . 'Related' : $this->defaultCollectionAction . 'Related'; } } else { if (isset($params[$this->idName])) { $actionID = isset($this->itemVerbMap[$requestType]) ? $this->itemVerbMap[$requestType] : $this->defaultItemAction; } else { $actionID = isset($this->collectionVerbMap[$requestType]) ? $this->collectionVerbMap[$requestType] : $this->defaultCollectionAction; } } } $segments[] = $controllerID; $segments[] = $actionID; foreach ($params as $key => $value) { $_GET[$key] = $value; } return implode('/', $segments); }