From c898292ebe922e03affc9320f348f9a6982a1e2c Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Sat, 28 Aug 2021 01:49:06 +0800 Subject: [PATCH] 111 --- http-server/Constrict/Response.php | 47 +++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/http-server/Constrict/Response.php b/http-server/Constrict/Response.php index 05f488bb..d0fb02c4 100644 --- a/http-server/Constrict/Response.php +++ b/http-server/Constrict/Response.php @@ -22,19 +22,38 @@ class Response implements ResponseInterface const HTML = 'html'; const FILE = 'file'; - /** - * @param $name - * @param $args - * @return mixed - */ - public function __call($name, $args) - { - if (!Context::hasContext(Psr7Response::class)) { - $context = Context::setContext(Psr7Response::class, new Psr7Response()); - } else { - $context = Context::getContext(Psr7Response::class); - } - return $context->{$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 + */ + public function __get(string $name) + { + return $this->__call__()->{$name}; + } + + + /** + * @return Psr7Response + */ + public function __call__(): Psr7Response + { + if (!Context::hasContext(Psr7Response::class)) { + $context = Context::setContext(Psr7Response::class, new Psr7Response()); + } else { + $context = Context::getContext(Psr7Response::class); + } + return $context; + } }