Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| BaseStringL11nType | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setL11n | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| getL11n | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| toArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Localization |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Localization; |
| 16 | |
| 17 | /** |
| 18 | * String l11n class. |
| 19 | * |
| 20 | * @package phpOMS\Localization |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | class BaseStringL11nType implements \JsonSerializable |
| 26 | { |
| 27 | /** |
| 28 | * ID. |
| 29 | * |
| 30 | * @var int |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public int $id = 0; |
| 34 | |
| 35 | /** |
| 36 | * Identifier for the l11n type. |
| 37 | * |
| 38 | * @var string |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | public string $title = ''; |
| 42 | |
| 43 | /* |
| 44 | * String l11n |
| 45 | * |
| 46 | * @var string | BaseStringL11n |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | public string | BaseStringL11n $l11n = ''; |
| 50 | |
| 51 | /** |
| 52 | * Is the l11n type required for an item? |
| 53 | * |
| 54 | * @var bool |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public bool $isRequired = false; |
| 58 | |
| 59 | /** |
| 60 | * Constructor. |
| 61 | * |
| 62 | * @param string $title Title |
| 63 | * |
| 64 | * @since 1.0.0 |
| 65 | */ |
| 66 | public function __construct(string $title = '') |
| 67 | { |
| 68 | $this->title = $title; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get id |
| 73 | * |
| 74 | * @return int |
| 75 | * |
| 76 | * @since 1.0.0 |
| 77 | */ |
| 78 | public function getId() : int |
| 79 | { |
| 80 | return $this->id; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Set l11n |
| 85 | * |
| 86 | * @param string|BaseStringL11n $l11n Tag article l11n |
| 87 | * @param string $lang Language |
| 88 | * |
| 89 | * @return void |
| 90 | * |
| 91 | * @since 1.0.0 |
| 92 | */ |
| 93 | public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void |
| 94 | { |
| 95 | if ($l11n instanceof BaseStringL11n) { |
| 96 | $this->l11n = $l11n; |
| 97 | } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { |
| 98 | $this->l11n->content = $l11n; |
| 99 | $this->l11n->setLanguage($lang); |
| 100 | } else { |
| 101 | $this->l11n = new BaseStringL11n(); |
| 102 | $this->l11n->content = $l11n; |
| 103 | $this->l11n->setLanguage($lang); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @return string |
| 109 | * |
| 110 | * @since 1.0.0 |
| 111 | */ |
| 112 | public function getL11n() : string |
| 113 | { |
| 114 | if (!isset($this->l11n)) { |
| 115 | return ''; |
| 116 | } |
| 117 | |
| 118 | return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * {@inheritdoc} |
| 123 | */ |
| 124 | public function toArray() : array |
| 125 | { |
| 126 | return [ |
| 127 | 'id' => $this->id, |
| 128 | 'title' => $this->title, |
| 129 | ]; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * {@inheritdoc} |
| 134 | */ |
| 135 | public function jsonSerialize() : mixed |
| 136 | { |
| 137 | return $this->toArray(); |
| 138 | } |
| 139 | } |