Sort of working beta
This commit is contained in:
44
app/Notification/NotificationBody/ListNotificationBody.php
Normal file
44
app/Notification/NotificationBody/ListNotificationBody.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notification\NotificationBody;
|
||||
|
||||
use App\Notification\NotificationBody;
|
||||
use App\Notification\Stringifiable;
|
||||
|
||||
class ListNotificationBody extends NotificationBody {
|
||||
|
||||
private array $content;
|
||||
|
||||
public function __construct(array $content) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toMarkdownString(): string {
|
||||
$string = "";
|
||||
foreach ($this->content as $item) {
|
||||
$string .= "- ". $this->getTextFromContent($item) . "\n";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toString(): string {
|
||||
$string = "";
|
||||
foreach ($this->content as $item) {
|
||||
$string .= $this->getTextFromContent($item) . "\n";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function getTextFromContent(string|Stringifiable $content): string {
|
||||
if ($content instanceof Stringifiable) {
|
||||
return $content->toString();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user