|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Field\Renderer\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Field\Builder\BuilderInterface; |
|
6
|
|
|
use Graze\CiffRenderer\Field\Renderer\RendererInterface; |
|
7
|
|
|
use Graze\CiffRenderer\Field\Parser\ParserInterface; |
|
8
|
|
|
use Graze\CiffRenderer\Field\Parser\ParserManager; |
|
9
|
|
|
use Intervention\Image\ImageManager; |
|
10
|
|
|
use \SimpleXMLElement; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractRendererBuilder implements BuilderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var ParserManager |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $parserManager; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var SimpleXMLElement |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $xmlField; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ImageManager |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $imageManager; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var SimpleXMLElement |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $xmlHeader; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var callable |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $fontResolver; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var callable |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $graphicResolver; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $tracerColour; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return ParserInterface |
|
51
|
|
|
*/ |
|
52
|
|
|
abstract protected function instantiateParser(); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param ParserInterface $parser |
|
56
|
|
|
* |
|
57
|
|
|
* @return ParserInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function buildParser(ParserInterface $parser) |
|
60
|
|
|
{ |
|
61
|
|
|
$parser->setXmlField($this->getXmlField()); |
|
62
|
|
|
$parser->setParserManager($this->getParserManager()); |
|
63
|
|
|
|
|
64
|
|
|
return $parser; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param ParserInterface $parser |
|
69
|
|
|
* |
|
70
|
|
|
* @return RendererInterface |
|
71
|
|
|
*/ |
|
72
|
|
|
abstract protected function instantiateRenderer(ParserInterface $parser); |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param RendererInterface $renderer |
|
76
|
|
|
* @param ParserInterface $parser |
|
77
|
|
|
* |
|
78
|
|
|
* @return RendererInterface |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function buildRenderer(RendererInterface $renderer, ParserInterface $parser) |
|
81
|
|
|
{ |
|
82
|
|
|
$renderer->setParser($parser); |
|
83
|
|
|
$renderer->setImageManager($this->getImageManager()); |
|
84
|
|
|
$renderer->setScale($this->getScale()); |
|
85
|
|
|
$renderer->setTracerColour($this->getTracerColour()); |
|
86
|
|
|
|
|
87
|
|
|
return $renderer; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return RendererInterface |
|
92
|
|
|
*/ |
|
93
|
|
|
public function build() |
|
94
|
|
|
{ |
|
95
|
|
|
$parser = $this->instantiateParser(); |
|
96
|
|
|
|
|
97
|
|
|
$parser = $this->buildParser($parser); |
|
98
|
|
|
|
|
99
|
|
|
// store it in the manager - other parsers may depend on it |
|
100
|
|
|
$this->getParserManager()->addParser($parser); |
|
101
|
|
|
|
|
102
|
|
|
$renderer = $this->instantiateRenderer($parser); |
|
103
|
|
|
|
|
104
|
|
|
return $this->buildRenderer($renderer, $parser); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param ParserManager $parserManager |
|
109
|
|
|
*/ |
|
110
|
|
|
public function setParserManager(ParserManager $parserManager) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->parserManager = $parserManager; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return ParserManager |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function getParserManager() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->parserManager; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param SimpleXMLElement $xmlField |
|
125
|
|
|
*/ |
|
126
|
|
|
public function setXmlField(SimpleXMLElement $xmlField) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->xmlField = $xmlField; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return SimpleXMLElement |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function getXmlField() |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->xmlField; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param ImageManager $imageManager |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setImageManager(ImageManager $imageManager) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->imageManager = $imageManager; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return ImageManager |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function getImageManager() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->imageManager; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param float $scale |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setScale($scale) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->scale = $scale; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return float |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function getScale() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->scale; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param string $tracerColour |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setTracerColour($tracerColour) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->tracerColour = $tracerColour; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
|
|
protected function getTracerColour() |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->tracerColour; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param SimpleXMLElement $xmlHeader |
|
189
|
|
|
*/ |
|
190
|
|
|
public function setXmlHeader(SimpleXMLElement $xmlHeader) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->xmlHeader = $xmlHeader; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @return SimpleXMLElement |
|
197
|
|
|
*/ |
|
198
|
|
|
protected function getXmlHeader() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->xmlHeader; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @param callable $fontResolver |
|
205
|
|
|
*/ |
|
206
|
|
|
public function setFontResolver(callable $fontResolver) |
|
207
|
|
|
{ |
|
208
|
|
|
$this->fontResolver = $fontResolver; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @return callable |
|
213
|
|
|
*/ |
|
214
|
|
|
protected function getFontResolver() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->fontResolver; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param callable $graphicResolver |
|
221
|
|
|
*/ |
|
222
|
|
|
public function setGraphicResolver(callable $graphicResolver) |
|
223
|
|
|
{ |
|
224
|
|
|
$this->graphicResolver = $graphicResolver; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @return callable |
|
229
|
|
|
*/ |
|
230
|
|
|
protected function getGraphicResolver() |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->graphicResolver; |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|