-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code that sents notifications
Make sure no notification is sent twice in the same request.
- Loading branch information
Showing
3 changed files
with
160 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
classes/BlueChip/Security/Modules/Notifications/Message.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BlueChip\Security\Modules\Notifications; | ||
|
||
class Message | ||
{ | ||
/** | ||
* @var string[] Message body as lines of text | ||
*/ | ||
private array $body = []; | ||
|
||
|
||
public function __construct(string $text = '') | ||
{ | ||
$this->body = ($text !== '') ? [$text] : []; | ||
} | ||
|
||
|
||
public function __toString(): string | ||
{ | ||
return \implode(PHP_EOL, $this->body); | ||
} | ||
|
||
|
||
public function addEmptyLine(): self | ||
{ | ||
return $this->addLine(''); | ||
} | ||
|
||
|
||
public function addLine(string $text = ''): self | ||
{ | ||
$this->body[] = $text; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param string[] $text | ||
* | ||
* @return self | ||
*/ | ||
public function addLines(array $text): self | ||
{ | ||
$this->body = \array_merge($this->body, \array_is_list($text) ? $text : \array_values($text)); | ||
return $this; | ||
} | ||
|
||
|
||
public function getFingerprint(): string | ||
{ | ||
return \sha1((string) $this); | ||
} | ||
|
||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getRaw(): array | ||
{ | ||
return $this->body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters