/** * Checks to see if the given URL can be parsed by this route. * If the route can be parsed an array of parameters will be returned if not * false will be returned. String urls are parsed if they match a routes regular expression. * * @param string $url The url to attempt to parse. * @return mixed Boolean false on failure, otherwise an array or parameters * @access public */ public function parse($url) { $params = parent::parse($url); if (empty($params)) { return false; } if (isset($this->options['models']) && isset($params['_args_'])) { $index = -1; foreach ($this->options['models'] as $checkNamed => $slugField) { $index++; if (is_numeric($checkNamed)) { $checkNamed = $slugField; $slugField = null; } $slugSet = $this->_Sluggable->getSlugs($checkNamed, $slugField); if ($slugSet === false) { continue; } $slugSet = array_flip($slugSet); $passed = explode('/', $params['_args_']); foreach ($passed as $key => $pass) { if (isset($slugSet[$pass])) { unset($passed[$key]); $passed[$index] = $slugSet[$pass]; } } $params['_args_'] = implode('/', $passed); } return $params; } return false; }
/** * Parses a string url into an array. If a plugin key is found, it will be copied to the * controller parameter * * @param string $url The url to parse * @return mixed false on failure, or an array of request parameters */ public function parse($url) { $params = parent::parse($url); if (!$params) { return false; } $params['controller'] = $params['plugin']; return $params; }