Completed
Push — master ( bf66ca...210cc2 )
by Sebastian
05:53
created

Context::setCitationsAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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