/** * Compile path to regular expression * * @return $this */ protected function compileRegExp() { $exp = str_replace(array('(', ')'), array('(', ')?'), $this->content); foreach ($this->route->getParams() as $name => $config) { $class = isset($config['regExp']) ? $config['regExp'] : self::PARAM; $exp = str_replace('{' . $name . '}', '(' . $class . ')', $exp); } $exp = ':^' . $exp . '$:u'; $this->regExp = $exp; return $this; }
/** * Find route segment that could have specified parameters * * @param Route $route Route * @param array $params Route parameters * * @return Template * @throws \InvalidArgumentException */ protected function getSegment(Route $route, array $params) { $segments = $route->getPath()->getSegments(); foreach ($segments as $segment) { $diff = array_diff_key($segment->getParams(), $params); if (empty($diff)) { return $segment; } } throw new \InvalidArgumentException(sprintf("Route '%s' does not have any segment that match specified parameters: '%s' (invalid parameter count).", $route->getName(), implode(', ', array_keys($params)))); }
/** * Get control method name basing on current route * * @return string */ protected function getControlMethod() { $method = lcfirst($this->route->getAction()) . 'Action'; return $method; }