|
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\Util; |
|
11
|
|
|
use Seboettg\CiteProc\Exception\CiteProcException; |
|
12
|
|
|
use Seboettg\CiteProc\Exception\ClassNotFoundException; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Factory |
|
17
|
|
|
* @package Seboettg\CiteProc\Util |
|
18
|
|
|
* |
|
19
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Factory |
|
22
|
|
|
{ |
|
23
|
|
|
const CITE_PROC_NODE_NAMESPACE = "Seboettg\\CiteProc\\Rendering"; |
|
24
|
|
|
|
|
25
|
|
|
static $nodes = [ |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
'layout' => "\\Layout", |
|
28
|
|
|
'text' => "\\Text", |
|
29
|
|
|
"macro" => "\\Macro", |
|
30
|
|
|
"number" => "\\Number", |
|
31
|
|
|
"label" => "\\Label", |
|
32
|
|
|
"group" => "\\Group", |
|
33
|
|
|
"choose" => "\\Choose\\Choose", |
|
34
|
|
|
"if" => "\\Choose\\ChooseIf", |
|
35
|
|
|
"else-if" => "\\Choose\\ChooseElseIf", |
|
36
|
|
|
"else" => "\\Choose\\ChooseElse", |
|
37
|
|
|
'date' => "\\Date\\Date", |
|
38
|
|
|
"date-part" => "\\Date\\DatePart", |
|
39
|
|
|
"names" => "\\Name\\Names", |
|
40
|
|
|
"name" => "\\Name\\Name", |
|
41
|
|
|
"name-part" => "\\Name\\NamePart", |
|
42
|
|
|
"substitute" => "\\Name\\Substitute", |
|
43
|
|
|
"et-al" => "\\Name\\EtAl" |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
public static function create($node, $param = null) |
|
47
|
|
|
{ |
|
48
|
|
|
$nodeClass = self::CITE_PROC_NODE_NAMESPACE . self::$nodes[$node->getName()]; |
|
49
|
|
|
if (!class_exists($nodeClass)) { |
|
50
|
|
|
throw new ClassNotFoundException($nodeClass); |
|
51
|
|
|
} |
|
52
|
|
|
if ($param != null) { |
|
53
|
|
|
return new $nodeClass($node, $param); |
|
54
|
|
|
} |
|
55
|
|
|
return new $nodeClass($node); |
|
56
|
|
|
} |
|
57
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.