orbit/src/Orbit/Request.php
2020-09-06 02:32:56 -05:00

61 lines
1.4 KiB
PHP

<?php declare(strict_types=1);
namespace Orbit;
/**
* Request
*
* @package Orbit
*/
class Request
{
public $url = '';
public $scheme;
public $host;
public $port;
public $user;
public $pass;
public $path;
public $query;
public $fragment;
/**
* Construct a request object
*
* @param string $request_input Gemini request line (URL)
* @return void
*/
public function __construct(string $request_input)
{
$this->url = trim($request_input);
$data = parse_url($this->url);
foreach ($data as $key => $value) {
$this->{$key} = urldecode((string) $value);
}
// If scheme is missing, infer as default scheme
if (!$this->scheme) {
$this->scheme = Server::SCHEME;
}
}
/**
* Get a new URL with some text appended to the path
*
* @return string New URL
*/
public function getUrlAppendPath(string $text): string
{
return $this->scheme . '://'
. ($this->user ? $this->user : '')
. ($this->pass ? ':' . $this->pass : '')
. ($this->user ? '@' : '')
. $this->host
. ($this->port ? ':' . $this->port : '')
. $this->path . $text
. ($this->query ? '?' . $this->query : '')
. ($this->fragment ? '#' . $this->fragment : '');
}
}