1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ReliqArts\StyleImporter\CSS\Generator; |
6
|
|
|
|
7
|
|
|
use ReliqArts\StyleImporter\CSS\MediaBlock; |
8
|
|
|
use ReliqArts\StyleImporter\CSS\Rule\FontFace; |
9
|
|
|
use ReliqArts\StyleImporter\CSS\Rule\Import; |
10
|
|
|
|
11
|
|
|
final class Context |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $sanitizedStyles; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string[] |
20
|
|
|
*/ |
21
|
|
|
private $htmlElements; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Import[] |
25
|
|
|
*/ |
26
|
|
|
private $importRules; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var FontFace[] |
30
|
|
|
*/ |
31
|
|
|
private $fontFaceRules; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var MediaBlock[] |
35
|
|
|
*/ |
36
|
|
|
private $mediaBlocks; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Context constructor. |
40
|
|
|
* |
41
|
|
|
* @param string $sanitizedStyles |
42
|
|
|
* @param string ...$htmlElements |
43
|
|
|
*/ |
44
|
|
|
public function __construct(string $sanitizedStyles, string ...$htmlElements) |
45
|
|
|
{ |
46
|
|
|
$this->sanitizedStyles = $sanitizedStyles; |
47
|
|
|
$this->htmlElements = $htmlElements; |
48
|
|
|
$this->importRules = []; |
49
|
|
|
$this->fontFaceRules = []; |
50
|
|
|
$this->mediaBlocks = []; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Import ...$importRules |
55
|
|
|
* |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
|
|
public function withImportRules(Import ...$importRules): self |
59
|
|
|
{ |
60
|
|
|
$this->importRules = $importRules; |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param FontFace ...$fontFaceRules |
67
|
|
|
* |
68
|
|
|
* @return self |
69
|
|
|
*/ |
70
|
|
|
public function withFontFaceRules(FontFace ...$fontFaceRules): self |
71
|
|
|
{ |
72
|
|
|
$this->fontFaceRules = $fontFaceRules; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param MediaBlock ...$mediaBlocks |
79
|
|
|
* |
80
|
|
|
* @return self |
81
|
|
|
*/ |
82
|
|
|
public function withMediaBlocks(MediaBlock ...$mediaBlocks): self |
83
|
|
|
{ |
84
|
|
|
$this->mediaBlocks = $mediaBlocks; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getSanitizedStyles(): string |
93
|
|
|
{ |
94
|
|
|
return $this->sanitizedStyles; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string[] |
99
|
|
|
*/ |
100
|
|
|
public function getHtmlElements(): array |
101
|
|
|
{ |
102
|
|
|
return $this->htmlElements; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return Import[] |
107
|
|
|
*/ |
108
|
|
|
public function getImportRules(): array |
109
|
|
|
{ |
110
|
|
|
return $this->importRules; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return FontFace[] |
115
|
|
|
*/ |
116
|
|
|
public function getFontFaceRules(): array |
117
|
|
|
{ |
118
|
|
|
return $this->fontFaceRules; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return MediaBlock[] |
123
|
|
|
*/ |
124
|
|
|
public function getMediaBlocks(): array |
125
|
|
|
{ |
126
|
|
|
return $this->mediaBlocks; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|