1 | <?php |
||
10 | class MixedContentExtractor |
||
11 | { |
||
12 | public static function extract(string $html, string $currentUri): array |
||
13 | { |
||
14 | return static::getSearchNodes() |
||
15 | ->mapSpread(function ($tagName, $attribute) use ($html, $currentUri) { |
||
16 | return (new DomCrawler($html, $currentUri)) |
||
17 | ->filterXPath("//{$tagName}[@{$attribute}]") |
||
18 | ->reduce(function (DomCrawler $node) { |
||
19 | return ! self::isShortLink($node); |
||
20 | }) |
||
21 | ->each(function (DomCrawler $node) use ($tagName, $attribute) { |
||
22 | $url = Url::create($node->attr($attribute)); |
||
23 | |||
24 | if ($tagName === 'link' && $attribute === 'href') { |
||
25 | if ($node->attr('rel') !== 'stylesheet') { |
||
26 | return null; |
||
27 | } |
||
28 | } |
||
29 | |||
30 | return $url->scheme === 'http' ? [$tagName, $url] : null; |
||
31 | }); |
||
32 | }) |
||
33 | ->flatten(1) |
||
34 | ->filter() |
||
35 | ->mapSpread(function ($tagName, $mixedContentUrl) use ($currentUri) { |
||
36 | return new MixedContent($tagName, $mixedContentUrl, Url::create($currentUri)); |
||
37 | }) |
||
38 | ->toArray(); |
||
39 | } |
||
40 | |||
41 | protected static function getSearchNodes(): Collection |
||
59 | |||
60 | protected static function isShortLink(DomCrawler $node) |
||
70 | } |
||
71 |