Skip to content

Commit dfe36e7

Browse files
Merge pull request #374 from magento-obsessive-owls/PB-369-Integrate-third-party-library
[Owls] PB-369: Integrate third party library to work with DOMDocument
2 parents 08e9cd1 + b3b05ed commit dfe36e7

34 files changed

+1982
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for Attr wrappers
12+
*/
13+
interface AttrInterface
14+
{
15+
/**
16+
* Removes attribute
17+
*
18+
* @return $this
19+
*/
20+
public function remove(): self;
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for CharacterData wrappers
12+
*/
13+
interface CharacterDataInterface
14+
{
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for Comment wrappers
12+
*/
13+
interface CommentInterface
14+
{
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for DocumentFragment wrappers
12+
*/
13+
interface DocumentFragmentInterface
14+
{
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;
22+
23+
/**
24+
* Returns the first element matching the specified selector.
25+
*
26+
* @param string $selector
27+
* @return ElementInterface
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+
* Returns string content of fragment
41+
*/
42+
public function propGetInnerText(): string;
43+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
use DOMNode;
11+
use RuntimeException;
12+
13+
/**
14+
* Interface for Document wrappers
15+
*/
16+
interface DocumentInterface
17+
{
18+
/**
19+
* Returns string representation of document
20+
*
21+
* @return string
22+
*/
23+
public function __toString(): string;
24+
25+
/**
26+
* Create new document fragment
27+
*
28+
* @return DocumentFragmentInterface
29+
*/
30+
public function createDocumentFragment(): DocumentFragmentInterface;
31+
32+
/**
33+
* Returns the first element matching the specified selector.
34+
*
35+
* @param string $selector
36+
* @return ElementInterface
37+
*/
38+
public function querySelector(string $selector): ElementInterface;
39+
40+
/**
41+
* Returns all elements matching the specified selector.
42+
*
43+
* @param string $selector
44+
* @return HtmlCollectionInterface
45+
*/
46+
public function querySelectorAll(string $selector): HtmlCollectionInterface;
47+
48+
/**
49+
* Dumps the internal document into a string using HTML formatting
50+
*
51+
* @param DOMNode|null $node
52+
* @return string
53+
*/
54+
public function saveHTML(DOMNode $node = null): string;
55+
56+
/**
57+
* Closes the stream and any underlying resources.
58+
*
59+
* @return void
60+
*/
61+
public function close(): void;
62+
63+
/**
64+
* Separates any underlying resources from the stream.
65+
*
66+
* After the stream has been detached, the stream is in an unusable state.
67+
*
68+
* @return resource|null Underlying PHP stream, if any
69+
*/
70+
public function detach();
71+
72+
/**
73+
* Get the size of the stream if known.
74+
*
75+
* @return int|null Returns the size in bytes if known, or null if unknown.
76+
*/
77+
public function getSize(): ?int;
78+
79+
/**
80+
* Returns the current position of the file read/write pointer
81+
*
82+
* @return int Position of the file pointer
83+
* @throws RuntimeException on error.
84+
*/
85+
public function tell(): int;
86+
87+
/**
88+
* Returns true if the stream is at the end of the stream.
89+
*
90+
* @return bool
91+
*/
92+
public function eof(): bool;
93+
94+
/**
95+
* Returns whether or not the stream is seekable.
96+
*
97+
* @return bool
98+
*/
99+
public function isSeekable(): bool;
100+
101+
/**
102+
* Seek to a position in the stream.
103+
*
104+
* @link http://www.php.net/manual/en/function.fseek.php
105+
* @param int $offset Stream offset
106+
* @param int $whence Specifies how the cursor position will be calculated
107+
* based on the seek offset. Valid values are identical to the built-in
108+
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
109+
* offset bytes SEEK_CUR: Set position to current location plus offset
110+
* SEEK_END: Set position to end-of-stream plus offset.
111+
* @throws RuntimeException on failure.
112+
*/
113+
public function seek($offset, $whence = SEEK_SET): void;
114+
115+
/**
116+
* Seek to the beginning of the stream.
117+
*
118+
* If the stream is not seekable, this method will raise an exception;
119+
* otherwise, it will perform a seek(0).
120+
*
121+
* @throws RuntimeException on failure.
122+
* @link http://www.php.net/manual/en/function.fseek.php
123+
* @see seek()
124+
*/
125+
public function rewind(): void;
126+
127+
/**
128+
* Returns whether or not the stream is writable.
129+
*
130+
* @return bool
131+
*/
132+
public function isWritable(): bool;
133+
134+
/**
135+
* Write data to the stream.
136+
*
137+
* @param string $string The string that is to be written.
138+
* @return int Returns the number of bytes written to the stream.
139+
* @throws RuntimeException on failure.
140+
*/
141+
public function write($string): int;
142+
143+
/**
144+
* Returns whether or not the stream is readable.
145+
*
146+
* @return bool
147+
*/
148+
public function isReadable(): bool;
149+
150+
/**
151+
* Read data from the stream.
152+
*
153+
* @param int $length Read up to $length bytes from the object and return
154+
* them. Fewer than $length bytes may be returned if underlying stream
155+
* call returns fewer bytes.
156+
* @return string Returns the data read from the stream, or an empty string
157+
* if no bytes are available.
158+
* @throws RuntimeException if an error occurs.
159+
*/
160+
public function read($length): string;
161+
162+
/**
163+
* Returns the remaining contents in a string
164+
*
165+
* @return string
166+
* @throws RuntimeException if unable to read or an error occurs while
167+
* reading.
168+
*/
169+
public function getContents(): string;
170+
171+
/**
172+
* Get stream metadata as an associative array or retrieve a specific key.
173+
*
174+
* The keys returned are identical to the keys returned from PHP's
175+
* stream_get_meta_data() function.
176+
*
177+
* @link http://php.net/manual/en/function.stream-get-meta-data.php
178+
* @param string $key Specific metadata to retrieve.
179+
* @return array|mixed|null Returns an associative array if no key is
180+
* provided. Returns a specific key value if a key is provided and the
181+
* value is found, or null if the key is not found.
182+
*/
183+
public function getMetadata($key = null);
184+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for DocumentType wrappers
12+
*/
13+
interface DocumentTypeInterface
14+
{
15+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Model\Dom\Adapter;
9+
10+
/**
11+
* Interface for Element wrappers
12+
*/
13+
interface ElementInterface
14+
{
15+
/**
16+
* Returns true if the element would be selected by the specified selector string; otherwise, returns false.
17+
*
18+
* @param string $selectors The CSS selector(s) to check against
19+
* @return bool True if this element is selectable by provided selector
20+
*/
21+
public function matches(string $selectors): bool;
22+
23+
/**
24+
* Returns a live HTMLCollection containing all child elements which have all of the given class names.
25+
*
26+
* @param string $names a string representing the list of class names to
27+
* match; class names are separated by whitespace
28+
* @return HtmlCollectionInterface
29+
*/
30+
public function getElementsByClassName(string $names): HtmlCollectionInterface;
31+
32+
/**
33+
* Returns the closest ancestor of the current element (or itself) which matches the selectors.
34+
*
35+
* @param string $selectors CSS selector(s)
36+
* @return ElementInterface|null
37+
*/
38+
public function closest(string $selectors): ?ElementInterface;
39+
40+
/**
41+
* Returns the value of the specified attribute
42+
*
43+
* @param string $name
44+
* @return string|null
45+
*/
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 ElementInterface
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;
72+
}

0 commit comments

Comments
 (0)