| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Scheduler\Common; |
| 4 |
|
| 5 |
use LogicException; |
| 6 |
use Ramsey\Uuid\UuidInterface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Common property helpers for {@see \ipl\Scheduler\Contract\Task} implementations |
| 10 |
* |
| 11 |
* Provides storage and accessors for the name, description, and UUID of a task. |
| 12 |
* Getters throw a {@see LogicException} when the corresponding property has not been set. |
| 13 |
*/ |
| 14 |
trait TaskProperties |
| 15 |
{ |
| 16 |
protected ?string $description = null; |
| 17 |
|
| 18 |
protected ?string $name = null; |
| 19 |
|
| 20 |
protected ?UuidInterface $uuid = null; |
| 21 |
|
| 22 |
/** |
| 23 |
* Set the description of this task |
| 24 |
* |
| 25 |
* @param ?string $desc |
| 26 |
* |
| 27 |
* @return $this |
| 28 |
*/ |
| 29 |
public function setDescription(?string $desc): static |
| 30 |
{ |
| 31 |
$this->description = $desc; |
| 32 |
|
| 33 |
return $this; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get the description of this task |
| 38 |
* |
| 39 |
* @return ?string |
| 40 |
*/ |
| 41 |
public function getDescription(): ?string |
| 42 |
{ |
| 43 |
return $this->description; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get the name of this task |
| 48 |
* |
| 49 |
* @return string |
| 50 |
* |
| 51 |
* @throws LogicException If the name has not been set |
| 52 |
*/ |
| 53 |
public function getName(): string |
| 54 |
{ |
| 55 |
if (! $this->name) { |
| 56 |
throw new LogicException('Task name must not be null'); |
| 57 |
} |
| 58 |
|
| 59 |
return $this->name; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Set the name of this task |
| 64 |
* |
| 65 |
* @param string $name |
| 66 |
* |
| 67 |
* @return $this |
| 68 |
*/ |
| 69 |
public function setName(string $name): static |
| 70 |
{ |
| 71 |
$this->name = $name; |
| 72 |
|
| 73 |
return $this; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Get the unique identifier of this task |
| 78 |
* |
| 79 |
* @return UuidInterface |
| 80 |
* |
| 81 |
* @throws LogicException If the UUID has not been set |
| 82 |
*/ |
| 83 |
public function getUuid(): UuidInterface |
| 84 |
{ |
| 85 |
if (! $this->uuid) { |
| 86 |
throw new LogicException('Task UUID must not be null'); |
| 87 |
} |
| 88 |
|
| 89 |
return $this->uuid; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Set the UUID of this task |
| 94 |
* |
| 95 |
* @param UuidInterface $uuid |
| 96 |
* |
| 97 |
* @return $this |
| 98 |
*/ |
| 99 |
public function setUuid(UuidInterface $uuid): static |
| 100 |
{ |
| 101 |
$this->uuid = $uuid; |
| 102 |
|
| 103 |
return $this; |
| 104 |
} |
| 105 |
} |