This commit is contained in:
2026-03-21 11:20:10 -04:00
parent 1b4dca9810
commit 45252bfd87
2 changed files with 35 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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;
}