1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00
Daniel Neto 2024-03-05 19:22:51 -03:00
parent 7673eda07e
commit 330cdbe615
9054 changed files with 480487 additions and 41800 deletions

View file

@ -23,15 +23,15 @@ use Symfony\Component\HttpFoundation\Request;
*/
class RequestContext
{
private $baseUrl;
private $pathInfo;
private $method;
private $host;
private $scheme;
private $httpPort;
private $httpsPort;
private $queryString;
private $parameters = [];
private string $baseUrl;
private string $pathInfo;
private string $method;
private string $host;
private string $scheme;
private int $httpPort;
private int $httpsPort;
private string $queryString;
private array $parameters = [];
public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '')
{
@ -67,7 +67,7 @@ class RequestContext
*
* @return $this
*/
public function fromRequest(Request $request)
public function fromRequest(Request $request): static
{
$this->setBaseUrl($request->getBaseUrl());
$this->setPathInfo($request->getPathInfo());
@ -83,10 +83,8 @@ class RequestContext
/**
* Gets the base URL.
*
* @return string
*/
public function getBaseUrl()
public function getBaseUrl(): string
{
return $this->baseUrl;
}
@ -96,7 +94,7 @@ class RequestContext
*
* @return $this
*/
public function setBaseUrl(string $baseUrl)
public function setBaseUrl(string $baseUrl): static
{
$this->baseUrl = rtrim($baseUrl, '/');
@ -105,10 +103,8 @@ class RequestContext
/**
* Gets the path info.
*
* @return string
*/
public function getPathInfo()
public function getPathInfo(): string
{
return $this->pathInfo;
}
@ -118,7 +114,7 @@ class RequestContext
*
* @return $this
*/
public function setPathInfo(string $pathInfo)
public function setPathInfo(string $pathInfo): static
{
$this->pathInfo = $pathInfo;
@ -129,10 +125,8 @@ class RequestContext
* Gets the HTTP method.
*
* The method is always an uppercased string.
*
* @return string
*/
public function getMethod()
public function getMethod(): string
{
return $this->method;
}
@ -142,7 +136,7 @@ class RequestContext
*
* @return $this
*/
public function setMethod(string $method)
public function setMethod(string $method): static
{
$this->method = strtoupper($method);
@ -153,10 +147,8 @@ class RequestContext
* Gets the HTTP host.
*
* The host is always lowercased because it must be treated case-insensitive.
*
* @return string
*/
public function getHost()
public function getHost(): string
{
return $this->host;
}
@ -166,7 +158,7 @@ class RequestContext
*
* @return $this
*/
public function setHost(string $host)
public function setHost(string $host): static
{
$this->host = strtolower($host);
@ -175,10 +167,8 @@ class RequestContext
/**
* Gets the HTTP scheme.
*
* @return string
*/
public function getScheme()
public function getScheme(): string
{
return $this->scheme;
}
@ -188,7 +178,7 @@ class RequestContext
*
* @return $this
*/
public function setScheme(string $scheme)
public function setScheme(string $scheme): static
{
$this->scheme = strtolower($scheme);
@ -197,10 +187,8 @@ class RequestContext
/**
* Gets the HTTP port.
*
* @return int
*/
public function getHttpPort()
public function getHttpPort(): int
{
return $this->httpPort;
}
@ -210,7 +198,7 @@ class RequestContext
*
* @return $this
*/
public function setHttpPort(int $httpPort)
public function setHttpPort(int $httpPort): static
{
$this->httpPort = $httpPort;
@ -219,10 +207,8 @@ class RequestContext
/**
* Gets the HTTPS port.
*
* @return int
*/
public function getHttpsPort()
public function getHttpsPort(): int
{
return $this->httpsPort;
}
@ -232,7 +218,7 @@ class RequestContext
*
* @return $this
*/
public function setHttpsPort(int $httpsPort)
public function setHttpsPort(int $httpsPort): static
{
$this->httpsPort = $httpsPort;
@ -241,10 +227,8 @@ class RequestContext
/**
* Gets the query string without the "?".
*
* @return string
*/
public function getQueryString()
public function getQueryString(): string
{
return $this->queryString;
}
@ -254,7 +238,7 @@ class RequestContext
*
* @return $this
*/
public function setQueryString(?string $queryString)
public function setQueryString(?string $queryString): static
{
// string cast to be fault-tolerant, accepting null
$this->queryString = (string) $queryString;
@ -264,10 +248,8 @@ class RequestContext
/**
* Returns the parameters.
*
* @return array
*/
public function getParameters()
public function getParameters(): array
{
return $this->parameters;
}
@ -279,7 +261,7 @@ class RequestContext
*
* @return $this
*/
public function setParameters(array $parameters)
public function setParameters(array $parameters): static
{
$this->parameters = $parameters;
@ -288,20 +270,16 @@ class RequestContext
/**
* Gets a parameter value.
*
* @return mixed
*/
public function getParameter(string $name)
public function getParameter(string $name): mixed
{
return $this->parameters[$name] ?? null;
}
/**
* Checks if a parameter value is set for the given parameter.
*
* @return bool
*/
public function hasParameter(string $name)
public function hasParameter(string $name): bool
{
return \array_key_exists($name, $this->parameters);
}
@ -309,11 +287,9 @@ class RequestContext
/**
* Sets a parameter value.
*
* @param mixed $parameter The parameter value
*
* @return $this
*/
public function setParameter(string $name, $parameter)
public function setParameter(string $name, mixed $parameter): static
{
$this->parameters[$name] = $parameter;