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 | protected function __construct(SimpleXMLElement $node, $parent) |
||
54 | { |
||
55 | $this->parent = $parent; |
||
56 | // init child elements |
||
57 | /** @var SimpleXMLElement $child */ |
||
58 | foreach ($node->children() as $child) { |
||
59 | 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 | case 'layout': |
||
65 | $this->layout = new Layout($child, $this); |
||
66 | break; |
||
67 | |||
68 | /* cs:citation and cs:bibliography may include a cs:sort child element before the cs:layout element to |
||
69 | * specify the sorting order of respectively cites within citations, and bibliographic entries within |
||
70 | * the bibliography. In the absence of cs:sort, cites and bibliographic entries appear in the order in |
||
71 | * which they are cited. |
||
72 | */ |
||
73 | case 'sort': |
||
74 | $sorting = new Sort($child); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
75 | CiteProc::getContext()->setSorting($sorting); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return Root |
||
82 | */ |
||
83 | public function getParent() |
||
84 | { |
||
85 | return $this->parent; |
||
86 | } |
||
87 | } |
||
88 |