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