diff --git a/http-helper/Context/Context.php b/http-helper/Context/Context.php index 83bc90fb..781608b8 100644 --- a/http-helper/Context/Context.php +++ b/http-helper/Context/Context.php @@ -81,11 +81,7 @@ class Context extends BaseContext */ private static function loadByContext($id, $default = null, $coroutineId = null): mixed { - $data = Coroutine::getContext($coroutineId)[$id] ?? null; - if ($data === null) { - return $default; - } - return $data; + return Coroutine::getContext($coroutineId)[$id] ?? $default; } @@ -96,11 +92,7 @@ class Context extends BaseContext */ private static function loadByStatic($id, $default = null): mixed { - $data = static::$_contents[$id] ?? null; - if ($data === null) { - return $default; - } - return $data; + return static::$_contents[$id] ?? $default; } diff --git a/http-server/Constrict/Request.php b/http-server/Constrict/Request.php index d53c2876..4a5678e7 100644 --- a/http-server/Constrict/Request.php +++ b/http-server/Constrict/Request.php @@ -21,7 +21,7 @@ class Request implements RequestInterface */ private function __call__(): RequestInterface { - return Context::getContext(RequestMessage::class); + return Context::getContext(RequestMessage::class, new RequestMessage()); } diff --git a/http-server/Constrict/Response.php b/http-server/Constrict/Response.php index 5680cc24..a83d76d0 100644 --- a/http-server/Constrict/Response.php +++ b/http-server/Constrict/Response.php @@ -5,8 +5,8 @@ namespace Server\Constrict; use Http\Context\Context; -use Server\ResponseInterface; use Server\Message\Response as Psr7Response; +use Server\ResponseInterface; /** @@ -22,34 +22,34 @@ class Response implements ResponseInterface const HTML = 'html'; const FILE = 'file'; - /** - * @param $name - * @param $args - * @return mixed - */ - public function __call($name, $args) - { - if (!method_exists($this, $name)) { - return $this->__call__()->{$name}(...$args); - } - return $this->{$name}(...$args); - } + /** + * @param $name + * @param $args + * @return mixed + */ + public function __call($name, $args) + { + if (!method_exists($this, $name)) { + return $this->__call__()->{$name}(...$args); + } + return $this->{$name}(...$args); + } - /** - * @param string $name - * @return mixed - */ - public function __get(string $name) - { - return $this->__call__()->{$name}; - } + /** + * @param string $name + * @return mixed + */ + public function __get(string $name) + { + return $this->__call__()->{$name}; + } - /** - * @return Psr7Response - */ - public function __call__(): Psr7Response - { - return Context::getContext(Psr7Response::class); - } + /** + * @return Psr7Response + */ + public function __call__(): Psr7Response + { + return Context::getContext(Psr7Response::class, new Psr7Response()); + } }