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