generated from Potter/Template
init
This commit is contained in:
@@ -10,6 +10,7 @@ use \Potter\Aware\AwareInterface;
|
|||||||
|
|
||||||
interface DispatcherAwareInterface extends BaseDispatcherAwareInterface, AwareInterface
|
interface DispatcherAwareInterface extends BaseDispatcherAwareInterface, AwareInterface
|
||||||
{
|
{
|
||||||
public function useEventDispatcher(BaseDispatcher $dispatcher): void;
|
|
||||||
public function eventDispatcher(): BaseDispatcher;
|
public function eventDispatcher(): BaseDispatcher;
|
||||||
|
public function hasEventDispatcher(): bool;
|
||||||
|
public function useEventDispatcher(BaseDispatcher $dispatcher): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,34 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Potter\Event;
|
namespace Potter\Event;
|
||||||
|
|
||||||
|
use \League\Event\EventDispatcher as BaseDispatcher;
|
||||||
|
|
||||||
trait DispatcherAwareTrait
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user