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
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class Context |
28
|
|
|
* @package Seboettg\CiteProc |
29
|
|
|
* |
30
|
|
|
* @author Sebastian Böttger <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class Context |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var ArrayList |
36
|
|
|
*/ |
37
|
|
|
private $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
|
179 |
|
public function __construct($locale = null) |
|
|
|
|
130
|
|
|
{ |
131
|
179 |
|
if (!empty($locale)) { |
132
|
|
|
$this->locale = $locale; |
133
|
|
|
} |
134
|
|
|
|
135
|
179 |
|
$this->macros = new ArrayList(); |
136
|
179 |
|
$this->citationData = new DataList(); |
137
|
179 |
|
$this->results = new ArrayList(); |
138
|
179 |
|
$this->renderingState = RenderingState::RENDERING(); |
139
|
179 |
|
$this->citedItems = new ArrayList(); |
140
|
179 |
|
} |
141
|
|
|
|
142
|
69 |
|
public function addMacro($key, $macro) |
143
|
|
|
{ |
144
|
69 |
|
$this->macros->add($key, $macro); |
145
|
69 |
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param $key |
149
|
|
|
* @return Macro |
150
|
|
|
*/ |
151
|
63 |
|
public function getMacro($key) |
152
|
|
|
{ |
153
|
63 |
|
return $this->macros->get($key); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param Locale $locale |
158
|
|
|
*/ |
159
|
178 |
|
public function setLocale(Locale $locale) |
160
|
|
|
{ |
161
|
178 |
|
$this->locale = $locale; |
162
|
178 |
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return Locale |
166
|
|
|
*/ |
167
|
129 |
|
public function getLocale() |
168
|
|
|
{ |
169
|
129 |
|
return $this->locale; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return Bibliography |
174
|
|
|
*/ |
175
|
77 |
|
public function getBibliography() |
176
|
|
|
{ |
177
|
77 |
|
return $this->bibliography; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param Bibliography $bibliography |
182
|
|
|
*/ |
183
|
84 |
|
public function setBibliography(Bibliography $bibliography) |
184
|
|
|
{ |
185
|
84 |
|
$this->bibliography = $bibliography; |
186
|
84 |
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return Citation |
190
|
|
|
*/ |
191
|
161 |
|
public function getCitation() |
192
|
|
|
{ |
193
|
161 |
|
return $this->citation; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param Citation $citation |
198
|
|
|
*/ |
199
|
158 |
|
public function setCitation($citation) |
200
|
|
|
{ |
201
|
158 |
|
$this->citation = $citation; |
202
|
158 |
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param $citationsAsArray |
206
|
|
|
*/ |
207
|
169 |
|
public function setCitationsAsArray($citationsAsArray = true) |
|
|
|
|
208
|
|
|
{ |
209
|
169 |
|
$this->citationsAsArray = $citationsAsArray; |
210
|
169 |
|
} |
211
|
|
|
|
212
|
1 |
|
public function isCitationsAsArray() |
213
|
|
|
{ |
214
|
1 |
|
return $this->citationsAsArray; |
215
|
|
|
} |
216
|
|
|
|
217
|
60 |
|
public function setSorting($sorting) |
218
|
|
|
{ |
219
|
60 |
|
$this->sorting = $sorting; |
220
|
60 |
|
} |
221
|
|
|
|
222
|
165 |
|
public function getSorting() |
223
|
|
|
{ |
224
|
165 |
|
return $this->sorting; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* return the render mode (citation|bibliography) |
229
|
|
|
* @return string |
230
|
|
|
*/ |
231
|
173 |
|
public function getMode() |
232
|
|
|
{ |
233
|
173 |
|
return $this->mode; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param string $mode |
238
|
|
|
*/ |
239
|
165 |
|
public function setMode($mode) |
240
|
|
|
{ |
241
|
165 |
|
$this->mode = $mode; |
242
|
165 |
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* returns true if the render mode is set to citation |
246
|
|
|
* @return bool |
247
|
|
|
*/ |
248
|
132 |
|
public function isModeCitation() |
249
|
|
|
{ |
250
|
132 |
|
return $this->mode === "citation"; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* returns true if the render mode is set to bibliography |
255
|
|
|
* @return bool |
256
|
|
|
*/ |
257
|
165 |
|
public function isModeBibliography() |
258
|
|
|
{ |
259
|
165 |
|
return $this->mode === "bibliography"; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @return DataList |
264
|
|
|
*/ |
265
|
103 |
|
public function getCitationData() |
266
|
|
|
{ |
267
|
103 |
|
return $this->citationData; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param ArrayList|DataList $citationData |
272
|
|
|
*/ |
273
|
78 |
|
public function setCitationData($citationData) |
274
|
|
|
{ |
275
|
78 |
|
$this->citationData = $citationData; |
276
|
78 |
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @return ArrayList |
280
|
|
|
*/ |
281
|
|
|
public function getCitationItems(): ArrayList |
282
|
|
|
{ |
283
|
|
|
return $this->citationItems; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @param ArrayList $citationItems |
288
|
|
|
*/ |
289
|
104 |
|
public function setCitationItems(ArrayList $citationItems): void |
290
|
|
|
{ |
291
|
104 |
|
$this->citationItems = $citationItems; |
292
|
104 |
|
} |
293
|
|
|
|
294
|
|
|
public function hasCitationItems() |
295
|
|
|
{ |
296
|
|
|
return ($this->citationData->count() > 0); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @return ArrayList |
301
|
|
|
*/ |
302
|
|
|
public function getMacros() |
303
|
|
|
{ |
304
|
|
|
return $this->macros; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @return ArrayList |
309
|
|
|
*/ |
310
|
165 |
|
public function getResults() |
311
|
|
|
{ |
312
|
165 |
|
return $this->results; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return Root |
317
|
|
|
*/ |
318
|
169 |
|
public function getRoot() |
319
|
|
|
{ |
320
|
169 |
|
return $this->root; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param Root $root |
325
|
|
|
*/ |
326
|
169 |
|
public function setRoot(Root $root) |
327
|
|
|
{ |
328
|
169 |
|
$this->root = $root; |
329
|
169 |
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @return GlobalOptions |
333
|
|
|
*/ |
334
|
107 |
|
public function getGlobalOptions() |
335
|
|
|
{ |
336
|
107 |
|
return $this->globalOptions; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @param GlobalOptions $globalOptions |
341
|
|
|
*/ |
342
|
169 |
|
public function setGlobalOptions(GlobalOptions $globalOptions) |
343
|
|
|
{ |
344
|
169 |
|
$this->globalOptions = $globalOptions; |
345
|
169 |
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @return RenderingState |
349
|
|
|
*/ |
350
|
140 |
|
public function getRenderingState() |
351
|
|
|
{ |
352
|
140 |
|
return $this->renderingState; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @param RenderingState|string $renderingState |
357
|
|
|
*/ |
358
|
63 |
|
public function setRenderingState(RenderingState $renderingState) |
359
|
|
|
{ |
360
|
63 |
|
$this->renderingState = $renderingState; |
361
|
63 |
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @return BibliographyOptions |
365
|
|
|
*/ |
366
|
168 |
|
public function getBibliographySpecificOptions() |
367
|
|
|
{ |
368
|
168 |
|
return $this->bibliographySpecificOptions; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @param BibliographyOptions $bibliographySpecificOptions |
373
|
|
|
*/ |
374
|
84 |
|
public function setBibliographySpecificOptions(BibliographyOptions $bibliographySpecificOptions) |
375
|
|
|
{ |
376
|
84 |
|
$this->bibliographySpecificOptions = $bibliographySpecificOptions; |
377
|
84 |
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @return CitationOptions |
381
|
|
|
*/ |
382
|
|
|
public function getCitationSpecificOptions() |
383
|
|
|
{ |
384
|
|
|
return $this->citationSpecificOptions; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @param CitationOptions $citationSpecificOptions |
389
|
|
|
*/ |
390
|
158 |
|
public function setCitationSpecificOptions(CitationOptions $citationSpecificOptions) |
391
|
|
|
{ |
392
|
158 |
|
$this->citationSpecificOptions = $citationSpecificOptions; |
393
|
158 |
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @param CssStyle $cssStyle |
397
|
|
|
*/ |
398
|
3 |
|
public function setCssStyle(CssStyle $cssStyle) |
399
|
|
|
{ |
400
|
3 |
|
$this->cssStyle = $cssStyle; |
401
|
3 |
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @return CssStyle |
405
|
|
|
*/ |
406
|
3 |
|
public function getCssStyle() |
407
|
|
|
{ |
408
|
3 |
|
return $this->cssStyle; |
409
|
|
|
} |
410
|
|
|
|
411
|
161 |
|
public function setInfo(Info $info) |
412
|
|
|
{ |
413
|
161 |
|
$this->info = $info; |
414
|
161 |
|
} |
415
|
|
|
|
416
|
1 |
|
public function getInfo() |
417
|
|
|
{ |
418
|
1 |
|
return $this->info; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @return array |
423
|
|
|
*/ |
424
|
169 |
|
public function getMarkupExtension() |
425
|
|
|
{ |
426
|
169 |
|
return $this->markupExtension; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param array $markupExtension |
431
|
|
|
*/ |
432
|
169 |
|
public function setMarkupExtension($markupExtension) |
433
|
|
|
{ |
434
|
169 |
|
$this->markupExtension = $markupExtension; |
435
|
169 |
|
} |
436
|
|
|
|
437
|
12 |
|
public function getCitationItemById($id) |
438
|
|
|
{ |
439
|
|
|
return $this->citationItems->filter(function ($item) use ($id) { |
440
|
7 |
|
return $item->id === $id; |
441
|
12 |
|
})->current(); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @return ArrayList |
446
|
|
|
*/ |
447
|
1 |
|
public function getCitedItems(): ArrayList |
448
|
|
|
{ |
449
|
1 |
|
return $this->citedItems; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @param ArrayList $citedItems |
454
|
|
|
*/ |
455
|
|
|
public function setCitedItems(ArrayList $citedItems): void |
456
|
|
|
{ |
457
|
|
|
$this->citedItems = $citedItems; |
458
|
|
|
} |
459
|
|
|
|
460
|
104 |
|
public function appendCitedItem($citedItem) |
461
|
|
|
{ |
462
|
104 |
|
$this->citedItems->append($citedItem); |
463
|
104 |
|
return $this; |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|