-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathHTMLReader.php
More file actions
52 lines (44 loc) · 1.43 KB
/
HTMLReader.php
File metadata and controls
52 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Brick\StructuredData;
final class HTMLReader
{
private readonly Reader $reader;
/**
* HTMLReader constructor.
*
* @param Reader $reader
*/
public function __construct(Reader $reader)
{
$this->reader = $reader;
}
/**
* Reads the items contained in the given HTML string.
*
* @param string $html The HTML string to read.
* @param string $url The URL the document was retrieved from. This will be used only to resolve relative URLs in
* property values. No attempt will be performed to connect to this URL.
*
* @return Item[] The top-level items.
*/
public function read(string $html, string $url) : array
{
$document = DOMBuilder::fromHTML($html);
return $this->reader->read($document, $url);
}
/**
* Reads the items contained in the given HTML file.
*
* @param string $file The HTML file to read.
* @param string $url The URL the document was retrieved from. This will be used only to resolve relative URLs in
* property values. No attempt will be performed to connect to this URL.
*
* @return Item[] The top-level items.
*/
public function readFile(string $file, string $url) : array
{
$document = DOMBuilder::fromHTMLFile($file);
return $this->reader->read($document, $url);
}
}