PluginProbe
Auto Alt Text / trunk
Auto Alt Text vtrunk
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / src / App / Events / AltTextGeneratedEvent.php

AltTextGeneratedEvent.php in Auto Alt Text trunk, at src/App/Events/AltTextGeneratedEvent.php

109 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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