2020-08-31 01:27:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace HttpServer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use HttpServer\Http\HttpHeaders;
|
|
|
|
|
use HttpServer\Http\HttpParams;
|
|
|
|
|
use HttpServer\Http\Request;
|
|
|
|
|
use Exception;
|
2020-09-10 15:50:32 +08:00
|
|
|
use Snowflake\Abstracts\BaseGoto;
|
2020-08-31 01:27:08 +08:00
|
|
|
use Snowflake\Snowflake;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class WebController
|
2020-08-31 12:38:32 +08:00
|
|
|
* @package Snowflake\Snowflake\Web
|
2020-09-10 15:50:32 +08:00
|
|
|
* @property BaseGoto $goto
|
2020-08-31 01:27:08 +08:00
|
|
|
*/
|
|
|
|
|
class Controller extends Application
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** @var HttpParams $input */
|
2020-08-31 10:48:02 +08:00
|
|
|
public $input;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var HttpHeaders */
|
2020-08-31 10:48:02 +08:00
|
|
|
public $headers;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var Request */
|
2020-08-31 10:48:02 +08:00
|
|
|
public $request;
|
2020-08-31 01:27:08 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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) {
|
2020-09-03 11:39:20 +08:00
|
|
|
$this->request = Snowflake::app()->request;
|
2020-08-31 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
2020-09-10 15:49:42 +08:00
|
|
|
|
|
|
|
|
$app = Snowflake::app();
|
|
|
|
|
if ($app->has($name)) {
|
|
|
|
|
return $app->get($name);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 01:27:08 +08:00
|
|
|
return parent::__get($name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|