-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidget.php
More file actions
61 lines (55 loc) · 2.23 KB
/
Widget.php
File metadata and controls
61 lines (55 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
/* #############################################################################
*
* █▀▀▄ ▀ █▀▀▄ █▀▀▄
* █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀
* █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █
* █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █
*
* Customizable developer toolbar for Symfony projects
*
* @author Marcin Orlowski <mail (#) marcinOrlowski (.) com>
* @copyright 2025 Marcin Orlowski
* @license https://opensource.org/license/mit MIT
* @link https://github.com/MarcinOrlowski/php-symfony-discodevbar
*
* ########################################################################## */
namespace MarcinOrlowski\DiscoDevBar\Dto;
class Widget
{
public function __construct(
public readonly string $icon,
public readonly string $text,
public readonly string $url,
public readonly string $target,
public readonly string $title,
public readonly bool $expand,
public readonly IconType $iconType = IconType::FONT_AWESOME
) {
}
/**
* Create Widget from array configuration
*
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
$icon = $data['icon'] ?? '';
$text = $data['text'] ?? '';
$url = $data['url'] ?? '';
$target = $data['target'] ?? '';
$title = $data['title'] ?? '';
$expand = $data['expand'] ?? false;
$iconType = $data['icon_type'] ?? 'fa';
return new self(
icon: \is_string($icon) ? $icon : '',
text: \is_string($text) ? $text : '',
url: \is_string($url) ? $url : '',
target: \is_string($target) ? $target : '',
title: \is_string($title) ? $title : '',
expand: \is_bool($expand) ? $expand : false,
iconType: IconType::tryFrom(\is_string($iconType) ? $iconType : 'fa') ?? IconType::FONT_AWESOME
);
}
}