| 1 |
<?php |
| 2 |
|
| 3 |
namespace AATXT\App\Events; |
| 4 |
|
| 5 |
/** |
| 6 |
* Event dispatched when alt text is successfully generated. |
| 7 |
* |
| 8 |
* This event is fired after an AI provider successfully generates |
| 9 |
* alt text for an image. Listeners can use this for logging, |
| 10 |
* analytics, or triggering additional actions. |
| 11 |
* |
| 12 |
* @package AATXT\App\Events |
| 13 |
*/ |
| 14 |
final class AltTextGeneratedEvent |
| 15 |
{ |
| 16 |
/** |
| 17 |
* WordPress attachment ID |
| 18 |
* |
| 19 |
* @var int |
| 20 |
*/ |
| 21 |
private $imageId; |
| 22 |
|
| 23 |
/** |
| 24 |
* Generated alt text |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
private $altText; |
| 29 |
|
| 30 |
/** |
| 31 |
* Provider name that generated the alt text |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
private $provider; |
| 36 |
|
| 37 |
/** |
| 38 |
* Timestamp when the event occurred |
| 39 |
* |
| 40 |
* @var int |
| 41 |
*/ |
| 42 |
private $timestamp; |
| 43 |
|
| 44 |
/** |
| 45 |
* Constructor |
| 46 |
* |
| 47 |
* @param int $imageId WordPress attachment ID |
| 48 |
* @param string $altText Generated alt text |
| 49 |
* @param string $provider Provider name (e.g., 'OpenAI Vision', 'Anthropic') |
| 50 |
*/ |
| 51 |
public function __construct(int $imageId, string $altText, string $provider) |
| 52 |
{ |
| 53 |
$this->imageId = $imageId; |
| 54 |
$this->altText = $altText; |
| 55 |
$this->provider = $provider; |
| 56 |
$this->timestamp = time(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get the image ID. |
| 61 |
* |
| 62 |
* @return int |
| 63 |
*/ |
| 64 |
public function getImageId(): int |
| 65 |
{ |
| 66 |
return $this->imageId; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get the generated alt text. |
| 71 |
* |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
public function getAltText(): string |
| 75 |
{ |
| 76 |
return $this->altText; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Get the provider name. |
| 81 |
* |
| 82 |
* @return string |
| 83 |
*/ |
| 84 |
public function getProvider(): string |
| 85 |
{ |
| 86 |
return $this->provider; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Get the timestamp when the event occurred. |
| 91 |
* |
| 92 |
* @return int Unix timestamp |
| 93 |
*/ |
| 94 |
public function getTimestamp(): int |
| 95 |
{ |
| 96 |
return $this->timestamp; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Get the length of the generated alt text. |
| 101 |
* |
| 102 |
* @return int Character count |
| 103 |
*/ |
| 104 |
public function getAltTextLength(): int |
| 105 |
{ |
| 106 |
return mb_strlen($this->altText); |
| 107 |
} |
| 108 |
} |
| 109 |
|