Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DataBag | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
getObject | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stashObject | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\NodeData; |
5 | |
6 | class DataBag { |
7 | /** |
8 | * @var NodeData[] A map of node data-object-id ids to data objects. |
9 | * This map is used during DOM processing to avoid having to repeatedly |
10 | * json-parse/json-serialize data-parsoid and data-mw attributes. |
11 | * This map is initialized when a DOM is created/parsed/refreshed. |
12 | */ |
13 | private array $dataObject = []; |
14 | |
15 | /** An id counter for this document used for the dataObject map */ |
16 | private int $nodeId = 0; |
17 | |
18 | /** |
19 | * FIXME: Figure out a decent interface for updating these depths |
20 | * without needing to import the various util files. |
21 | * |
22 | * Map of start/end meta tag tree depths keyed by about id |
23 | */ |
24 | public array $transclusionMetaTagDepthMap = []; |
25 | |
26 | /** |
27 | * Get the data object for the node with data-object-id 'nodeId'. |
28 | * This will return null if a non-existent nodeId is provided. |
29 | * |
30 | * @param int $nodeId |
31 | * @return NodeData|null |
32 | */ |
33 | public function getObject( int $nodeId ): ?NodeData { |
34 | return $this->dataObject[$nodeId] ?? null; |
35 | } |
36 | |
37 | /** |
38 | * Stash the data and return an id for retrieving it later |
39 | * @param NodeData $data |
40 | * @return int |
41 | */ |
42 | public function stashObject( NodeData $data ): int { |
43 | $nodeId = $this->nodeId++; |
44 | $this->dataObject[$nodeId] = $data; |
45 | return $nodeId; |
46 | } |
47 | } |