1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace YiiRocks\SvgInline; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Icon class to store all icon properties. |
9
|
|
|
*/ |
10
|
|
|
class Icon implements IconInterface |
11
|
|
|
{ |
12
|
|
|
/** @var string Additional custom classes */ |
13
|
|
|
private string $class; |
14
|
|
|
|
15
|
|
|
/** @var array Additional CSS attributes */ |
16
|
|
|
private array $css; |
17
|
|
|
|
18
|
|
|
/** @var string Color of the icon. Set to empty string to disable this attribute */ |
19
|
|
|
private string $fill; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int The height of the icon. This will dismiss the automatic height |
23
|
|
|
* and width classes. If height is given without width, the latter |
24
|
|
|
* will be calculated from the SVG size |
25
|
|
|
*/ |
26
|
|
|
private int $height; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string Id for the SVG tag. |
30
|
|
|
*/ |
31
|
|
|
private string $id; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string Valid path to an SVG image |
35
|
|
|
*/ |
36
|
|
|
private string $name; |
37
|
|
|
|
38
|
|
|
/** @var null|string Sets a title to the SVG output */ |
39
|
|
|
private ?string $title = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int The width of the icon. This will dismiss the automatic height |
43
|
|
|
* and width classes. If `width` is given without `height`, the |
44
|
|
|
* latter will be calculated from the SVG size |
45
|
|
|
*/ |
46
|
|
|
private int $width; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @see $icon |
50
|
|
|
* @param string $key |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function get(string $key) |
54
|
|
|
{ |
55
|
|
|
return $this->$key ?? null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @see $name |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getTitle(): string |
63
|
|
|
{ |
64
|
|
|
return $this->title ?? ucfirst(basename($this->name, '.svg')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function setClass(string $value): void |
68
|
|
|
{ |
69
|
|
|
$this->class = $value; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setCss(array $value): void |
73
|
|
|
{ |
74
|
|
|
$this->css = $value; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setFill(string $value): void |
78
|
|
|
{ |
79
|
|
|
$this->fill = $value; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setHeight(int $value): void |
83
|
|
|
{ |
84
|
|
|
$this->height = abs($value); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setId(string $value): void |
88
|
|
|
{ |
89
|
|
|
$this->id = $value; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setName(string $value): void |
93
|
|
|
{ |
94
|
|
|
$this->name = $value; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setTitle(string $value): void |
98
|
|
|
{ |
99
|
|
|
$this->title = $value; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setWidth(int $value): void |
103
|
|
|
{ |
104
|
|
|
$this->width = abs($value); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|