modify
This commit is contained in:
+19
-69
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
use Annotation\Inject;
|
||||
use Exception;
|
||||
use HttpServer\Abstracts\HttpService;
|
||||
use HttpServer\Http\HttpHeaders;
|
||||
use HttpServer\Http\HttpParams;
|
||||
use HttpServer\Http\Request;
|
||||
use HttpServer\Http\Response;
|
||||
use Snowflake\Abstracts\Input;
|
||||
use Snowflake\Abstracts\TraitApplication;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
@@ -17,82 +20,29 @@ use Snowflake\Snowflake;
|
||||
* @package Snowflake\Snowflake\Web
|
||||
* @property-read HttpParams $input
|
||||
* @property-read HttpHeaders $headers
|
||||
* @property-read Request $request
|
||||
*/
|
||||
class Controller extends HttpService
|
||||
class Controller
|
||||
{
|
||||
|
||||
use TraitApplication;
|
||||
use TraitApplication;
|
||||
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
* @param array $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
parent::__construct($config);
|
||||
}
|
||||
/**
|
||||
* inject request
|
||||
*
|
||||
* @var \HttpServer\Http\Request
|
||||
*/
|
||||
#[Inject(className: 'request', withContext: true)]
|
||||
protected Request $request;
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$annotation = Snowflake::getAnnotation();
|
||||
$annotation->injectProperty($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ?HttpParams
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getInput(): ?HttpParams
|
||||
{
|
||||
return \request()->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?HttpHeaders
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getHeaders(): ?HttpHeaders
|
||||
{
|
||||
return \request()->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Request|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRequest(): ?Request
|
||||
{
|
||||
return \request();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($name): mixed
|
||||
{
|
||||
// TODO: Change the autogenerated stub
|
||||
if (property_exists($this, $name)) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
$method = 'get' . ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->{$method}();
|
||||
}
|
||||
|
||||
return Snowflake::app()->get($name);
|
||||
}
|
||||
/**
|
||||
* inject response
|
||||
*
|
||||
* @var \HttpServer\Http\Response
|
||||
*/
|
||||
#[Inject('response')]
|
||||
protected Response $response;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user