-
-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathMetas.php
43 lines (33 loc) · 942 Bytes
/
Metas.php
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
<?php
declare(strict_types = 1);
namespace Embed;
class Metas
{
use ApiTrait;
protected function fetchData(): array
{
$data = [];
$document = $this->extractor->getDocument();
foreach ($document->select('.//meta')->nodes() as $node) {
$type = $node->getAttribute('name') ?: $node->getAttribute('property') ?: $node->getAttribute('itemprop');
$value = $node->getAttribute('content');
if (!empty($value) && !empty($type)) {
$type = strtolower($type);
$data[$type] ??= [];
$data[$type][] = $value;
}
}
return $data;
}
public function get(string ...$keys)
{
$data = $this->all();
foreach ($keys as $key) {
$values = $data[$key] ?? null;
if ($values) {
return $values;
}
}
return null;
}
}