File: //home/artinside/sites.artinside.com.br/mainpro/source/Support/Message.php
<?php
namespace Source\Support;
use Source\Core\Session;
/**
* FSPHP | Class Message
*
* @author Robson V. Leite <cursos@upinside.com.br>
* @package Source\Core
*/
class Message
{
/** @var string */
private $text;
/** @var string */
private $type;
/** @var string */
private $icon;
/** @var string */
private $before;
/** @var string */
private $after;
/**
* @return string
*/
public function __toString()
{
return $this->render();
}
/**
* @return string
*/
public function getText(): ?string
{
return $this->before . $this->text . $this->after;
}
/**
* @return string
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @return string
*/
public function getIcon(): ?string
{
return $this->icon;
}
/**
* @param string $text
* @return Message
*/
public function before(string $text): Message
{
$this->before = $text;
return $this;
}
/**
* @param string $text
* @return Message
*/
public function after(string $text): Message
{
$this->after = $text;
return $this;
}
/**
* @param string $message
* @return Message
*/
public function info(string $message): Message
{
$this->type = "info";
$this->icon = "fal fa-info";
$this->text = $this->filter($message);
return $this;
}
/**
* @param string $message
* @return Message
*/
public function success(string $message): Message
{
$this->type = "success";
$this->icon = "fal fa-badge-check";
$this->text = $this->filter($message);
return $this;
}
/**
* @param string $message
* @return Message
*/
public function warning(string $message): Message
{
$this->type = "warning";
$this->icon = "fal fa-exclamation-circle";
$this->text = $this->filter($message);
return $this;
}
/**
* @param string $message
* @return Message
*/
public function error(string $message): Message
{
$this->type = "error";
$this->icon = "fal fa-exclamation-circle";
$this->text = $this->filter($message);
return $this;
}
/**
* @return string
*/
public function render(): string
{
return "<div class='message {$this->getType()}'><i class='{$this->getIcon()} font-small' style='margin-right: 12px'></i> {$this->getText()}</div>";
}
/**
* Set flash Session Key
*/
public function flash(): void
{
(new Session())->set("flash", $this);
}
/**
* @param string $message
* @return string
*/
private function filter(string $message): string
{
return filter_var($message, FILTER_SANITIZE_STRIPPED);
}
}