Classes/Domain/Notification/Slack/Application/EntitySlack/Service/EntitySlackMessageBuilder.php
<?php
declare(strict_types=1);
/*
* Copyright (C)
* Nathan Boiron <nathan.boiron@gmail.com>
* Romain Canon <romain.hydrocanon@gmail.com>
*
* This file is part of the TYPO3 NotiZ project.
* It is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, either
* version 3 of the License, or any later version.
*
* For the full copyright and license information, see:
* http://www.gnu.org/licenses/gpl-3.0.html
*/
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Service;
use CuyZ\Notiz\Core\Channel\Payload;
use CuyZ\Notiz\Core\Property\Factory\PropertyFactory;
use CuyZ\Notiz\Core\Property\Service\MarkerParser;
use CuyZ\Notiz\Domain\Notification\Slack\SlackNotification;
use CuyZ\Notiz\Domain\Property\Marker;
class EntitySlackMessageBuilder
{
/**
* @var SlackNotification
*/
protected $notification;
/**
* @var MarkerParser
*/
protected $markerParser;
/**
* @var Marker[]
*/
protected $markers = [];
/**
* @param Payload $payload
* @param MarkerParser $markerParser
* @param PropertyFactory $propertyFactory
*/
public function __construct(Payload $payload, MarkerParser $markerParser, PropertyFactory $propertyFactory)
{
$this->notification = $payload->getNotification();
$this->markerParser = $markerParser;
$this->markers = $propertyFactory->getProperties(Marker::class, $payload->getEvent());
}
/**
* Returns the message with markers replaced.
*
* @return string
*/
public function getMessage(): string
{
return $this->markerParser->replaceMarkers(
$this->notification->getMessage(),
$this->markers
);
}
}