/** * Does the heavy lifting of creating an actual route. You must specify * the request method(s) that this route will work for. They can be separated * by a pipe character "|" if there is more than one. * * @param string $from * @param array $to * * @return array The built route. */ private static function createRoute($from, $to, $options = array(), $nested = false) { $prefix = is_null(self::$prefix) ? '' : self::$prefix . '/'; $from = self::$nested_prefix . $prefix . $from; // Are we saving the name for this one? if (isset($options['as']) && !empty($options['as'])) { self::$named_routes[$options['as']] = $from; } self::$routes[$from] = $to; // Do we have a nested function? if ($nested && is_callable($nested) && self::$nested_depth === 0) { self::$nested_prefix .= rtrim($from, '/') . '/'; self::$nested_depth += 1; call_user_func($nested); self::$nested_prefix = ''; } // Reset our prefix. if ($nested_depth) { self::$nested_prefix = ''; } else { self::$nested_depth = self::$nested_depth === 0 ? self::$nested_depth : self::$nested_depth - 1; } }