| 1 | <?php |
||
| 10 | class CssInline implements ScraperInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var \Aoe\Asdis\Content\Scraper\Css\Url |
||
| 14 | */ |
||
| 15 | private $cssUrlScraper; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param \Aoe\Asdis\Content\Scraper\Css\Url $cssUrlScraper |
||
| 19 | */ |
||
| 20 | 1 | public function injectCssUrlScraper(Url $cssUrlScraper) |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @param $content |
||
| 27 | * @return \Aoe\Asdis\Domain\Model\Asset\Collection |
||
| 28 | */ |
||
| 29 | 1 | public function scrape($content) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Returns the inner content of all <style></style> blocks of the given markup as an array. |
||
| 36 | * |
||
| 37 | * @param string $content |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 1 | private function getStyleBlocksFromMarkup($content) |
|
| 41 | { |
||
| 42 | 1 | $blocks = []; |
|
| 43 | 1 | $matches = []; |
|
| 44 | |||
| 45 | 1 | preg_match_all( |
|
| 46 | 1 | '~<style[^>]*>(.*?)</style>~is', |
|
| 47 | 1 | $content, |
|
| 48 | 1 | $matches, |
|
| 49 | 1 | PREG_PATTERN_ORDER |
|
| 50 | ); |
||
| 51 | |||
| 52 | 1 | if (is_array($matches) && sizeof($matches) > 1 && is_array($matches[1])) { |
|
| 53 | 1 | $blocks = $matches[1]; |
|
| 54 | } |
||
| 55 | |||
| 56 | 1 | return $blocks; |
|
| 57 | } |
||
| 58 | } |