e
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
use HttpServer\Http\HttpHeaders;
|
||||
use HttpServer\Http\HttpParams;
|
||||
use HttpServer\Http\Request;
|
||||
use Exception;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class WebController
|
||||
* @package BeReborn\Web
|
||||
*/
|
||||
class Controller extends Application
|
||||
{
|
||||
|
||||
/** @var HttpParams $input */
|
||||
protected $input;
|
||||
|
||||
|
||||
/** @var HttpHeaders */
|
||||
protected $headers;
|
||||
|
||||
|
||||
/** @var Request */
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @param HttpParams $input
|
||||
*/
|
||||
public function setInput(HttpParams $input): void
|
||||
{
|
||||
$this->input = $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HttpHeaders $headers
|
||||
*/
|
||||
public function setHeaders(HttpHeaders $headers): void
|
||||
{
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
public function setRequest(Request $request): void
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpParams
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getInput(): HttpParams
|
||||
{
|
||||
if (!$this->input) {
|
||||
$this->input = $this->getRequest()->params;
|
||||
}
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpHeaders
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getHeaders(): HttpHeaders
|
||||
{
|
||||
if (!$this->headers) {
|
||||
$this->headers = $this->getRequest()->headers;
|
||||
}
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRequest(): Request
|
||||
{
|
||||
if (!$this->request) {
|
||||
$this->request = Snowflake::get()->request;
|
||||
}
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$method = 'get' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user