Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
HtmlSnippet | |
0.00% |
0 / 5 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * HtmlSnippet.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 `HtmlSnippet` 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 | /** |
20 | * HtmlSnippet |
21 | * |
22 | * This class is part of the Codex PHP library and is responsible for |
23 | * representing an immutable object. It is primarily intended for use |
24 | * with a builder class to construct its instances. |
25 | * |
26 | * @category Component |
27 | * @package Codex\Component |
28 | * @since 0.1.0 |
29 | * @author Doğu Abaris <abaris@null.net> |
30 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
31 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
32 | */ |
33 | class HtmlSnippet { |
34 | |
35 | /** |
36 | * The safe HTML content to be rendered. |
37 | */ |
38 | private string $content; |
39 | |
40 | /** |
41 | * Additional HTML attributes for the container element. |
42 | */ |
43 | private array $attributes; |
44 | |
45 | /** |
46 | * Constructor for the HtmlSnippet component. |
47 | * |
48 | * Initializes a HtmlSnippet instance with the specified content and attributes. |
49 | * |
50 | * @param string $content The safe HTML content to be rendered. |
51 | * @param array $attributes Additional HTML attributes for the container element. |
52 | */ |
53 | public function __construct( string $content, array $attributes ) { |
54 | $this->content = $content; |
55 | $this->attributes = $attributes; |
56 | } |
57 | |
58 | /** |
59 | * Get the raw HTML content. |
60 | * |
61 | * This method returns the raw HTML content for rendering. |
62 | * |
63 | * @since 0.1.0 |
64 | * @return string The raw HTML content. |
65 | */ |
66 | public function getContent(): string { |
67 | return $this->content; |
68 | } |
69 | |
70 | /** |
71 | * Retrieve additional HTML attributes for the the html snippet element. |
72 | * |
73 | * This method returns an associative array of additional HTML attributes that will be applied |
74 | * to the html snippet element. These attributes can be used to enhance the appearance, accessibility, |
75 | * or functionality of the html snippet element. |
76 | * |
77 | * @since 0.1.0 |
78 | * @return array The additional attributes as an array. |
79 | */ |
80 | public function getAttributes(): array { |
81 | return $this->attributes; |
82 | } |
83 | |
84 | /** |
85 | * Get the component's HTML representation. |
86 | * |
87 | * This method generates the HTML markup for the component, incorporating relevant properties |
88 | * and any additional attributes. The component is structured using appropriate HTML elements |
89 | * as defined by the implementation. |
90 | * |
91 | * @since 0.1.0 |
92 | * @return string The generated HTML string for the component. |
93 | */ |
94 | public function __toString(): string { |
95 | return $this->content; |
96 | } |
97 | } |