diff --git a/src/Potter/Event/DispatcherAwareInterface.php b/src/Potter/Event/DispatcherAwareInterface.php index a349e01..a0cbaba 100644 --- a/src/Potter/Event/DispatcherAwareInterface.php +++ b/src/Potter/Event/DispatcherAwareInterface.php @@ -13,4 +13,6 @@ interface DispatcherAwareInterface extends BaseDispatcherAwareInterface, AwareIn public function eventDispatcher(): BaseDispatcher; public function hasEventDispatcher(): bool; public function useEventDispatcher(BaseDispatcher $dispatcher): void; + public function withEventDispatcher(BaseDispatcher $dispatcher): static; + public function withoutEventDispatcher(): static; } diff --git a/src/Potter/Event/DispatcherAwareTrait.php b/src/Potter/Event/DispatcherAwareTrait.php index 46b9838..246c345 100644 --- a/src/Potter/Event/DispatcherAwareTrait.php +++ b/src/Potter/Event/DispatcherAwareTrait.php @@ -28,6 +28,16 @@ trait DispatcherAwareTrait return $this->has(self::DISPATCHER); } + final public function withEventDispatcher(BaseDispatcher $dispatcher): static + { + return $this->with(self::DISPATCHER, $dispatcher); + } + + final public function withoutEventDispatcher(): static + { + return $this->without(self::DISPATCHER); + } + abstract public function get(string $key): mixed; abstract public function has(string $key): mixed; abstract protected function set(string $key, mixed $value): mixed;