diff --git a/src/Potter/Http/Server/HttpServerAwareInterface.php b/src/Potter/Http/Server/HttpServerAwareInterface.php index c5197b3..be68c8a 100644 --- a/src/Potter/Http/Server/HttpServerAwareInterface.php +++ b/src/Potter/Http/Server/HttpServerAwareInterface.php @@ -11,4 +11,6 @@ interface HttpServerAwareInterface extends AwareInterface { public function getHttpServer(): HttpServer; public function hasHttpServer(): bool; + public function withHttpServer(HttpServer $httpServer): static; + public function withoutHttpServer(): static; } diff --git a/src/Potter/Http/Server/HttpServerAwareTrait.php b/src/Potter/Http/Server/HttpServerAwareTrait.php index a2da572..18fa01d 100644 --- a/src/Potter/Http/Server/HttpServerAwareTrait.php +++ b/src/Potter/Http/Server/HttpServerAwareTrait.php @@ -4,11 +4,41 @@ declare(strict_types=1); namespace Potter\Http\Server; +use \React\Http\HttpServer; + trait HttpServerAwareTrait { private const string HTTP_SERVER = 'httpServer'; - final public function getHttpServer(): HttpServer; - final public function hasHttpServer(): bool; - final protected function setHttpServer(HttpServer $httpServer): HttpServer; + final public function getHttpServer(): HttpServer + { + return $this->get(self::HTTP_SERVER); + } + + final public function hasHttpServer(): bool + { + return $this->has(self::HTTP_SERVER); + } + + final protected function setHttpServer(HttpServer $httpServer): HttpServer + { + return $this->set(self::HTTP_SERVER, $httpServer); + } + + final public function withHttpServer(HttpServer $httpServer): static + { + return $this->with(self::HTTP_SERVER, $httpServer); + } + + final public function withoutHttpServer(): static + { + return $this->without(self::HTTP_SERVER); + } + + abstract public function get(string $key): mixed; + abstract public function has(string $key): mixed; + abstract protected function set(string $key, mixed $value): mixed; + abstract protected function unset(string $key): null; + abstract public function with(string $key, mixed $value): static; + abstract public function without(string $key): static; }