1: <?php declare(strict_types=1);
2:
3: namespace Salient\Sync\Exception;
4:
5: use Salient\Contract\Sync\SyncEntityInterface;
6: use Salient\Contract\Sync\SyncProviderInterface;
7: use Throwable;
8:
9: /**
10: * @api
11: */
12: class SyncInvalidEntityException extends AbstractSyncException
13: {
14: protected SyncProviderInterface $Provider;
15: /** @var class-string<SyncEntityInterface> */
16: protected string $EntityType;
17: /** @var int|string|null */
18: protected $EntityId;
19: protected ?SyncEntityInterface $Entity;
20:
21: /**
22: * @template T of SyncEntityInterface
23: *
24: * @param class-string<T> $entityType
25: * @param T|int|string|null $entityOrId
26: */
27: public function __construct(
28: string $message,
29: SyncProviderInterface $provider,
30: string $entityType,
31: $entityOrId,
32: ?Throwable $previous = null
33: ) {
34: $this->Provider = $provider;
35: $this->EntityType = $entityType;
36:
37: if ($entityOrId instanceof SyncEntityInterface) {
38: $this->EntityId = $entityOrId->getId();
39: $this->Entity = $entityOrId;
40: } else {
41: $this->EntityId = $entityOrId;
42: $this->Entity = null;
43: }
44:
45: parent::__construct($message, $previous);
46: }
47:
48: public function getProvider(): SyncProviderInterface
49: {
50: return $this->Provider;
51: }
52:
53: public function getEntityType(): string
54: {
55: return $this->EntityType;
56: }
57:
58: /**
59: * @return int|string|null
60: */
61: public function getEntityId()
62: {
63: return $this->EntityId;
64: }
65:
66: public function getEntity(): ?SyncEntityInterface
67: {
68: return $this->Entity;
69: }
70:
71: /**
72: * @inheritDoc
73: */
74: public function getMetadata(): array
75: {
76: return [
77: 'Provider' => $this->getProviderName($this->Provider),
78: 'Entity' => $this->EntityType,
79: 'EntityId' => $this->EntityId,
80: ];
81: }
82: }
83: