1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* citeproc-php |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Sebastian Böttger. |
7
|
|
|
* @license https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\Data\DataList; |
13
|
|
|
use Seboettg\CiteProc\Locale\Locale; |
14
|
|
|
use Seboettg\CiteProc\Root\Info; |
15
|
|
|
use Seboettg\CiteProc\Style\Bibliography; |
16
|
|
|
use Seboettg\CiteProc\Style\Citation; |
17
|
|
|
use Seboettg\CiteProc\Style\Macro; |
18
|
|
|
use Seboettg\CiteProc\Style\Options\BibliographyOptions; |
19
|
|
|
use Seboettg\CiteProc\Style\Options\CitationOptions; |
20
|
|
|
use Seboettg\CiteProc\Style\Options\GlobalOptions; |
21
|
|
|
use Seboettg\CiteProc\Style\Sort\Sort; |
22
|
|
|
use Seboettg\CiteProc\Root\Root; |
23
|
|
|
use Seboettg\CiteProc\Styles\Css\CssStyle; |
24
|
|
|
use Seboettg\Collection\ArrayList; |
25
|
|
|
use Seboettg\Collection\Lists\ListInterface; |
26
|
|
|
use Seboettg\Collection\Map\MapInterface; |
27
|
|
|
use function Seboettg\Collection\Map\emptyMap; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class Context |
31
|
|
|
* @package Seboettg\CiteProc |
32
|
|
|
* |
33
|
|
|
* @author Sebastian Böttger <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class Context |
36
|
|
|
{ |
37
|
|
|
private MapInterface $macros; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Locale |
41
|
|
|
*/ |
42
|
|
|
private $locale; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Bibliography |
46
|
|
|
*/ |
47
|
|
|
private $bibliography; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Citation |
51
|
|
|
*/ |
52
|
|
|
private $citation; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var Sort |
56
|
|
|
*/ |
57
|
|
|
private $sorting; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $mode; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var DataList |
66
|
|
|
*/ |
67
|
|
|
private $citationData; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var ArrayList |
71
|
|
|
*/ |
72
|
|
|
private $citationItems; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var ArrayList |
76
|
|
|
*/ |
77
|
|
|
private $results; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var Root |
81
|
|
|
*/ |
82
|
|
|
private $root; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var GlobalOptions |
86
|
|
|
*/ |
87
|
|
|
private $globalOptions; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var BibliographyOptions |
91
|
|
|
*/ |
92
|
|
|
private $bibliographySpecificOptions; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var CitationOptions |
96
|
|
|
*/ |
97
|
|
|
private $citationSpecificOptions; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var RenderingState |
101
|
|
|
*/ |
102
|
|
|
private $renderingState; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var CssStyle |
106
|
|
|
*/ |
107
|
|
|
private $cssStyle; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var Info |
111
|
|
|
*/ |
112
|
|
|
private $info; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var array |
116
|
|
|
*/ |
117
|
|
|
protected $markupExtension = []; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var bool |
121
|
|
|
*/ |
122
|
|
|
private $citationsAsArray = false; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var ArrayList |
126
|
|
|
*/ |
127
|
|
|
private $citedItems; |
128
|
|
|
|
129
|
|
|
public function __construct($locale = null) |
130
|
|
|
{ |
131
|
|
|
if (!empty($locale)) { |
132
|
|
|
$this->locale = $locale; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->macros = emptyMap(); |
136
|
|
|
$this->citationData = new DataList(); |
137
|
|
|
$this->results = new ArrayList(); |
138
|
|
|
$this->renderingState = RenderingState::RENDERING(); |
139
|
|
|
$this->citedItems = new ArrayList(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function addMacro(string $key, Macro $macro): void |
143
|
|
|
{ |
144
|
|
|
$this->macros->put($key, $macro); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getMacro(string $key): ?Macro |
148
|
|
|
{ |
149
|
|
|
return $this->macros->get($key); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param Locale $locale |
154
|
|
|
*/ |
155
|
|
|
public function setLocale(Locale $locale) |
156
|
|
|
{ |
157
|
|
|
$this->locale = $locale; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return Locale |
162
|
|
|
*/ |
163
|
|
|
public function getLocale() |
164
|
|
|
{ |
165
|
|
|
return $this->locale; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return Bibliography |
170
|
|
|
*/ |
171
|
|
|
public function getBibliography() |
172
|
|
|
{ |
173
|
|
|
return $this->bibliography; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param Bibliography $bibliography |
178
|
|
|
*/ |
179
|
|
|
public function setBibliography(Bibliography $bibliography) |
180
|
|
|
{ |
181
|
|
|
$this->bibliography = $bibliography; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return Citation |
186
|
|
|
*/ |
187
|
|
|
public function getCitation() |
188
|
|
|
{ |
189
|
|
|
return $this->citation; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param Citation $citation |
194
|
|
|
*/ |
195
|
|
|
public function setCitation($citation) |
196
|
|
|
{ |
197
|
|
|
$this->citation = $citation; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param $citationsAsArray |
202
|
|
|
*/ |
203
|
|
|
public function setCitationsAsArray($citationsAsArray = true) |
204
|
|
|
{ |
205
|
|
|
$this->citationsAsArray = $citationsAsArray; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function isCitationsAsArray() |
209
|
|
|
{ |
210
|
|
|
return $this->citationsAsArray; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function setSorting($sorting) |
214
|
|
|
{ |
215
|
|
|
$this->sorting = $sorting; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function getSorting() |
219
|
|
|
{ |
220
|
|
|
return $this->sorting; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* return the render mode (citation|bibliography) |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function getMode() |
228
|
|
|
{ |
229
|
|
|
return $this->mode; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param string $mode |
234
|
|
|
*/ |
235
|
|
|
public function setMode($mode) |
236
|
|
|
{ |
237
|
|
|
$this->mode = $mode; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* returns true if the render mode is set to citation |
242
|
|
|
* @return bool |
243
|
|
|
*/ |
244
|
|
|
public function isModeCitation() |
245
|
|
|
{ |
246
|
|
|
return $this->mode === "citation"; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* returns true if the render mode is set to bibliography |
251
|
|
|
* @return bool |
252
|
|
|
*/ |
253
|
|
|
public function isModeBibliography() |
254
|
|
|
{ |
255
|
|
|
return $this->mode === "bibliography"; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return DataList |
260
|
|
|
*/ |
261
|
|
|
public function getCitationData() |
262
|
|
|
{ |
263
|
|
|
return $this->citationData; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param DataList $citationData |
268
|
|
|
*/ |
269
|
|
|
public function setCitationData($citationData) |
270
|
|
|
{ |
271
|
|
|
$this->citationData = $citationData; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return ArrayList |
276
|
|
|
*/ |
277
|
|
|
public function getCitationItems(): ArrayList |
278
|
|
|
{ |
279
|
|
|
return $this->citationItems; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function setCitationItems(ListInterface $citationItems): void |
283
|
|
|
{ |
284
|
|
|
$this->citationItems = $citationItems; |
|
|
|
|
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function hasCitationItems() |
288
|
|
|
{ |
289
|
|
|
return $this->citationData->isNotEmpty(); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function getMacros(): MapInterface |
293
|
|
|
{ |
294
|
|
|
return $this->macros; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return ArrayList |
299
|
|
|
*/ |
300
|
|
|
public function getResults() |
301
|
|
|
{ |
302
|
|
|
return $this->results; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return Root |
307
|
|
|
*/ |
308
|
|
|
public function getRoot() |
309
|
|
|
{ |
310
|
|
|
return $this->root; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param Root $root |
315
|
|
|
*/ |
316
|
|
|
public function setRoot(Root $root) |
317
|
|
|
{ |
318
|
|
|
$this->root = $root; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @return GlobalOptions |
323
|
|
|
*/ |
324
|
|
|
public function getGlobalOptions() |
325
|
|
|
{ |
326
|
|
|
return $this->globalOptions; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @param GlobalOptions $globalOptions |
331
|
|
|
*/ |
332
|
|
|
public function setGlobalOptions(GlobalOptions $globalOptions) |
333
|
|
|
{ |
334
|
|
|
$this->globalOptions = $globalOptions; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @return RenderingState |
339
|
|
|
*/ |
340
|
|
|
public function getRenderingState() |
341
|
|
|
{ |
342
|
|
|
return $this->renderingState; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param RenderingState|string $renderingState |
347
|
|
|
*/ |
348
|
|
|
public function setRenderingState(RenderingState $renderingState) |
349
|
|
|
{ |
350
|
|
|
$this->renderingState = $renderingState; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @return BibliographyOptions |
355
|
|
|
*/ |
356
|
|
|
public function getBibliographySpecificOptions() |
357
|
|
|
{ |
358
|
|
|
return $this->bibliographySpecificOptions; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @param BibliographyOptions $bibliographySpecificOptions |
363
|
|
|
*/ |
364
|
|
|
public function setBibliographySpecificOptions(BibliographyOptions $bibliographySpecificOptions) |
365
|
|
|
{ |
366
|
|
|
$this->bibliographySpecificOptions = $bibliographySpecificOptions; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @return CitationOptions |
371
|
|
|
*/ |
372
|
|
|
public function getCitationSpecificOptions() |
373
|
|
|
{ |
374
|
|
|
return $this->citationSpecificOptions; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @param CitationOptions $citationSpecificOptions |
379
|
|
|
*/ |
380
|
|
|
public function setCitationSpecificOptions(CitationOptions $citationSpecificOptions) |
381
|
|
|
{ |
382
|
|
|
$this->citationSpecificOptions = $citationSpecificOptions; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @param CssStyle $cssStyle |
387
|
|
|
*/ |
388
|
|
|
public function setCssStyle(CssStyle $cssStyle) |
389
|
|
|
{ |
390
|
|
|
$this->cssStyle = $cssStyle; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @return CssStyle |
395
|
|
|
*/ |
396
|
|
|
public function getCssStyle() |
397
|
|
|
{ |
398
|
|
|
return $this->cssStyle; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function setInfo(Info $info) |
402
|
|
|
{ |
403
|
|
|
$this->info = $info; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
public function getInfo() |
407
|
|
|
{ |
408
|
|
|
return $this->info; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* @return array |
413
|
|
|
*/ |
414
|
|
|
public function getMarkupExtension() |
415
|
|
|
{ |
416
|
|
|
return $this->markupExtension; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* @param array $markupExtension |
421
|
|
|
*/ |
422
|
|
|
public function setMarkupExtension($markupExtension) |
423
|
|
|
{ |
424
|
|
|
$this->markupExtension = $markupExtension; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
public function getCitationItemById($id) |
428
|
|
|
{ |
429
|
|
|
return $this->citationItems->filter(function ($item) use ($id) { |
430
|
|
|
return $item->id === $id; |
431
|
|
|
})->current(); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @return ArrayList |
436
|
|
|
*/ |
437
|
|
|
public function getCitedItems(): ArrayList |
438
|
|
|
{ |
439
|
|
|
return $this->citedItems; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @param ArrayList $citedItems |
444
|
|
|
*/ |
445
|
|
|
public function setCitedItems(ArrayList $citedItems): void |
446
|
|
|
{ |
447
|
|
|
$this->citedItems = $citedItems; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
public function appendCitedItem($citedItem) |
451
|
|
|
{ |
452
|
|
|
$this->citedItems->add($citedItem); |
453
|
|
|
return $this; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.