-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][FEATURE] Add new notifications feature #104
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
namespace T3Monitor\T3monitoring\Notification; | ||
|
||
/* | ||
* This file is part of the t3monitoring extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use T3Monitor\T3monitoring\Notification\Channel\AbstractNotificationChannel; | ||
use TYPO3\CMS\Core\Utility\ArrayUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Class AbstractNotification | ||
*/ | ||
abstract class AbstractNotification { | ||
/** | ||
* @var AbstractNotificationChannel[] | ||
*/ | ||
protected $channels; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wanna move the /** @var array */ syntax? because no description will be used and will save some lines. |
||
* @var array | ||
*/ | ||
protected $overrideChannelConfig; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $subject; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $message; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $data; | ||
|
||
/** | ||
* AbstractNotification constructor. | ||
* | ||
* @param string $subject | ||
* @param string $message | ||
* @param array $data | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function __construct($subject, $message = '', array $data = []) { | ||
$this->subject = $subject; | ||
$this->message = $message; | ||
$this->data = $data; | ||
|
||
$channels = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3monitoring'][get_class($this)]['channels']; | ||
if (!empty($channels) && is_array($channels)) { | ||
foreach ($channels as $channelClass => $channelConfig) { | ||
$this->channels[] = GeneralUtility::makeInstance($channelClass, $channelConfig); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Send notification to all configured channels | ||
*/ | ||
public function send() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's follow cgl, new lines |
||
if (!empty($this->channels)) { | ||
foreach ($this->channels as $channel) { | ||
if (!empty($this->overrideChannelConfig[get_class($channel)])) { | ||
$options = $channel->getOptions(); | ||
ArrayUtility::mergeRecursiveWithOverrule($options, $this->overrideChannelConfig[get_class($channel)]); | ||
$channel->setOptions($options); | ||
} | ||
$channel->process($this); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSubject() | ||
{ | ||
return $this->subject; | ||
} | ||
|
||
/** | ||
* @param string $subject | ||
* | ||
* @return $this | ||
*/ | ||
public function setSubject($subject) | ||
{ | ||
$this->subject = $subject; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMessage() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
/** | ||
* @param string $message | ||
* | ||
* @return $this | ||
*/ | ||
public function setMessage($message) | ||
{ | ||
$this->message = $message; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return $this | ||
*/ | ||
public function setData(array $data) | ||
{ | ||
$this->data = $data; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getOverrideChannelConfig() | ||
{ | ||
return $this->overrideChannelConfig; | ||
} | ||
|
||
/** | ||
* @param mixed $overrideChannelConfig | ||
* | ||
* @return AbstractNotification | ||
*/ | ||
public function setOverrideChannelConfig($overrideChannelConfig) | ||
{ | ||
$this->overrideChannelConfig = $overrideChannelConfig; | ||
return $this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace T3Monitor\T3monitoring\Notification\Channel; | ||
|
||
/* | ||
* This file is part of the t3monitoring extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use T3Monitor\T3monitoring\Notification\AbstractNotification; | ||
|
||
/** | ||
* Class AbstractNotificationChannel | ||
*/ | ||
abstract class AbstractNotificationChannel implements NotificationChannelInterface { | ||
/** | ||
* @var array | ||
*/ | ||
protected $options; | ||
|
||
public function __construct(array $options) { | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @param AbstractNotification $notification | ||
*/ | ||
abstract public function process(AbstractNotification $notification); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOptions() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return AbstractNotificationChannel | ||
*/ | ||
public function setOptions(array $options) | ||
{ | ||
$this->options = $options; | ||
return $this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace T3Monitor\T3monitoring\Notification\Channel; | ||
|
||
/* | ||
* This file is part of the t3monitoring extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use T3Monitor\T3monitoring\Notification\AbstractNotification; | ||
use TYPO3\CMS\Core\Mail\MailMessage; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Class EmailChannel | ||
* Options: | ||
* - senderAddress | ||
* - senderName | ||
* - recipientAddress | ||
*/ | ||
class EmailChannel extends AbstractNotificationChannel | ||
{ | ||
/** | ||
* @param AbstractNotification $notification | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function process(AbstractNotification $notification) | ||
{ | ||
$mailMessage = GeneralUtility::makeInstance(MailMessage::class); | ||
$mailMessage | ||
->setSubject($notification->getSubject()) | ||
->addFrom($this->getOptions()['senderAddress'], $this->getOptions()['senderName']) | ||
->setTo($this->getOptions()['recipientAddress']) | ||
->setBody($notification->getMessage()) | ||
->setContentType('text/plain'); | ||
$mailMessage->send(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we check response? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to avoid those lines