Skip to content

Commit 50a4c9b

Browse files
committed
PB-369: Integrate third party library to work with DOMDocument
- update wrapper classes
1 parent fcfb121 commit 50a4c9b

26 files changed

+499
-118
lines changed

app/code/Magento/PageBuilder/Model/Dom/Adapter/AttrInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
*/
1313
interface AttrInterface
1414
{
15-
public function remove():self;
15+
/**
16+
* Removes attribute
17+
*
18+
* @return $this
19+
*/
20+
public function remove(): self;
1621
}

app/code/Magento/PageBuilder/Model/Dom/Adapter/DocumentFragmentInterface.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
namespace Magento\PageBuilder\Model\Dom\Adapter;
99

10-
use DOMNode;
11-
use RuntimeException;
12-
1310
/**
1411
* Interface for DocumentFragment wrappers
1512
*/
1613
interface DocumentFragmentInterface
1714
{
18-
public function appendHTML(string $data):bool;
15+
/**
16+
* Appends the specified content to the document fragment
17+
*
18+
* @param string $data
19+
* @return bool
20+
*/
21+
public function appendHTML(string $data): bool;
1922
}

app/code/Magento/PageBuilder/Model/Dom/Adapter/DocumentInterface.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@
1515
*/
1616
interface DocumentInterface
1717
{
18-
public function __toString():string;
18+
/**
19+
* Returns string representation of document
20+
*
21+
* @return string
22+
*/
23+
public function __toString(): string;
1924

20-
public function saveHTML(DOMNode $node = null):string;
25+
/**
26+
* Dumps the internal document into a string using HTML formatting
27+
*
28+
* @param DOMNode|null $node
29+
* @return string
30+
*/
31+
public function saveHTML(DOMNode $node = null): string;
2132

2233
/**
2334
* Closes the stream and any underlying resources.
2435
*
2536
* @return void
2637
*/
27-
public function close():void;
38+
public function close(): void;
2839

2940
/**
3041
* Separates any underlying resources from the stream.
@@ -40,29 +51,29 @@ public function detach();
4051
*
4152
* @return int|null Returns the size in bytes if known, or null if unknown.
4253
*/
43-
public function getSize():?int;
54+
public function getSize(): ?int;
4455

4556
/**
4657
* Returns the current position of the file read/write pointer
4758
*
4859
* @return int Position of the file pointer
4960
* @throws RuntimeException on error.
5061
*/
51-
public function tell():int;
62+
public function tell(): int;
5263

5364
/**
5465
* Returns true if the stream is at the end of the stream.
5566
*
5667
* @return bool
5768
*/
58-
public function eof():bool;
69+
public function eof(): bool;
5970

6071
/**
6172
* Returns whether or not the stream is seekable.
6273
*
6374
* @return bool
6475
*/
65-
public function isSeekable():bool;
76+
public function isSeekable(): bool;
6677

6778
/**
6879
* Seek to a position in the stream.
@@ -76,7 +87,7 @@ public function isSeekable():bool;
7687
* SEEK_END: Set position to end-of-stream plus offset.
7788
* @throws RuntimeException on failure.
7889
*/
79-
public function seek($offset, $whence = SEEK_SET):void;
90+
public function seek($offset, $whence = SEEK_SET): void;
8091

8192
/**
8293
* Seek to the beginning of the stream.
@@ -88,14 +99,14 @@ public function seek($offset, $whence = SEEK_SET):void;
8899
* @link http://www.php.net/manual/en/function.fseek.php
89100
* @see seek()
90101
*/
91-
public function rewind():void;
102+
public function rewind(): void;
92103

93104
/**
94105
* Returns whether or not the stream is writable.
95106
*
96107
* @return bool
97108
*/
98-
public function isWritable():bool;
109+
public function isWritable(): bool;
99110

100111
/**
101112
* Write data to the stream.
@@ -104,14 +115,14 @@ public function isWritable():bool;
104115
* @return int Returns the number of bytes written to the stream.
105116
* @throws RuntimeException on failure.
106117
*/
107-
public function write($string):int;
118+
public function write($string): int;
108119

109120
/**
110121
* Returns whether or not the stream is readable.
111122
*
112123
* @return bool
113124
*/
114-
public function isReadable():bool;
125+
public function isReadable(): bool;
115126

116127
/**
117128
* Read data from the stream.
@@ -123,7 +134,7 @@ public function isReadable():bool;
123134
* if no bytes are available.
124135
* @throws RuntimeException if an error occurs.
125136
*/
126-
public function read($length):string;
137+
public function read($length): string;
127138

128139
/**
129140
* Returns the remaining contents in a string
@@ -132,7 +143,7 @@ public function read($length):string;
132143
* @throws RuntimeException if unable to read or an error occurs while
133144
* reading.
134145
*/
135-
public function getContents():string;
146+
public function getContents(): string;
136147

137148
/**
138149
* Get stream metadata as an associative array or retrieve a specific key.

app/code/Magento/PageBuilder/Model/Dom/Adapter/ElementInterface.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,66 @@
77

88
namespace Magento\PageBuilder\Model\Dom\Adapter;
99

10-
use Gt\Dom\Element;
11-
1210
/**
1311
* Interface for Element wrappers
1412
*/
1513
interface ElementInterface
1614
{
1715
/**
18-
* returns true if the element would be selected by the specified selector
19-
* string; otherwise, returns false.
16+
* Returns true if the element would be selected by the specified selector string; otherwise, returns false.
17+
*
2018
* @param string $selectors The CSS selector(s) to check against
2119
* @return bool True if this element is selectable by provided selector
2220
*/
23-
public function matches(string $selectors):bool;
21+
public function matches(string $selectors): bool;
2422

2523
/**
26-
* Returns a live HTMLCollection containing all child elements which have all
27-
* of the given class names. When called on the document object, the complete
28-
* document is searched, including the root node.
24+
* Returns a live HTMLCollection containing all child elements which have all of the given class names.
25+
*
2926
* @param string $names a string representing the list of class names to
3027
* match; class names are separated by whitespace
3128
* @return HtmlCollectionInterface
3229
*/
33-
public function getElementsByClassName(string $names):HtmlCollectionInterface;
30+
public function getElementsByClassName(string $names): HtmlCollectionInterface;
3431

3532
/**
36-
* Returns the closest ancestor of the current element (or itself)
37-
* which matches the selectors.
33+
* Returns the closest ancestor of the current element (or itself) which matches the selectors.
34+
*
3835
* @param string $selectors CSS selector(s)
3936
* @return ElementInterface|null
4037
*/
4138
public function closest(string $selectors): ?ElementInterface;
4239

4340
/**
4441
* Returns the value of the specified attribute
45-
* @param $name
42+
*
43+
* @param string $name
4644
* @return string|null
4745
*/
48-
public function getAttribute($name):?string;
46+
public function getAttribute($name): ?string;
47+
48+
/**
49+
* Sets the value of the specified attribute
50+
*
51+
* @param string $name
52+
* @param string $value
53+
* @return AttrInterface|null
54+
*/
55+
public function setAttribute($name, $value): ?AttrInterface;
56+
57+
/**
58+
* Returns the first element matching the specified selector.
59+
*
60+
* @param string $selector
61+
* @return HtmlCollectionInterface
62+
*/
63+
public function querySelector(string $selector): ElementInterface;
64+
65+
/**
66+
* Returns all elements matching the specified selector.
67+
*
68+
* @param string $selector
69+
* @return HtmlCollectionInterface
70+
*/
71+
public function querySelectorAll(string $selector): HtmlCollectionInterface;
4972
}

app/code/Magento/PageBuilder/Model/Dom/Adapter/HtmlCollectionInterface.php

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,92 @@
1212
*/
1313
interface HtmlCollectionInterface
1414
{
15-
/**
16-
* Returns the specific Node whose ID or, as a fallback,
17-
* name matches the string specified by $name. Matching by name is only done
18-
* as a last resort, and only if the referenced element supports the name
19-
* attribute.
15+
/**
16+
* Returns the specific Node whose ID or, as a fallback, name matches the string specified by $name.
17+
*
2018
* @param string $name
2119
* @return ElementInterface
2220
*/
2321
public function namedItem(string $name): ?ElementInterface;
2422

23+
/**
24+
* Gets the nth Element object in the internal DOMNodeList.
25+
*
26+
* @param int $index
27+
* @return ElementInterface|null
28+
*/
2529
public function item(int $index): ?ElementInterface;
2630

31+
/**
32+
* Resets the internal pointer to the beginning of the collection
33+
*
34+
* @return void
35+
*/
2736
public function rewind(): void;
2837

38+
/**
39+
* Returns the current index key value
40+
*
41+
* @return int
42+
*/
2943
public function key(): int;
3044

45+
/**
46+
* Returns true if the current index key is valid
47+
*
48+
* @return bool
49+
*/
3150
public function valid(): bool;
3251

52+
/**
53+
* Advances the iterator one position forward
54+
*
55+
* @return void
56+
*/
3357
public function next(): void;
3458

59+
/**
60+
* Returns the element currently being pointed to by the iterator
61+
*
62+
* @return ElementInterface|null
63+
*/
3564
public function current(): ?ElementInterface;
3665

66+
/**
67+
* Returns true if the specified offset points to a value in the collection, false otherwise.
68+
*
69+
* @param int $offset
70+
* @return bool
71+
*/
3772
public function offsetExists($offset): bool;
3873

74+
/**
75+
* Returns the item in the $offset position in the collection
76+
*
77+
* @param int $offset
78+
* @return ElementInterface|null
79+
*/
3980
public function offsetGet($offset): ?ElementInterface;
4081

82+
/**
83+
* Attempts to set the specified value in the $offset position of the collection
84+
*
85+
* @param int $offset
86+
* @param string $value
87+
*/
4188
public function offsetSet($offset, $value): void;
4289

90+
/**
91+
* Attempts to unset the item in the specified offset of the collection
92+
*
93+
* @param int $offset
94+
*/
4395
public function offsetUnset($offset): void;
4496

97+
/**
98+
* Returns the number of items in the collection
99+
*
100+
* @return int
101+
*/
45102
public function count(): int;
46103
}

app/code/Magento/PageBuilder/Model/Dom/Adapter/HtmlDocumentInterface.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,32 @@ interface HtmlDocumentInterface
1414
{
1515
/**
1616
* Returns collection of elements matching the specified class names
17+
*
1718
* @param string $names
1819
* @return HtmlCollectionInterface
1920
*/
20-
public function getElementsByClassName(string $names):HtmlCollectionInterface;
21+
public function getElementsByClassName(string $names): HtmlCollectionInterface;
22+
23+
/**
24+
* Returns the first element matching the specified selector.
25+
*
26+
* @param string $selector
27+
* @return HtmlCollectionInterface
28+
*/
29+
public function querySelector(string $selector): ElementInterface;
30+
31+
/**
32+
* Returns all elements matching the specified selector.
33+
*
34+
* @param string $selector
35+
* @return HtmlCollectionInterface
36+
*/
37+
public function querySelectorAll(string $selector): HtmlCollectionInterface;
38+
39+
/**
40+
* Dumps the internal document into a string using HTML formatting
41+
*
42+
* @return string
43+
*/
44+
public function saveHTML(): string;
2145
}

0 commit comments

Comments
 (0)