Skip to content

Commit 63e4a62

Browse files
committed
PB-369: Integrate third party library to work with DOMDocument
- add wrapper classes
1 parent 49eb7d8 commit 63e4a62

32 files changed

+1538
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
public function remove():self;
16+
}
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 DocumentFragment wrappers
15+
*/
16+
interface DocumentFragmentInterface
17+
{
18+
public function appendHTML(string $data):bool;
19+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
public function __toString():string;
19+
20+
public function saveHTML(DOMNode $node = null):string;
21+
22+
/**
23+
* Closes the stream and any underlying resources.
24+
*
25+
* @return void
26+
*/
27+
public function close():void;
28+
29+
/**
30+
* Separates any underlying resources from the stream.
31+
*
32+
* After the stream has been detached, the stream is in an unusable state.
33+
*
34+
* @return resource|null Underlying PHP stream, if any
35+
*/
36+
public function detach();
37+
38+
/**
39+
* Get the size of the stream if known.
40+
*
41+
* @return int|null Returns the size in bytes if known, or null if unknown.
42+
*/
43+
public function getSize():?int;
44+
45+
/**
46+
* Returns the current position of the file read/write pointer
47+
*
48+
* @return int Position of the file pointer
49+
* @throws RuntimeException on error.
50+
*/
51+
public function tell():int;
52+
53+
/**
54+
* Returns true if the stream is at the end of the stream.
55+
*
56+
* @return bool
57+
*/
58+
public function eof():bool;
59+
60+
/**
61+
* Returns whether or not the stream is seekable.
62+
*
63+
* @return bool
64+
*/
65+
public function isSeekable():bool;
66+
67+
/**
68+
* Seek to a position in the stream.
69+
*
70+
* @link http://www.php.net/manual/en/function.fseek.php
71+
* @param int $offset Stream offset
72+
* @param int $whence Specifies how the cursor position will be calculated
73+
* based on the seek offset. Valid values are identical to the built-in
74+
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
75+
* offset bytes SEEK_CUR: Set position to current location plus offset
76+
* SEEK_END: Set position to end-of-stream plus offset.
77+
* @throws RuntimeException on failure.
78+
*/
79+
public function seek($offset, $whence = SEEK_SET):void;
80+
81+
/**
82+
* Seek to the beginning of the stream.
83+
*
84+
* If the stream is not seekable, this method will raise an exception;
85+
* otherwise, it will perform a seek(0).
86+
*
87+
* @throws RuntimeException on failure.
88+
* @link http://www.php.net/manual/en/function.fseek.php
89+
* @see seek()
90+
*/
91+
public function rewind():void;
92+
93+
/**
94+
* Returns whether or not the stream is writable.
95+
*
96+
* @return bool
97+
*/
98+
public function isWritable():bool;
99+
100+
/**
101+
* Write data to the stream.
102+
*
103+
* @param string $string The string that is to be written.
104+
* @return int Returns the number of bytes written to the stream.
105+
* @throws RuntimeException on failure.
106+
*/
107+
public function write($string):int;
108+
109+
/**
110+
* Returns whether or not the stream is readable.
111+
*
112+
* @return bool
113+
*/
114+
public function isReadable():bool;
115+
116+
/**
117+
* Read data from the stream.
118+
*
119+
* @param int $length Read up to $length bytes from the object and return
120+
* them. Fewer than $length bytes may be returned if underlying stream
121+
* call returns fewer bytes.
122+
* @return string Returns the data read from the stream, or an empty string
123+
* if no bytes are available.
124+
* @throws RuntimeException if an error occurs.
125+
*/
126+
public function read($length):string;
127+
128+
/**
129+
* Returns the remaining contents in a string
130+
*
131+
* @return string
132+
* @throws RuntimeException if unable to read or an error occurs while
133+
* reading.
134+
*/
135+
public function getContents():string;
136+
137+
/**
138+
* Get stream metadata as an associative array or retrieve a specific key.
139+
*
140+
* The keys returned are identical to the keys returned from PHP's
141+
* stream_get_meta_data() function.
142+
*
143+
* @link http://php.net/manual/en/function.stream-get-meta-data.php
144+
* @param string $key Specific metadata to retrieve.
145+
* @return array|mixed|null Returns an associative array if no key is
146+
* provided. Returns a specific key value if a key is provided and the
147+
* value is found, or null if the key is not found.
148+
*/
149+
public function getMetadata($key = null);
150+
}
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 Gt\Dom\Element;
11+
12+
/**
13+
* Interface for Element wrappers
14+
*/
15+
interface ElementInterface
16+
{
17+
/**
18+
* returns true if the element would be selected by the specified selector
19+
* string; otherwise, returns false.
20+
* @param string $selectors The CSS selector(s) to check against
21+
* @return bool True if this element is selectable by provided selector
22+
*/
23+
public function matches(string $selectors):bool;
24+
25+
/**
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.
29+
* @param string $names a string representing the list of class names to
30+
* match; class names are separated by whitespace
31+
* @return HtmlCollectionInterface
32+
*/
33+
public function getElementsByClassName(string $names):HtmlCollectionInterface;
34+
35+
/**
36+
* Returns the closest ancestor of the current element (or itself)
37+
* which matches the selectors.
38+
* @param string $selectors CSS selector(s)
39+
* @return ElementInterface|null
40+
*/
41+
public function closest(string $selectors): ?ElementInterface;
42+
43+
/**
44+
* Returns the value of the specified attribute
45+
* @param $name
46+
* @return string|null
47+
*/
48+
public function getAttribute($name):?string;
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 HtmlCollection wrappers
12+
*/
13+
interface HtmlCollectionInterface
14+
{
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.
20+
* @param string $name
21+
* @return ElementInterface
22+
*/
23+
public function namedItem(string $name): ?ElementInterface;
24+
25+
public function item(int $index): ?ElementInterface;
26+
27+
public function rewind(): void;
28+
29+
public function key(): int;
30+
31+
public function valid(): bool;
32+
33+
public function next(): void;
34+
35+
public function current(): ?ElementInterface;
36+
37+
public function offsetExists($offset): bool;
38+
39+
public function offsetGet($offset): ?ElementInterface;
40+
41+
public function offsetSet($offset, $value): void;
42+
43+
public function offsetUnset($offset): void;
44+
45+
public function count(): int;
46+
}
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 HtmlDocument wrappers
12+
*/
13+
interface HtmlDocumentInterface
14+
{
15+
/**
16+
* Returns collection of elements matching the specified class names
17+
* @param string $names
18+
* @return HtmlCollectionInterface
19+
*/
20+
public function getElementsByClassName(string $names):HtmlCollectionInterface;
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 Node wrappers
12+
*/
13+
interface NodeInterface
14+
{
15+
}

0 commit comments

Comments
 (0)