This commit is contained in:
2026-03-21 12:28:08 -04:00
parent 5598373b09
commit b25ab2d651
2 changed files with 32 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ use \Potter\Aware\AwareInterface;
interface DispatcherAwareInterface extends BaseDispatcherAwareInterface, AwareInterface
{
public function useEventDispatcher(BaseDispatcher $dispatcher): void;
public function eventDispatcher(): BaseDispatcher;
public function hasEventDispatcher(): bool;
public function useEventDispatcher(BaseDispatcher $dispatcher): void;
}

View File

@@ -4,5 +4,34 @@ declare(strict_types=1);
namespace Potter\Event;
use \League\Event\EventDispatcher as BaseDispatcher;
trait DispatcherAwareTrait
{ }
{
private const string DISPATCHER = 'dispatcher';
final public function useEventDispatcher(BaseDispatcher $dispatcher): void
{
$this->set(self::DISPATCHER, $dispatcher);
}
final public function eventDispatcher(): BaseDispatcher
{
if (!$this->hasEventDispatcher()) {
$this->useEventDispatcher(new Dispatcher);
}
return $this->get(self::DISPATCHER);
}
final public function hasEventDispatcher(): bool
{
return $this->has(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;
abstract protected function unset(string $key): null;
abstract public function with(string $key, mixed $value): static;
abstract public function without(string $key): static;
}