| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Message |
| 4 |
* |
| 5 |
* @package Packetery\Module |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class Message |
| 14 |
* |
| 15 |
* @package Packetery\Module |
| 16 |
*/ |
| 17 |
class Message { |
| 18 |
|
| 19 |
/** |
| 20 |
* Message. |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
private $message = ''; |
| 25 |
|
| 26 |
/** |
| 27 |
* Type. |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
private $type = MessageManager::TYPE_SUCCESS; |
| 32 |
|
| 33 |
/** |
| 34 |
* Renderer. |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
private $renderer = MessageManager::RENDERER_WORDPRESS; |
| 39 |
|
| 40 |
/** |
| 41 |
* Context. |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
private $context = ''; |
| 46 |
|
| 47 |
/** |
| 48 |
* Tells if text should be escaped. |
| 49 |
* |
| 50 |
* @var bool |
| 51 |
*/ |
| 52 |
private $escape = true; |
| 53 |
|
| 54 |
/** |
| 55 |
* Creates message. |
| 56 |
* |
| 57 |
* @return self |
| 58 |
*/ |
| 59 |
public static function create(): self { |
| 60 |
return new self(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Sets text. |
| 65 |
* |
| 66 |
* @param string $message The message text. |
| 67 |
* |
| 68 |
* @return $this |
| 69 |
*/ |
| 70 |
public function setText( string $message ): self { |
| 71 |
$this->message = $message; |
| 72 |
|
| 73 |
return $this; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Sets type. |
| 78 |
* |
| 79 |
* @param string $type Type. |
| 80 |
* |
| 81 |
* @return $this |
| 82 |
*/ |
| 83 |
public function setType( string $type ): self { |
| 84 |
$this->type = $type; |
| 85 |
|
| 86 |
return $this; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Sets renderer. |
| 91 |
* |
| 92 |
* @param string $renderer Renderer. |
| 93 |
* |
| 94 |
* @return $this |
| 95 |
*/ |
| 96 |
public function setRenderer( string $renderer ): self { |
| 97 |
$this->renderer = $renderer; |
| 98 |
|
| 99 |
return $this; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Sets context. |
| 104 |
* |
| 105 |
* @param string $context Context. |
| 106 |
* |
| 107 |
* @return $this |
| 108 |
*/ |
| 109 |
public function setContext( string $context ): self { |
| 110 |
$this->context = $context; |
| 111 |
|
| 112 |
return $this; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Sets escape flag. |
| 117 |
* |
| 118 |
* @param bool $escape Tells if message is HTML. |
| 119 |
* |
| 120 |
* @return $this |
| 121 |
*/ |
| 122 |
public function setEscape( bool $escape ): self { |
| 123 |
$this->escape = $escape; |
| 124 |
|
| 125 |
return $this; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Converts object to array. |
| 130 |
* |
| 131 |
* @return array<string, string|bool> |
| 132 |
*/ |
| 133 |
public function toArray(): array { |
| 134 |
return get_object_vars( $this ); |
| 135 |
} |
| 136 |
} |
| 137 |
|