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\Style; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
13
|
|
|
use Seboettg\CiteProc\Exception\InvalidStylesheetException; |
14
|
|
|
use Seboettg\CiteProc\Rendering\Layout; |
15
|
|
|
use Seboettg\CiteProc\Root\Root; |
16
|
|
|
use Seboettg\CiteProc\Style\Sort\Sort; |
17
|
|
|
use SimpleXMLElement; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class StyleElement |
21
|
|
|
* |
22
|
|
|
* StyleElement is an abstract class which must be extended by Citation and Bibliography class. The constructor |
23
|
|
|
* of StyleElement class parses the cs:layout element (necessary for cs:citation and cs:bibliography) and the optional |
24
|
|
|
* cs:sort element. |
25
|
|
|
* |
26
|
|
|
* @package Seboettg\CiteProc\Style |
27
|
|
|
* |
28
|
|
|
* @author Sebastian Böttger <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
abstract class StyleElement |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
use InheritableNameAttributesTrait; |
34
|
|
|
/** |
35
|
|
|
* @var Layout |
36
|
|
|
*/ |
37
|
|
|
protected $layout; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $doNotSort; |
43
|
|
|
|
44
|
|
|
protected $parent; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Parses the configuration. |
48
|
|
|
* |
49
|
|
|
* @param SimpleXMLElement $node |
50
|
|
|
* @param Root $parent |
51
|
|
|
* @throws InvalidStylesheetException |
52
|
|
|
*/ |
53
|
171 |
|
protected function __construct(SimpleXMLElement $node, $parent) |
54
|
|
|
{ |
55
|
171 |
|
$this->parent = $parent; |
56
|
|
|
// init child elements |
57
|
|
|
/** @var SimpleXMLElement $child */ |
58
|
171 |
|
foreach ($node->children() as $child) { |
59
|
171 |
|
switch ($child->getName()) { |
60
|
|
|
/* The cs:layout rendering element is a required child element of cs:citation and cs:bibliography. It |
61
|
|
|
* must contain one or more of the other rendering elements described below, and may carry affixes and |
62
|
|
|
* formatting attributes. |
63
|
|
|
*/ |
64
|
171 |
|
case 'layout': |
65
|
171 |
|
$this->layout = Layout::factory($child); |
66
|
171 |
|
$this->layout->setParent($this); |
67
|
171 |
|
break; |
68
|
|
|
|
69
|
|
|
/* cs:citation and cs:bibliography may include a cs:sort child element before the cs:layout element to |
70
|
|
|
* specify the sorting order of respectively cites within citations, and bibliographic entries within |
71
|
|
|
* the bibliography. In the absence of cs:sort, cites and bibliographic entries appear in the order in |
72
|
|
|
* which they are cited. |
73
|
|
|
*/ |
74
|
60 |
|
case 'sort': |
75
|
60 |
|
$sorting = new Sort($child); |
76
|
171 |
|
CiteProc::getContext()->setSorting($sorting); |
77
|
|
|
} |
78
|
|
|
} |
79
|
171 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Root |
83
|
|
|
*/ |
84
|
|
|
public function getParent() |
85
|
|
|
{ |
86
|
|
|
return $this->parent; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|