48 lines
1.0 KiB
PHP
48 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Khofmann\Request;
|
|
|
|
use Pecee\Http\Request as PRequest;
|
|
use Pecee\SimpleRouter\SimpleRouter;
|
|
|
|
/**
|
|
* Facade for Request access (wraps SimpleRouter)
|
|
*/
|
|
class Request
|
|
{
|
|
/**
|
|
* Private since facade.
|
|
*/
|
|
private function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Get current request
|
|
*/
|
|
public static function request(): PRequest
|
|
{
|
|
return SimpleRouter::request();
|
|
}
|
|
|
|
/**
|
|
* Get header value from current request
|
|
*
|
|
* @param string $name Field name
|
|
* @param mixed $defaultValue Default value if header field was null
|
|
* @param bool $tryParse When enabled the method will try to find the header from both from client (http) and server-side variants, if the header is not found.
|
|
*/
|
|
public static function header(string $name, $defaultValue = null, bool $tryParse = true): ?string
|
|
{
|
|
return Request::request()->getHeader($name, $defaultValue, $tryParse);
|
|
}
|
|
|
|
/**
|
|
* Get authentication header field
|
|
*/
|
|
public static function token()
|
|
{
|
|
return Request::header("token");
|
|
}
|
|
}
|