Files
kiri-core/HttpServer/Controller.php
T

156 lines
2.9 KiB
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-08-31 01:27:08 +08:00
namespace HttpServer;
2020-11-12 15:37:59 +08:00
use Database\DatabasesProviders;
use HttpServer\Client\Client;
use HttpServer\Client\Curl;
use HttpServer\Client\Http2;
2020-08-31 01:27:08 +08:00
use HttpServer\Http\HttpHeaders;
use HttpServer\Http\HttpParams;
use HttpServer\Http\Request;
use Exception;
2020-11-12 15:37:59 +08:00
use HttpServer\Route\Router;
use Kafka\Producer;
2020-09-10 15:50:32 +08:00
use Snowflake\Abstracts\BaseGoto;
2020-11-12 15:37:59 +08:00
use Snowflake\Annotation\Annotation;
use Snowflake\Cache\Memcached;
use Snowflake\Cache\Redis;
use Snowflake\Error\Logger;
use Snowflake\Event;
2020-11-10 18:04:42 +08:00
use Snowflake\Exception\ComponentException;
2020-11-12 15:37:59 +08:00
use Snowflake\Jwt\Jwt;
use Snowflake\Pool\Connection;
use Snowflake\Pool\Pool as SPool;
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-11-12 15:37:59 +08:00
* @property Annotation $annotation
* @property Event $event
* @property Router $router
* @property SPool $pool
* @property \Redis|Redis $redis
* @property Server $server
* @property DatabasesProviders $db
* @property Connection $connections
* @property Memcached $memcached
* @property Logger $logger
* @property Jwt $jwt
* @property Client $client
* @property Producer $kafka
* @property Curl $curl
* @property Http2 $http2
2020-08-31 01:27:08 +08:00
*/
class Controller extends Application
{
/** @var HttpParams $input */
2020-10-29 18:17:25 +08:00
public HttpParams $input;
2020-08-31 01:27:08 +08:00
/** @var HttpHeaders */
2020-10-29 18:17:25 +08:00
public HttpHeaders $headers;
2020-08-31 01:27:08 +08:00
/** @var Request */
2020-10-29 18:17:25 +08:00
public Request $request;
2020-08-31 01:27:08 +08:00
2020-09-10 15:54:14 +08:00
2020-11-10 18:04:42 +08:00
/**
* Controller constructor.
* @param array $config
*/
2020-09-10 15:54:14 +08:00
public function __construct($config = [])
{
parent::__construct($config);
}
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;
}
2020-11-10 18:04:42 +08:00
/**
* @param $methods
* @return mixed
* @throws ComponentException
*/
public function __get($methods)
{
// TODO: Change the autogenerated stub
if (property_exists($this, $methods)) {
return $this->$methods;
}
$method = 'get' . ucfirst($methods);
if (method_exists($this, $method)) {
return $this->{$method}();
}
return Snowflake::app()->get($methods);
}
2020-08-31 01:27:08 +08:00
}