|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* citeproc-php |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
|
6
|
|
|
* @copyright Copyright (c) 2017 Sebastian Böttger. |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Style\Options; |
|
11
|
|
|
|
|
12
|
|
|
use SimpleXMLElement; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class GlobalOptionsTrait |
|
16
|
|
|
* @package Seboettg\CiteProc\Style |
|
17
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class BibliographyOptions implements StyleOptions |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* If set, the value of this attribute replaces names in a bibliographic entry that also occur in the preceding |
|
24
|
|
|
* entry. The exact method of substitution depends on the value of the subsequent-author-substitute-rule attribute. |
|
25
|
|
|
* Substitution is limited to the names of the first cs:names element rendered. (Bibliography-specific option) |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $subsequentAuthorSubstitute; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Specifies when and how names are substituted as a result of subsequent-author-substitute. |
|
33
|
|
|
* (Bibliography-specific option) |
|
34
|
|
|
* |
|
35
|
|
|
* @var SubsequentAuthorSubstituteRule |
|
36
|
|
|
*/ |
|
37
|
|
|
private $subsequentAuthorSubstituteRule; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* If set to “true” (“false” is the default), bibliographic entries are rendered with hanging-indents. |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $hangingIndent; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* If set, subsequent lines of bibliographic entries are aligned along the second field. With “flush”, the first |
|
47
|
|
|
* field is flush with the margin. With “margin”, the first field is put in the margin, and subsequent lines are |
|
48
|
|
|
* aligned with the margin. |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
private $secondFieldAlign; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Specifies vertical line distance. Defaults to “1” (single-spacing), and can be set to any positive integer to |
|
55
|
|
|
* specify a multiple of the standard unit of line height (e.g. “2” for double-spacing). |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $lineSpacing; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Specifies vertical distance between bibliographic entries. By default (with a value of “1”), entries are |
|
62
|
|
|
* separated by a single additional line-height (as set by the line-spacing attribute). Can be set to any |
|
63
|
|
|
* non-negative integer to specify a multiple of this amount. |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
private $entrySpacing; |
|
67
|
|
|
|
|
68
|
87 |
|
public static function factory(SimpleXMLElement $node): BibliographyOptions |
|
69
|
|
|
{ |
|
70
|
|
|
$subsequentAuthorSubstitute = $subsequentAuthorSubstituteRule = |
|
71
|
87 |
|
$secondFieldAlign = $lineSpacing = $entrySpacing = null; |
|
72
|
87 |
|
$hangingIndent = false; |
|
73
|
|
|
/** @var SimpleXMLElement $attribute */ |
|
74
|
87 |
|
foreach ($node->attributes() as $attribute) { |
|
75
|
69 |
|
switch ($attribute->getName()) { |
|
76
|
69 |
|
case 'subsequent-author-substitute': |
|
77
|
13 |
|
$subsequentAuthorSubstitute = (string) $attribute; |
|
78
|
13 |
|
break; |
|
79
|
67 |
|
case 'subsequent-author-substitute-rule': |
|
80
|
4 |
|
$subsequentAuthorSubstituteRule = new SubsequentAuthorSubstituteRule((string) $attribute); |
|
81
|
4 |
|
break; |
|
82
|
63 |
|
case 'hanging-indent': |
|
83
|
36 |
|
$hangingIndent = "true" === (string) $attribute; |
|
84
|
36 |
|
break; |
|
85
|
61 |
|
case 'second-field-align': |
|
86
|
14 |
|
$secondFieldAlign = (string) $attribute; |
|
87
|
14 |
|
break; |
|
88
|
61 |
|
case 'line-spacing': |
|
89
|
21 |
|
$lineSpacing = (string) $attribute; |
|
90
|
21 |
|
break; |
|
91
|
61 |
|
case 'entry-spacing': |
|
92
|
69 |
|
$entrySpacing = (string) $attribute; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
87 |
|
if (empty($subsequentAuthorSubstituteRule)) { |
|
96
|
83 |
|
$subsequentAuthorSubstituteRule = new SubsequentAuthorSubstituteRule("complete-all"); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
87 |
|
return new BibliographyOptions( |
|
100
|
87 |
|
$subsequentAuthorSubstitute, |
|
101
|
87 |
|
$subsequentAuthorSubstituteRule, |
|
102
|
87 |
|
$hangingIndent, |
|
103
|
87 |
|
$secondFieldAlign, |
|
104
|
87 |
|
$lineSpacing, |
|
105
|
87 |
|
$entrySpacing |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
87 |
|
public function __construct( |
|
110
|
|
|
?string $subsequentAuthorSubstitute, |
|
111
|
|
|
?SubsequentAuthorSubstituteRule $subsequentAuthorSubstituteRule, |
|
112
|
|
|
bool $hangingIndent, |
|
113
|
|
|
?string $secondFieldAlign, |
|
114
|
|
|
?string $lineSpacing, |
|
115
|
|
|
?string $entrySpacing |
|
116
|
|
|
) { |
|
117
|
87 |
|
$this->subsequentAuthorSubstitute = $subsequentAuthorSubstitute; |
|
118
|
87 |
|
$this->subsequentAuthorSubstituteRule = $subsequentAuthorSubstituteRule; |
|
119
|
87 |
|
$this->hangingIndent = $hangingIndent; |
|
|
|
|
|
|
120
|
87 |
|
$this->secondFieldAlign = $secondFieldAlign; |
|
121
|
87 |
|
$this->lineSpacing = $lineSpacing; |
|
122
|
87 |
|
$this->entrySpacing = $entrySpacing; |
|
123
|
87 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
80 |
|
public function getSubsequentAuthorSubstitute(): ?string |
|
129
|
|
|
{ |
|
130
|
80 |
|
return $this->subsequentAuthorSubstitute; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return SubsequentAuthorSubstituteRule |
|
135
|
|
|
*/ |
|
136
|
80 |
|
public function getSubsequentAuthorSubstituteRule(): ?SubsequentAuthorSubstituteRule |
|
137
|
|
|
{ |
|
138
|
80 |
|
return $this->subsequentAuthorSubstituteRule; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return bool |
|
143
|
|
|
*/ |
|
144
|
3 |
|
public function getHangingIndent(): ?bool |
|
145
|
|
|
{ |
|
146
|
3 |
|
return $this->hangingIndent; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
83 |
|
public function getSecondFieldAlign(): ?string |
|
153
|
|
|
{ |
|
154
|
83 |
|
return $this->secondFieldAlign; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
3 |
|
public function getLineSpacing(): ?string |
|
161
|
|
|
{ |
|
162
|
3 |
|
return $this->lineSpacing; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return string |
|
167
|
|
|
*/ |
|
168
|
3 |
|
public function getEntrySpacing(): ?string |
|
169
|
|
|
{ |
|
170
|
3 |
|
return $this->entrySpacing; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.