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