Gemini Protocol library for PHP 8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.3 KiB

<?php
namespace Yggverse\TitanII;
/**
* Gemini Request
*/
class Request {
/**
* Maximum length in bytes of the URL request.
*/
const MAX_LENGTH = 1024;
/**
* URL string.
*
* @var string
*/
private string $url;
/**
* @param string Incoming URL request.
*/
public function __construct(string $url)
{
$this->url = trim(substr($url, 0, self::MAX_LENGTH));
}
/**
* Magic method.
*/
public function __toString(): string
{
return $this->url;
}
/**
* Get the Hostname.
*
* @return string|null
*/
public function getHost(): ?string
{
return parse_url($this->url, PHP_URL_HOST);
}
/**
* Get the Path.
*
* @return string|null
*/
public function getPath(): ?string
{
return parse_url($this->url, PHP_URL_PATH);
}
/**
* Get the path, but as an array.
*
* @return array
*/
public function tokenizePath(): array
{
$path = trim(trim($this->getPath()), '/');
return explode('/', $path);
}
/**
* Get the Query.
*
* @return string|null
*/
public function getQuery(): ?string
{
return parse_url($this->url, PHP_URL_QUERY);
}
}