| 1 | <?php |
||
| 15 | class CssInlinerPlugin implements Swift_Events_SendListener |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var CssToInlineStyles |
||
| 19 | */ |
||
| 20 | private $converter; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param CssToInlineStyles $converter |
||
| 24 | */ |
||
| 25 | public function __construct(CssToInlineStyles $converter = null) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param Swift_Events_SendEvent $event |
||
| 36 | */ |
||
| 37 | 1 | public function beforeSendPerformed(Swift_Events_SendEvent $event) |
|
| 38 | { |
||
| 39 | 1 | $message = $event->getMessage(); |
|
| 40 | |||
| 41 | 1 | if ($message->getContentType() === 'text/html') { |
|
| 42 | 1 | $message->setBody($this->converter->convert($message->getBody())); |
|
| 43 | } |
||
| 44 | |||
| 45 | 1 | foreach ($message->getChildren() as $part) { |
|
| 46 | if (strpos($part->getContentType(), 'text/html') === 0) { |
||
| 47 | $part->setBody($this->converter->convert($part->getBody())); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | 1 | } |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Do nothing |
||
| 54 | * |
||
| 55 | * @param Swift_Events_SendEvent $event |
||
| 56 | */ |
||
| 57 | 1 | public function sendPerformed(\Swift_Events_SendEvent $event) |
|
| 61 | } |
||
| 62 |