Extends
lithium\core\Object
Compiles URL templates into regular expression patterns for matching against request URLs,
and extracts template parameters into match-parameter arrays.
Returns
voidSource
public function compile() {
$this->_match = $this->_params;
foreach ($this->_params as $key => $value) {
if (!strpos($key, ':')) {
continue;
}
unset($this->_params[$key]);
$this->_meta[$key] = $value;
}
if ($this->_template === '/' || $this->_template === '') {
$this->_pattern = '@^/*$@';
return;
}
$this->_pattern = "@^{$this->_template}\$@";
$match = '@([/.])?\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
preg_match_all($match, $this->_pattern, $m);
if (!$tokens = $m[0]) {
return;
}
$slashes = $m[1];
$params = $m[2];
$regexs = $m[3];
unset($m);
$this->_keys = array();
foreach ($params as $i => $param) {
$this->_keys[$param] = $param;
$this->_pattern = $this->_regex($regexs[$i], $param, $tokens[$i], $slashes[$i]);
}
$this->_defaults = array_intersect_key($this->_params, $this->_keys);
$this->_match = array_diff_key($this->_params, $this->_defaults);
}