0 follower

Final Class Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher

InheritanceYiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher
ImplementsPsr\EventDispatcher\EventDispatcherInterface

Method Details

Hide inherited methods

__construct() public method

public __construct( Closure $listeners ): mixed
$listeners Closure

Functions that will handle each event.

                public function __construct(Closure ...$listeners)
{
    $this->listeners = $listeners;
}

            
clearEvents() public method

public clearEvents( ): void

                public function clearEvents(): void
{
    $this->events = [];
}

            
dispatch() public method

public dispatch( object $event ): object
$event object

                public function dispatch(object $event): object
{
    $this->events[] = $event;
    foreach ($this->listeners as $listener) {
        if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
            return $event;
        }
        $listener($event);
    }
    return $event;
}

            
getEventClasses() public method

public getEventClasses( ): array

                public function getEventClasses(): array
{
    return array_map('\get_class', $this->events);
}

            
getEvents() public method

public getEvents( ): object[]

                public function getEvents(): array
{
    return $this->events;
}

            
isClassTriggered() public method

public isClassTriggered( string $class, integer|null $times null ): boolean
$class string
$times integer|null

                public function isClassTriggered(string $class, ?int $times = null): bool
{
    return $this->processBoolResult(static fn (object $event): bool => $event::class === $class, $times);
}

            
isInstanceOfTriggered() public method

public isInstanceOfTriggered( string $class, integer|null $times null ): boolean
$class string
$times integer|null

                public function isInstanceOfTriggered(string $class, ?int $times = null): bool
{
    return $this->processBoolResult(static fn (object $event): bool => $event instanceof $class, $times);
}

            
isObjectTriggered() public method

public isObjectTriggered( object $event, integer|null $times null ): boolean
$event object
$times integer|null

                public function isObjectTriggered(object $event, ?int $times = null): bool
{
    return $this->processBoolResult(static fn (object $e): bool => $e === $event, $times);
}