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 | * Track whether or not data attributes have been loaded for this |
20 | * document. See DOMDataUtils::visitAndLoadDataAttribs(). |
21 | */ |
22 | public bool $loaded = false; |
23 | |
24 | /** |
25 | * FIXME: Figure out a decent interface for updating these depths |
26 | * without needing to import the various util files. |
27 | * |
28 | * Map of start/end meta tag tree depths keyed by about id |
29 | */ |
30 | public array $transclusionMetaTagDepthMap = []; |
31 | |
32 | /** |
33 | * Get the data object for the node with data-object-id 'nodeId'. |
34 | * This will return null if a non-existent nodeId is provided. |
35 | * |
36 | * @param int $nodeId |
37 | * @return NodeData|null |
38 | */ |
39 | public function getObject( int $nodeId ): ?NodeData { |
40 | return $this->dataObject[$nodeId] ?? null; |
41 | } |
42 | |
43 | /** |
44 | * Stash the data and return an id for retrieving it later |
45 | * @param NodeData $data |
46 | * @return int |
47 | */ |
48 | public function stashObject( NodeData $data ): int { |
49 | $nodeId = $this->nodeId++; |
50 | $this->dataObject[$nodeId] = $data; |
51 | return $nodeId; |
52 | } |
53 | } |