src/Router/UrlGenerator.php
protected function compile($name) {
		if (!isset($this->raw[$name])) {
			return;
		}

		$count = preg_match_all(
			self::ROUTE_PARAM_PATTERN,
			$this->raw[$name],
			$matches,
			PREG_OFFSET_CAPTURE
		);

		if ($count === 0) {
			$this->compiled[$name] = $this->raw[$name];
		} else if ($count > 0) {
			$routePath = $this->raw[$name];
			$params = [];
			$chunks = [];
			$pos = 0;
			for ($i = 0; $i < $count; $i++) {
				$chunks[] = substr($routePath, $pos, $matches[1][$i][1] - $pos);
				$size = array_push($chunks, ''); // Empty string is just a placeholder, it can be anything
				$params[$matches[2][$i][0]] = $size - 1; // Set index
				$pos = $matches[1][$i][1] + strlen($matches[1][$i][0]);
			}
			$chunks[] = substr($routePath, $pos);
			$this->compiled[$name] = [
				'params' => $params,
				'chunks' => $chunks,
			];
		}
	}
protected function compile($name) {
		if (!isset($this->raw[$name])) {
			return;
		}

		$count = preg_match_all(
			self::ROUTE_PARAM_PATTERN,
			$this->raw[$name],
			$matches,
			PREG_OFFSET_CAPTURE
		);

		if ($count === 0) {
			$this->compiled[$name] = $this->raw[$name];
		} else if ($count > 0) {
			$routePath = $this->raw[$name];
			$params = [];
			$chunks = [];
			$pos = 0;
			for ($i = 0; $i < $count; $i++) {
				$chunks[] = substr($routePath, $pos, $matches[1][$i][1] - $pos);
				$size = array_push($chunks, ''); // Empty string is just a placeholder, it can be anything
				$params[$matches[2][$i][0]] = $size - 1; // Set index
				$pos = $matches[1][$i][1] + strlen($matches[1][$i][0]);
			}
			$chunks[] = substr($routePath, $pos);
			$this->compiled[$name] = [
				'params' => $params,
				'chunks' => $chunks,
			];
		}
	}
protected function compile ( $ name ) { if ( ! isset ( $ this -> raw [ $ name ] ) ) { return ; } $ count = preg_match_all ( self :: ROUTE_PARAM_PATTERN , $ this -> raw [ $ name ] , $ matches , PREG_OFFSET_CAPTURE ) ; if ( $ count === 0 ) { $ this -> compiled [ $ name ] = $ this -> raw [ $ name ] ; } else if ( $ count > 0 ) { $ routePath = $ this -> raw [ $ name ] ; $ params = [ ] ; $ chunks = [ ] ; $ pos = 0 ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ chunks [ ] = substr ( $ routePath , $ pos , $ matches [ 1 ] [ $ i ] [ 1 ] - $ pos ) ; $ size = array_push ( $ chunks , '' ) ; // Empty string is just a placeholder, it can be anything $ params [ $ matches [ 2 ] [ $ i ] [ 0 ] ] = $ size - 1 ; // Set index $ pos = $ matches [ 1 ] [ $ i ] [ 1 ] + strlen ( $ matches [ 1 ] [ $ i ] [ 0 ] ) ; } $ chunks [ ] = substr ( $ routePath , $ pos ) ; $ this -> compiled [ $ name ] = [ 'params' => $ params , 'chunks' => $ chunks , ] ; } }
Compile raw route to a format for generation.

@param string $name
Compile raw route to a format for generation .