|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Derafu: Biblioteca PHP (Núcleo). |
|
7
|
|
|
* Copyright (C) Derafu <https://www.derafu.org> |
|
8
|
|
|
* |
|
9
|
|
|
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo |
|
10
|
|
|
* bajo los términos de la Licencia Pública General Affero de GNU publicada por |
|
11
|
|
|
* la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o |
|
12
|
|
|
* (a su elección) cualquier versión posterior de la misma. |
|
13
|
|
|
* |
|
14
|
|
|
* Este programa se distribuye con la esperanza de que sea útil, pero SIN |
|
15
|
|
|
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD |
|
16
|
|
|
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública |
|
17
|
|
|
* General Affero de GNU para obtener una información más detallada. |
|
18
|
|
|
* |
|
19
|
|
|
* Debería haber recibido una copia de la Licencia Pública General Affero de GNU |
|
20
|
|
|
* junto a este programa. |
|
21
|
|
|
* |
|
22
|
|
|
* En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Derafu\Lib\Core\Package\Prime\Component\Template\Entity; |
|
26
|
|
|
|
|
27
|
|
|
use Derafu\Lib\Core\Package\Prime\Component\Template\Contract\DataInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Entidad que reprenta el dato de una variable en una plantilla. |
|
31
|
|
|
* |
|
32
|
|
|
* Esta clase permitirá realizar un manejo sobre el dato y entregarlo de una |
|
33
|
|
|
* forma estandarizada para su uso en la plantilla. |
|
34
|
|
|
*/ |
|
35
|
|
|
class Data implements DataInterface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Identificador del dato representado. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private string $id; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Valor del dato. |
|
46
|
|
|
* |
|
47
|
|
|
* @var mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
private mixed $value; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Representación formateada del dato. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string|null |
|
55
|
|
|
*/ |
|
56
|
|
|
private ?string $formatted; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor de la entidad. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $id |
|
62
|
|
|
* @param mixed $value |
|
63
|
|
|
* @param string|null $formatted |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function __construct(string $id, mixed $value, string $formatted = null) |
|
66
|
|
|
{ |
|
67
|
2 |
|
$this->id = $id; |
|
68
|
2 |
|
$this->value = $value; |
|
69
|
2 |
|
$this->formatted = $formatted; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Entrega el string formateado del valor de este dato. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __toString(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->formatted; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @inheritDoc |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getId(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->id; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @inheritDoc |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getValue(): mixed |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->value; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @inheritDoc |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setFormatted(string $formatted): static |
|
102
|
|
|
{ |
|
103
|
|
|
$this->formatted = $formatted; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritDoc |
|
110
|
|
|
*/ |
|
111
|
2 |
|
public function getFormatted(): string |
|
112
|
|
|
{ |
|
113
|
2 |
|
return $this->formatted ?? (string) $this->value; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|