1 | <?php |
||
10 | class Component implements IComponent |
||
11 | { |
||
12 | const ATTRIBUTE_CLASS = 'class'; |
||
13 | |||
14 | /** @var string|IComponent */ |
||
15 | protected $content; |
||
16 | |||
17 | /** @var string|null */ |
||
18 | protected $tag; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $attributes = []; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $indentation = ''; |
||
25 | |||
26 | /** @var ITranslator */ |
||
27 | protected $translator; |
||
28 | |||
29 | /** |
||
30 | * Component constructor. |
||
31 | * |
||
32 | * @param string $content |
||
33 | * @param string|null $tag |
||
34 | * @param array $attributes |
||
35 | * @param ITranslator|null $translator |
||
36 | */ |
||
37 | 125 | public function __construct( |
|
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getContent(): string |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | 16 | public function getAttributes(): array |
|
64 | |||
65 | /** |
||
66 | * @param string $attribute |
||
67 | * @param string $valueToAppend |
||
68 | */ |
||
69 | 44 | public function appendToAttribute(string $attribute, string $valueToAppend) |
|
82 | |||
83 | /** |
||
84 | * @param int $num |
||
85 | * @param string $whitespace |
||
86 | */ |
||
87 | public function setIndentation(int $num, string $whitespace = ' ') |
||
91 | |||
92 | /** |
||
93 | * @param ITranslator $translator |
||
94 | */ |
||
95 | 4 | public function setTranslator(ITranslator $translator) |
|
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | 18 | public function __toString(): string |
|
117 | } |
||
118 | |||
119 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: