Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
Thumbnail | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBackgroundImage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPlaceholderClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Thumbnail.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system for Wikimedia projects. |
6 | * It contains the definition and implementation of the `Thumbnail` class, responsible for managing |
7 | * the behavior and properties of the corresponding component. |
8 | * |
9 | * @category Component |
10 | * @package Codex\Component |
11 | * @since 0.1.0 |
12 | * @author Doğu Abaris <abaris@null.net> |
13 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
14 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
15 | */ |
16 | |
17 | namespace Wikimedia\Codex\Component; |
18 | |
19 | use Wikimedia\Codex\Renderer\ThumbnailRenderer; |
20 | |
21 | /** |
22 | * Thumbnail |
23 | * |
24 | * This class is part of the Codex PHP library and is responsible for |
25 | * representing an immutable object. It is primarily intended for use |
26 | * with a builder class to construct its instances. |
27 | * |
28 | * @category Component |
29 | * @package Codex\Component |
30 | * @since 0.1.0 |
31 | * @author Doğu Abaris <abaris@null.net> |
32 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
33 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
34 | */ |
35 | class Thumbnail { |
36 | |
37 | /** |
38 | * The ID for the thumbnail. |
39 | */ |
40 | private string $id; |
41 | |
42 | /** |
43 | * The background image URL for the thumbnail. |
44 | */ |
45 | private string $backgroundImage; |
46 | |
47 | /** |
48 | * The CSS class for the custom placeholder icon. |
49 | */ |
50 | private string $placeholderClass; |
51 | |
52 | /** |
53 | * Additional HTML attributes for the thumbnail. |
54 | */ |
55 | private array $attributes; |
56 | |
57 | /** |
58 | * The renderer instance used to render the thumbnail. |
59 | */ |
60 | private ThumbnailRenderer $renderer; |
61 | |
62 | /** |
63 | * Constructor for the Thumbnail component. |
64 | * |
65 | * @param string $id The ID for the thumbnail. |
66 | * @param string $backgroundImage The background image URL. |
67 | * @param string $placeholderClass The CSS class for the placeholder icon. |
68 | * @param array $attributes Additional HTML attributes for the thumbnail. |
69 | * @param ThumbnailRenderer $renderer The renderer to use for rendering the thumbnail. |
70 | */ |
71 | public function __construct( |
72 | string $id, |
73 | string $backgroundImage, |
74 | string $placeholderClass, |
75 | array $attributes, |
76 | ThumbnailRenderer $renderer |
77 | ) { |
78 | $this->id = $id; |
79 | $this->backgroundImage = $backgroundImage; |
80 | $this->placeholderClass = $placeholderClass; |
81 | $this->attributes = $attributes; |
82 | $this->renderer = $renderer; |
83 | } |
84 | |
85 | /** |
86 | * Get the HTML ID for the thumbnail. |
87 | * |
88 | * This method returns the HTML `id` attribute value for the thumbnail element. |
89 | * |
90 | * @since 0.1.0 |
91 | * @return string The ID for the thumbnail. |
92 | */ |
93 | public function getId(): string { |
94 | return $this->id; |
95 | } |
96 | |
97 | /** |
98 | * Get the background image URL for the thumbnail. |
99 | * |
100 | * This method returns the URL of the background image that will be displayed within the thumbnail. |
101 | * The image serves as a visual preview of the content. |
102 | * |
103 | * @since 0.1.0 |
104 | * @return string The URL of the background image. |
105 | */ |
106 | public function getBackgroundImage(): string { |
107 | return $this->backgroundImage; |
108 | } |
109 | |
110 | /** |
111 | * Get the CSS class for the custom placeholder icon. |
112 | * |
113 | * This method returns the CSS class for the custom placeholder icon that will be displayed if |
114 | * the background image is not provided. |
115 | * The placeholder gives users a visual indication of where an image will appear. |
116 | * |
117 | * @since 0.1.0 |
118 | * @return string The CSS class for the placeholder icon. |
119 | */ |
120 | public function getPlaceholderClass(): string { |
121 | return $this->placeholderClass; |
122 | } |
123 | |
124 | /** |
125 | * Retrieve additional HTML attributes for the thumbnail element. |
126 | * |
127 | * This method returns an associative array of custom HTML attributes that will be applied to the outer |
128 | * `<span>` element of the thumbnail. These attributes can be used to improve accessibility, enhance styling, |
129 | * or integrate with JavaScript functionality. |
130 | * |
131 | * @since 0.1.0 |
132 | * @return array The additional attributes as an array. |
133 | */ |
134 | public function getAttributes(): array { |
135 | return $this->attributes; |
136 | } |
137 | |
138 | /** |
139 | * Get the component's HTML representation. |
140 | * |
141 | * This method generates the HTML markup for the component, incorporating relevant properties |
142 | * and any additional attributes. The component is structured using appropriate HTML elements |
143 | * as defined by the implementation. |
144 | * |
145 | * @since 0.1.0 |
146 | * @return string The generated HTML string for the component. |
147 | */ |
148 | public function getHtml(): string { |
149 | return $this->renderer->render( $this ); |
150 | } |
151 | } |