FingersCrossed
1 year ago
ChromePhpHandler.php
1 year ago
ConsoleHandler.php
1 year ago
ElasticsearchLogstashHandler.php
1 year ago
FirePHPHandler.php
1 year ago
MailerHandler.php
1 year ago
NotifierHandler.php
1 year ago
ServerLogHandler.php
2 months ago
SwiftMailerHandler.php
1 year ago
SwiftMailerHandler.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Matomo\Dependencies\Symfony\Bridge\Monolog\Handler; |
| 12 | |
| 13 | use Matomo\Dependencies\Monolog\Handler\SwiftMailerHandler as BaseSwiftMailerHandler; |
| 14 | use Matomo\Dependencies\Symfony\Component\Console\Event\ConsoleTerminateEvent; |
| 15 | use Matomo\Dependencies\Symfony\Component\HttpKernel\Event\TerminateEvent; |
| 16 | trigger_deprecation('symfony/monolog-bridge', '5.4', '"%s" is deprecated and will be removed in 6.0.', SwiftMailerHandler::class); |
| 17 | /** |
| 18 | * Extended SwiftMailerHandler that flushes mail queue if necessary. |
| 19 | * |
| 20 | * @author Philipp Kräutli <pkraeutli@astina.ch> |
| 21 | * |
| 22 | * @final |
| 23 | * |
| 24 | * @deprecated since Symfony 5.4 |
| 25 | */ |
| 26 | class SwiftMailerHandler extends BaseSwiftMailerHandler |
| 27 | { |
| 28 | protected $transport; |
| 29 | protected $instantFlush = \false; |
| 30 | public function setTransport(\Matomo\Dependencies\Swift_Transport $transport) |
| 31 | { |
| 32 | $this->transport = $transport; |
| 33 | } |
| 34 | /** |
| 35 | * After the kernel has been terminated we will always flush messages. |
| 36 | */ |
| 37 | public function onKernelTerminate(TerminateEvent $event) |
| 38 | { |
| 39 | $this->instantFlush = \true; |
| 40 | } |
| 41 | /** |
| 42 | * After the CLI application has been terminated we will always flush messages. |
| 43 | */ |
| 44 | public function onCliTerminate(ConsoleTerminateEvent $event) |
| 45 | { |
| 46 | $this->instantFlush = \true; |
| 47 | } |
| 48 | /** |
| 49 | * {@inheritdoc} |
| 50 | */ |
| 51 | protected function send($content, array $records) : void |
| 52 | { |
| 53 | parent::send($content, $records); |
| 54 | if ($this->instantFlush) { |
| 55 | $this->flushMemorySpool(); |
| 56 | } |
| 57 | } |
| 58 | /** |
| 59 | * {@inheritdoc} |
| 60 | */ |
| 61 | public function reset() : void |
| 62 | { |
| 63 | $this->flushMemorySpool(); |
| 64 | } |
| 65 | /** |
| 66 | * Flushes the mail queue if a memory spool is used. |
| 67 | */ |
| 68 | private function flushMemorySpool() |
| 69 | { |
| 70 | $mailerTransport = $this->mailer->getTransport(); |
| 71 | if (!$mailerTransport instanceof \Matomo\Dependencies\Swift_Transport_SpoolTransport) { |
| 72 | return; |
| 73 | } |
| 74 | $spool = $mailerTransport->getSpool(); |
| 75 | if (!$spool instanceof \Matomo\Dependencies\Swift_MemorySpool) { |
| 76 | return; |
| 77 | } |
| 78 | if (null === $this->transport) { |
| 79 | throw new \Exception('No transport available to flush mail queue.'); |
| 80 | } |
| 81 | $spool->flushQueue($this->transport); |
| 82 | } |
| 83 | } |
| 84 |