*/ class implementation_email implements interface_output { /** * @var $auth { * record< * host:string, * port:integer, * authtype:string, * username:string, * password:string * > * } */ private $auth; /** * @var array {list} */ private $receivers; /** * @var string */ private $sender; /** * @var array {list} */ private $tags; /** * @var string */ private $implementation; /** * @author Christian Fraß */ public function __construct( array $auth, array $receivers, string $sender, array $tags, string $implementation ) { $this->auth = $auth; $this->receivers = $receivers; $this->sender = $sender; $this->tags = $tags; $this->implementation = $implementation; } /** * @implementation * @author Christian Fraß */ public function process( int $level, \alveolata\report\struct_report $report ) : void { $subject = \alveolata\string\coin( '{{tags}} {{level}}: {{incident}}', [ 'tags' => \alveolata\string\join( \alveolata\list_\map( $this->tags, function (string $tag): string { return \alveolata\string\coin('[{{tag}}]', ['tag' => $tag]); } ), ' ' ), 'level' => output_translate_level($level), 'incident' => $report->incident, ] ); $body_plain = \alveolata\string\coin( "<{{timestamp}}>\n{{details}}", [ 'timestamp' => date('Y-m-d|H:i:s', $report->timestamp), 'details' => implode( "\n", \alveolata\list_\map( array_keys($report->details), function ($key) use ($report) { $value = $report->details[$key]; return \alveolata\string\coin( '{{key}}: {{value}}', [ 'key' => $key, 'value' => json_encode($value), ] ); } ) ), ] ); \alveolata\email\send( $this->auth, [ 'to' => $this->receivers, 'from' => $this->sender, 'subject' => $subject, 'body_plain' => $body_plain, ], [ 'implementation' => $this->implementation ] ); } } ?>