|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* rdfa-lite-microdata |
|
5
|
|
|
* |
|
6
|
|
|
* @category Jkphl |
|
7
|
|
|
* @package Jkphl\RdfaLiteMicrodata |
|
8
|
|
|
* @subpackage Jkphl\RdfaLiteMicrodata\Application |
|
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
|
10
|
|
|
* @copyright Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/*********************************************************************************** |
|
15
|
|
|
* The MIT License (MIT) |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright © 2017 Joschi Kuphal <[email protected]> / @jkphl |
|
18
|
|
|
* |
|
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
21
|
|
|
* the Software without restriction, including without limitation the rights to |
|
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
|
24
|
|
|
* subject to the following conditions: |
|
25
|
|
|
* |
|
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
27
|
|
|
* copies or substantial portions of the Software. |
|
28
|
|
|
* |
|
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
35
|
|
|
***********************************************************************************/ |
|
36
|
|
|
|
|
37
|
|
|
namespace Jkphl\RdfaLiteMicrodata\Application\Context; |
|
38
|
|
|
|
|
39
|
|
|
use Jkphl\RdfaLiteMicrodata\Application\Parser\RootThing; |
|
40
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Thing\ThingInterface; |
|
41
|
|
|
use Jkphl\RdfaLiteMicrodata\Domain\Vocabulary\VocabularyInterface; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Abstract parsing context |
|
45
|
|
|
* |
|
46
|
|
|
* @package Jkphl\RdfaLiteMicrodata |
|
47
|
|
|
* @subpackage Jkphl\RdfaLiteMicrodata\Application |
|
48
|
|
|
*/ |
|
49
|
|
|
abstract class AbstractContext implements ContextInterface |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* Current default vocabulary |
|
53
|
|
|
* |
|
54
|
|
|
* @var VocabularyInterface |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $defaultVocabulary = null; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Parent thing |
|
60
|
|
|
* |
|
61
|
|
|
* @var ThingInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $parentThing; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Root thing |
|
67
|
|
|
* |
|
68
|
|
|
* @var RootThing |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $rootThing; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Context constructor |
|
74
|
|
|
*/ |
|
75
|
24 |
|
public function __construct() |
|
76
|
|
|
{ |
|
77
|
24 |
|
$this->parentThing = $this->rootThing = new RootThing(); |
|
78
|
24 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return the registered child things |
|
82
|
|
|
* |
|
83
|
|
|
* @return ThingInterface[] Child things |
|
84
|
|
|
*/ |
|
85
|
8 |
|
public function getChildren() |
|
86
|
|
|
{ |
|
87
|
8 |
|
return $this->rootThing->getChildren(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return the current parent thing |
|
92
|
|
|
* |
|
93
|
|
|
* @return ThingInterface|null Parent thing |
|
94
|
|
|
*/ |
|
95
|
9 |
|
public function getParentThing() |
|
96
|
|
|
{ |
|
97
|
9 |
|
return $this->parentThing; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Set the parent thing |
|
102
|
|
|
* |
|
103
|
|
|
* @param ThingInterface $parentThing Parent thing |
|
104
|
|
|
* @return ContextInterface Self reference |
|
105
|
|
|
*/ |
|
106
|
10 |
|
public function setParentThing(ThingInterface $parentThing) |
|
107
|
|
|
{ |
|
108
|
|
|
// If the new parent thing differs from the current one |
|
109
|
10 |
|
if ($this->parentThing !== $parentThing) { |
|
110
|
10 |
|
$context = clone $this; |
|
111
|
10 |
|
$context->parentThing = $parentThing; |
|
112
|
10 |
|
return $context; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Return the root thing |
|
120
|
|
|
* |
|
121
|
|
|
* @return ThingInterface |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getRootThing() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->rootThing; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Add a child thing to the current parent thing |
|
130
|
|
|
* |
|
131
|
|
|
* @param ThingInterface $thing Child thing |
|
132
|
|
|
* @return ContextInterface Self reference |
|
133
|
|
|
*/ |
|
134
|
9 |
|
public function addChild(ThingInterface $thing) |
|
135
|
|
|
{ |
|
136
|
9 |
|
$this->rootThing->addChild($thing); |
|
137
|
9 |
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Return the current default vocabulary |
|
142
|
|
|
* |
|
143
|
|
|
* @return VocabularyInterface Current default vocabulary |
|
144
|
|
|
*/ |
|
145
|
12 |
|
public function getDefaultVocabulary() |
|
146
|
|
|
{ |
|
147
|
12 |
|
return $this->defaultVocabulary; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|