Skip to content

Commit

Permalink
+ Event refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu2607 committed Dec 6, 2024
1 parent 77fe8a8 commit 0ab3f81
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 117 deletions.
40 changes: 1 addition & 39 deletions src/Domain/Event/NewsCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,17 @@

class NewsCreatedEvent extends DomainEvent
{
private News $news;
use NewsEventTrait;

/**
* @var array<mixed>
*/
private array $payload;

/**
* @param array<mixed> $payload
*/
public function __construct(News $news, array $payload)
{
parent::__construct();
$this->news = $news;
$this->payload = $payload;
}

public function getNews(): News
{
return $this->news;
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getEventType(): string
{
return 'created';
}

public function getResourceKey(): string
{
return News::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->news->getId();
}

public function getResourceTitle(): ?string
{
return $this->news->getTitle();
}

public function getResourceSecurityContext(): ?string
{
return News::SECURITY_CONTEXT;
}
}
44 changes: 44 additions & 0 deletions src/Domain/Event/NewsEventTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Pixel\NewsBundle\Domain\Event;

use Pixel\NewsBundle\Entity\News;

trait NewsEventTrait
{
private News $news;

private array $payload;

public function getNews(): News
{
return $this->news;
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getResourceKey(): string
{
return News::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->news->getId();
}

public function getResourceTitle(): ?string
{
return $this->news->getTitle();
}

public function getResourceSecurityContext(): ?string
{
return News::SECURITY_CONTEXT;
}
}
40 changes: 1 addition & 39 deletions src/Domain/Event/NewsModifiedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,17 @@

class NewsModifiedEvent extends DomainEvent
{
private News $news;
use NewsEventTrait;

/**
* @var array<mixed>
*/
private array $payload;

/**
* @param array<mixed> $payload
*/
public function __construct(News $news, array $payload)
{
parent::__construct();
$this->news = $news;
$this->payload = $payload;
}

public function getNews(): News
{
return $this->news;
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getEventType(): string
{
return 'modified';
}

public function getResourceKey(): string
{
return News::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->news->getId();
}

public function getResourceTitle(): ?string
{
return $this->news->getTitle();
}

public function getResourceSecurityContext(): ?string
{
return News::SECURITY_CONTEXT;
}
}
40 changes: 1 addition & 39 deletions src/Domain/Event/NewsRestoredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,17 @@

class NewsRestoredEvent extends DomainEvent
{
private News $news;
use NewsEventTrait;

/**
* @var array<mixed>
*/
private array $payload;

/**
* @param array<mixed> $payload
*/
public function __construct(News $news, array $payload)
{
parent::__construct();
$this->news = $news;
$this->payload = $payload;
}

public function getNews(): News
{
return $this->news;
}

public function getEventPayload(): ?array
{
return $this->payload;
}

public function getEventType(): string
{
return 'restored';
}

public function getResourceKey(): string
{
return News::RESOURCE_KEY;
}

public function getResourceId(): string
{
return (string) $this->news->getId();
}

public function getResourceTitle(): ?string
{
return $this->news->getTitle();
}

public function getResourceSecurityContext(): ?string
{
return News::SECURITY_CONTEXT;
}
}

0 comments on commit 0ab3f81

Please sign in to comment.