| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tableberg\Renderer\Attrs; |
| 4 |
|
| 5 |
use function Tableberg\Renderer\getOrNull; |
| 6 |
|
| 7 |
class SvgIconAttrs { |
| 8 |
/** @var StringAttr */ |
| 9 |
public $viewBox; |
| 10 |
|
| 11 |
/** @var StringAttr */ |
| 12 |
public $path; |
| 13 |
|
| 14 |
/** |
| 15 |
* @param array<string, mixed>|null $data |
| 16 |
* @param array<string, mixed> $defaults |
| 17 |
* @param string $fallbackViewBox |
| 18 |
* @param string $fallbackPath |
| 19 |
* @return self |
| 20 |
*/ |
| 21 |
public static function from_array( |
| 22 |
$data, |
| 23 |
$defaults = [], |
| 24 |
$fallbackViewBox = '0 0 24 24', |
| 25 |
$fallbackPath = '' |
| 26 |
) { |
| 27 |
$data = is_array($data) ? $data : []; |
| 28 |
|
| 29 |
$defaultViewBox = getOrNull($defaults['viewBox']); |
| 30 |
$defaultPath = getOrNull($defaults['path']); |
| 31 |
|
| 32 |
$instance = new self(); |
| 33 |
$instance->viewBox = new StringAttr( |
| 34 |
getOrNull($data['viewBox']), |
| 35 |
$defaultViewBox |
| 36 |
); |
| 37 |
$instance->path = new StringAttr( |
| 38 |
getOrNull($data['path']), |
| 39 |
$defaultPath |
| 40 |
); |
| 41 |
|
| 42 |
return $instance; |
| 43 |
} |
| 44 |
} |
| 45 |
|