Engine
4 days ago
Integrations
4 days ago
Validator
11 months ago
class-bootstrap.php
3 months ago
class-container.php
9 months ago
class-email-css-inliner.php
9 months ago
class-email-editor-container.php
5 months ago
class-package.php
11 months ago
exceptions.php
11 months ago
index.php
11 months ago
class-email-css-inliner.php
37 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | namespace Automattic\WooCommerce\EmailEditor; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use Automattic\WooCommerce\EmailEditor\Engine\Renderer\Css_Inliner; |
| 6 | class Email_Css_Inliner implements Css_Inliner { |
| 7 | private $inliner; |
| 8 | public function from_html( string $unprocessed_html ): self { |
| 9 | $inliner_class = $this->get_inliner_class(); |
| 10 | $that = new self(); |
| 11 | $that->inliner = $inliner_class::fromHtml( $unprocessed_html ); |
| 12 | return $that; |
| 13 | } |
| 14 | public function inline_css( string $css = '' ): self { |
| 15 | if ( ! isset( $this->inliner ) ) { |
| 16 | throw new \LogicException( 'You must call from_html before calling inline_css' ); |
| 17 | } |
| 18 | $this->inliner->inlineCss( $css ); |
| 19 | return $this; |
| 20 | } |
| 21 | public function render(): string { |
| 22 | if ( ! isset( $this->inliner ) ) { |
| 23 | throw new \LogicException( 'You must call from_html before calling render' ); |
| 24 | } |
| 25 | return $this->inliner->render(); |
| 26 | } |
| 27 | private function get_inliner_class(): string { |
| 28 | if ( class_exists( 'Automattic\WooCommerce\Vendor\Pelago\Emogrifier\CssInliner' ) ) { |
| 29 | return 'Automattic\WooCommerce\Vendor\Pelago\Emogrifier\CssInliner'; |
| 30 | } |
| 31 | if ( class_exists( 'Automattic\WooCommerce\EmailEditorVendor\Pelago\Emogrifier\CssInliner' ) ) { |
| 32 | return 'Automattic\WooCommerce\EmailEditorVendor\Pelago\Emogrifier\CssInliner'; |
| 33 | } |
| 34 | throw new \Exception( 'CssInliner class not found' ); |
| 35 | } |
| 36 | } |
| 37 |