/** * @dataProvider splitProvider */ public function testSplit($input, $output, $base) { if ($base != null) { $result = URLHelper::split($input, $base) == $output; } else { $result = URLHelper::split($input) == $output; } $this->assertTrue($result); }
/** * Request constructor. * * Parses the URL producing a request. $url parameter must only be used for debugging purposes. * Only alphanumeric characters and dash "-" are accepted as valid values. For parameters * underscores "_" and full stops "." are allowed. * * @param string $url * @since 0.0.9 Extracted addBaseParameter() * @since 0.0.6 Refactored url parsing, regex now allows more symbols for parameters * @since 0.0.4 Now properly converts lisp-case to PascalCase * @since 0.0.3 Added query support * @since 0.0.2 Added $url parameter * @since 0.0.1 */ public function __construct($url = null) { $this->url = $url ?: "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $this->stripped_url = URLHelper::stripBase($this->url); $query = explode('?', $this->url); $this->query = count($query) > 1 ? $query[1] : null; $this->url_parts = URLHelper::split($query[0]); for ($i = 0; $i < count($this->url_parts); $i++) { $url_part = $this->url_parts[$i]; if ($i < 2) { if (preg_match('/^[A-Za-z0-9\\-]+$/', $url_part) === 1) { $this->addBaseParameter($i, $url_part); } else { $this->valid = false; break; } } else { if (preg_match('/^[A-Za-z0-9\\-\\.\\_]+$/', $url_part) === 1) { array_push($this->parameters, $url_part); } else { $this->valid = false; break; } } } if (empty($this->controller) && $this->valid) { $this->index = true; } }