Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
Reference | |
0.00% |
0 / 33 |
|
0.00% |
0 / 11 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getSrcWiki | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWorkflowId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSrcTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getObjectType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getObjectId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStorageRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getTargetIdentifier | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUniqueIdentifier | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Model; |
4 | |
5 | use Flow\Exception\InvalidParameterException; |
6 | use MediaWiki\Title\Title; |
7 | |
8 | abstract class Reference { |
9 | public const TYPE_LINK = 'link'; |
10 | |
11 | /** |
12 | * @var UUID |
13 | */ |
14 | protected $id; |
15 | |
16 | /** |
17 | * @var UUID |
18 | */ |
19 | protected $workflowId; |
20 | |
21 | /** |
22 | * @var Title |
23 | */ |
24 | protected $srcTitle; |
25 | |
26 | /** |
27 | * @var string |
28 | */ |
29 | protected $objectType; |
30 | |
31 | /** |
32 | * @var UUID |
33 | */ |
34 | protected $objectId; |
35 | |
36 | /** |
37 | * @var string |
38 | */ |
39 | protected $type; |
40 | |
41 | /** |
42 | * @var string |
43 | */ |
44 | protected $wikiId; |
45 | |
46 | /** @var string[] */ |
47 | protected $validTypes = [ self::TYPE_LINK ]; |
48 | |
49 | /** |
50 | * Standard constructor. Called from subclasses only |
51 | * |
52 | * @param UUID $id Id of the reference |
53 | * @param string $wiki Wiki ID of the reference source |
54 | * @param UUID $srcWorkflow Source Workflow's ID |
55 | * @param Title $srcTitle Title of the Workflow from which this reference comes. |
56 | * @param string $objectType Output of getRevisionType for the AbstractRevision that this reference comes from. |
57 | * @param UUID $objectId Unique identifier for the revisioned object containing the reference. |
58 | * @param string $type The type of reference |
59 | * @throws InvalidParameterException |
60 | */ |
61 | protected function __construct( UUID $id, $wiki, UUID $srcWorkflow, Title $srcTitle, $objectType, UUID $objectId, $type ) { |
62 | $this->id = $id; |
63 | $this->wikiId = $wiki; |
64 | $this->workflowId = $srcWorkflow; |
65 | $this->objectType = $objectType; |
66 | $this->objectId = $objectId; |
67 | $this->type = $type; |
68 | $this->srcTitle = $srcTitle; |
69 | |
70 | if ( !in_array( $type, $this->validTypes ) ) { |
71 | throw new InvalidParameterException( |
72 | "Invalid type $type specified for reference " . get_class( $this ) |
73 | ); |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * Returns the wiki ID of the wiki on which the reference appears |
79 | * @return string Wiki ID |
80 | */ |
81 | public function getSrcWiki() { |
82 | return $this->wikiId; |
83 | } |
84 | |
85 | /** |
86 | * Gives the UUID of the source Workflow |
87 | * |
88 | * @return UUID |
89 | */ |
90 | public function getWorkflowId() { |
91 | return $this->workflowId; |
92 | } |
93 | |
94 | /** |
95 | * Gives the Title from which this Reference comes. |
96 | * |
97 | * @return Title |
98 | */ |
99 | public function getSrcTitle() { |
100 | return $this->srcTitle; |
101 | } |
102 | |
103 | /** |
104 | * Gives the object type of the source object. |
105 | * @return string |
106 | */ |
107 | public function getObjectType() { |
108 | return $this->objectType; |
109 | } |
110 | |
111 | /** |
112 | * Gives the UUID of the source object |
113 | * |
114 | * @return UUID |
115 | */ |
116 | public function getObjectId() { |
117 | return $this->objectId; |
118 | } |
119 | |
120 | /** |
121 | * Gives the type of Reference |
122 | * |
123 | * @return string |
124 | */ |
125 | public function getType() { |
126 | return $this->type; |
127 | } |
128 | |
129 | /** |
130 | * Returns the storage row for this Reference. |
131 | * For this abstract reference, only partial. |
132 | * |
133 | * @return array |
134 | */ |
135 | public function getStorageRow() { |
136 | return [ |
137 | 'ref_id' => $this->id->getAlphadecimal(), |
138 | 'ref_src_wiki' => $this->wikiId, |
139 | 'ref_src_workflow_id' => $this->workflowId->getAlphadecimal(), |
140 | 'ref_src_namespace' => $this->srcTitle->getNamespace(), |
141 | 'ref_src_title' => $this->srcTitle->getDBkey(), |
142 | 'ref_src_object_type' => $this->objectType, |
143 | 'ref_src_object_id' => $this->objectId->getAlphadecimal(), |
144 | 'ref_type' => $this->type, |
145 | ]; |
146 | } |
147 | |
148 | /** |
149 | * @return string Unique string identifier for the target of this reference. |
150 | */ |
151 | abstract public function getTargetIdentifier(); |
152 | |
153 | public function getIdentifier() { |
154 | return $this->getType() . ':' . $this->getTargetIdentifier(); |
155 | } |
156 | |
157 | public function getUniqueIdentifier() { |
158 | return $this->getSrcTitle() . '|' . |
159 | $this->getObjectType() . '|' . |
160 | $this->getObjectId()->getAlphadecimal() . '|' . |
161 | $this->getIdentifier(); |
162 | } |
163 | |
164 | /** |
165 | * We don't have a real PK (see comment in |
166 | * ReferenceClarifier::loadReferencesForPage) but I'll do a array_unique on |
167 | * multiple Reference objects, just to make sure we have no duplicates. |
168 | * But to be able to do an array_unique, the objects will be compared as |
169 | * strings. |
170 | * |
171 | * @return string |
172 | */ |
173 | public function __toString() { |
174 | return $this->getUniqueIdentifier(); |
175 | } |
176 | } |