| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Libs\Emogrifier; |
| 4 |
|
| 5 |
class Emogrifier |
| 6 |
{ |
| 7 |
private $html = ''; |
| 8 |
|
| 9 |
private $disableInvisibleNode = false; |
| 10 |
|
| 11 |
public function __construct($html) |
| 12 |
{ |
| 13 |
$this->html = (string) $html; |
| 14 |
} |
| 15 |
|
| 16 |
public function disableInvisibleNodeRemoval() |
| 17 |
{ |
| 18 |
$this->disableInvisibleNode = true; |
| 19 |
return $this; |
| 20 |
} |
| 21 |
|
| 22 |
public function emogrify() |
| 23 |
{ |
| 24 |
// check if php version is less than 8.1 |
| 25 |
if (version_compare(phpversion(), '8.1', '<')) { |
| 26 |
return $this->handleLegacy(); |
| 27 |
} |
| 28 |
|
| 29 |
if (!class_exists('\FluentEmogrifier\Vendor\Pelago\Emogrifier\CssInliner')) { |
| 30 |
require_once __DIR__ . '/scoped-vendor/autoload.php'; |
| 31 |
} |
| 32 |
|
| 33 |
if (!class_exists('\FluentEmogrifier\Vendor\Pelago\Emogrifier\CssInliner')) { |
| 34 |
return $this->handleLegacy(); |
| 35 |
} |
| 36 |
|
| 37 |
// check if css inlines is available or not |
| 38 |
return \FluentEmogrifier\Vendor\Pelago\Emogrifier\CssInliner::fromHtml($this->html) |
| 39 |
->inlineCss() |
| 40 |
->render(); |
| 41 |
} |
| 42 |
|
| 43 |
private function handleLegacy() |
| 44 |
{ |
| 45 |
$emogrifier = new EmogrifierPhp7($this->html); |
| 46 |
if ($this->disableInvisibleNode) { |
| 47 |
$emogrifier->disableInvisibleNodeRemoval(); |
| 48 |
} |
| 49 |
|
| 50 |
return $emogrifier->emogrify(); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|