Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/MutableEvent.php → src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,62 @@

use Override;

class MutableEvent implements MutableEventInterface
class Event implements EventInterface, EventPropagationInterface
{
use EventPropagationTrait;

/**
* @param array<array-key, mixed>|null $params
*/
public function __construct(
private ?string $name = null,
private ?object $target = null,
private ?array $params = null,
private array $params = [],
) {}

#[Override]
public function setName(string $name): void
{
$this->name = $name;
}
#[Override]
public function getName(): string
{
return $this->name ?? static::class;
}

#[Override]
public function setName(string $name): void
public function setTarget(object $target): void
{
$this->name = $name;
$this->target = $target;
}

#[Override]
public function getTarget(): ?object
{
return $this->target;
}

#[Override]
public function setTarget(object $target): void
public function setParam(string $name, mixed $value): void
{
$this->target = $target;
$this->params[$name] = $value;
}

#[Override]
public function getParams(): array
public function getParam(string $name, mixed $default = null): mixed
{
return $this->params ?? [];
return $this->params[$name] ?? $default;
}

#[Override]
public function setParams(array $params): void
{
$this->params = $params;
}

#[Override]
public function getParams(): array
{
return $this->params;
}
}
3 changes: 3 additions & 0 deletions src/EventDispatcherAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Webware\CommandBus\Event;

use Override;
use Psr\EventDispatcher\EventDispatcherInterface;

/**
Expand All @@ -23,11 +24,13 @@ trait EventDispatcherAwareTrait
{
protected EventDispatcherInterface $eventDispatcher;

#[Override]
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}

#[Override]
public function getEventDispatcher(): EventDispatcherInterface
{
return $this->eventDispatcher;
Expand Down
15 changes: 13 additions & 2 deletions src/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@

interface EventInterface
{
public function setName(string $name): void;

public function getName(): string;

public function getTarget(): ?object;

public function setTarget(object $target): void;

public function setParam(string $name, mixed $value): void;

public function getParam(string $name, mixed $default = null): mixed;

public function setParams(array $params): void;

/**
* @return array<array-key, mixed>|null
* @return array<array-key, mixed>
*/
public function getParams(): ?array;
public function getParams(): array;

}
12 changes: 12 additions & 0 deletions src/EventPropagationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Webware\CommandBus\Event;

interface EventPropagationInterface
{
public function stopPropagation(): void;

public function isPropagationStopped(): bool;
}
24 changes: 24 additions & 0 deletions src/EventPropagationTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Webware\CommandBus\Event;

use Override;

trait EventPropagationTrait
{
protected bool $propagationStopped = false;

#[Override]
public function stopPropagation(bool $flag = true): void
{
$this->propagationStopped = $flag;
}

#[Override]
public function isPropagationStopped(): bool
{
return $this->propagationStopped;
}
}
71 changes: 0 additions & 71 deletions src/ImmutableEvent.php

This file was deleted.

27 changes: 0 additions & 27 deletions src/ImmutableEventInterface.php

This file was deleted.

27 changes: 0 additions & 27 deletions src/MutableEventInterface.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/PostHandleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use Webware\CommandBus\CommandInterface;

final class PostHandleEvent extends MutableEvent
final class PostHandleEvent extends Event
{
public function __construct(
private CommandInterface $command,
Expand Down
2 changes: 1 addition & 1 deletion src/PreHandleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use Webware\CommandBus\CommandInterface;

final class PreHandleEvent extends MutableEvent
final class PreHandleEvent extends Event
{
public function __construct(
private readonly CommandInterface $command,
Expand Down