PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / monolog / monolog / src / Monolog / Handler / MailHandler.php

MailHandler.php in Media Cloud Sync 1.4.2, at includes/sdk/google/monolog/monolog/src/Monolog/Handler/MailHandler.php

82 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 /*
5 * This file is part of the Monolog package.
6 *
7 * (c) Jordi Boggiano <[email protected]>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12 namespace Dudlewebs\WPMCS\GCP\Monolog\Handler;
13
14 use Dudlewebs\WPMCS\GCP\Monolog\Formatter\FormatterInterface;
15 use Dudlewebs\WPMCS\GCP\Monolog\Formatter\HtmlFormatter;
16 use Dudlewebs\WPMCS\GCP\Monolog\LogRecord;
17 /**
18 * Base class for all mail handlers
19 *
20 * @author Gyula Sallai
21 */
22 abstract class MailHandler extends AbstractProcessingHandler
23 {
24 /**
25 * @inheritDoc
26 */
27 public function handleBatch(array $records) : void
28 {
29 $messages = [];
30 foreach ($records as $record) {
31 if ($record->level->isLowerThan($this->level)) {
32 continue;
33 }
34 $message = $this->processRecord($record);
35 $messages[] = $message;
36 }
37 if (\count($messages) > 0) {
38 $this->send((string) $this->getFormatter()->formatBatch($messages), $messages);
39 }
40 }
41 /**
42 * Send a mail with the given content
43 *
44 * @param string $content formatted email body to be sent
45 * @param array $records the array of log records that formed this content
46 *
47 * @phpstan-param non-empty-array<LogRecord> $records
48 */
49 protected abstract function send(string $content, array $records) : void;
50 /**
51 * @inheritDoc
52 */
53 protected function write(LogRecord $record) : void
54 {
55 $this->send((string) $record->formatted, [$record]);
56 }
57 /**
58 * @phpstan-param non-empty-array<LogRecord> $records
59 */
60 protected function getHighestRecord(array $records) : LogRecord
61 {
62 $highestRecord = null;
63 foreach ($records as $record) {
64 if ($highestRecord === null || $record->level->isHigherThan($highestRecord->level)) {
65 $highestRecord = $record;
66 }
67 }
68 return $highestRecord;
69 }
70 protected function isHtmlBody(string $body) : bool
71 {
72 return ($body[0] ?? null) === '<';
73 }
74 /**
75 * Gets the default formatter.
76 */
77 protected function getDefaultFormatter() : FormatterInterface
78 {
79 return new HtmlFormatter();
80 }
81 }
82