Acf
2 days ago
Admin
2 days ago
Ajax
2 days ago
ApplyFilter
2 days ago
Asset
2 days ago
Capabilities
2 days ago
Check
2 days ago
Collection
2 days ago
Column
2 days ago
ColumnFactories
2 days ago
ColumnFactory
2 days ago
ColumnIterator
2 days ago
ColumnRepository
2 days ago
ColumnSize
2 days ago
DI
2 days ago
DefaultColumnHandler
2 days ago
Deprecated
2 days ago
Entity
2 days ago
Exception
2 days ago
Expression
2 days ago
Form
2 days ago
Formatter
2 days ago
Helper
2 days ago
Integration
2 days ago
ListScreenRepository
2 days ago
ListTable
2 days ago
Message
2 days ago
Meta
2 days ago
Nonce
2 days ago
Notice
2 days ago
Plugin
2 days ago
Preferences
2 days ago
Promo
2 days ago
Request
2 days ago
RequestHandler
2 days ago
Response
2 days ago
Sanitize
2 days ago
Service
2 days ago
Setting
2 days ago
Settings
2 days ago
Storage
2 days ago
Table
2 days ago
TableIdsFactory
2 days ago
TableScreen
2 days ago
TableScreenFactory
2 days ago
ThirdParty
2 days ago
Type
2 days ago
Value
2 days ago
View
2 days ago
Acf.php
2 days ago
AdminColumns.php
2 days ago
ArrayIterator.php
2 days ago
Capabilities.php
2 days ago
Collection.php
2 days ago
CollectionFormatter.php
2 days ago
Column.php
2 days ago
ColumnCollection.php
2 days ago
ColumnFactoryCollectionFactory.php
2 days ago
ColumnFactoryDefinitionCollection.php
2 days ago
ColumnGroups.php
2 days ago
ColumnIterator.php
2 days ago
ColumnNamesTrait.php
2 days ago
ColumnRepository.php
2 days ago
ColumnTypeRepository.php
2 days ago
Config.php
2 days ago
DateFormats.php
2 days ago
DefaultColumnHandler.php
2 days ago
Expirable.php
2 days ago
Formatter.php
2 days ago
FormatterCollection.php
2 days ago
Helper.php
2 days ago
ListScreen.php
2 days ago
ListScreenCollection.php
2 days ago
ListScreenRepository.php
2 days ago
ListScreenRepositoryWritable.php
2 days ago
ListTable.php
2 days ago
ListTableFactory.php
2 days ago
Loader.php
2 days ago
Message.php
2 days ago
MetaType.php
2 days ago
Middleware.php
2 days ago
OpCacheInvalidateTrait.php
2 days ago
PluginActionLinks.php
2 days ago
PluginActionUpgrade.php
2 days ago
PostType.php
2 days ago
PostTypeRepository.php
2 days ago
Registerable.php
2 days ago
Registry.php
2 days ago
Renderable.php
2 days ago
Request.php
2 days ago
RequestAjaxHandler.php
2 days ago
RequestAjaxHandlers.php
2 days ago
RequestAjaxParser.php
2 days ago
RequestHandler.php
2 days ago
RequestHandlerFactory.php
2 days ago
Screen.php
2 days ago
Services.php
2 days ago
TableIdsFactory.php
2 days ago
TableScreen.php
2 days ago
TableScreenFactory.php
2 days ago
Taxonomy.php
2 days ago
Transient.php
2 days ago
TypedArrayIterator.php
2 days ago
View.php
2 days ago
WooCommerce.php
2 days ago
WpListTableFactory.php
2 days ago
Message.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC; |
| 6 | |
| 7 | use LogicException; |
| 8 | |
| 9 | abstract class Message |
| 10 | { |
| 11 | public const SUCCESS = 'updated'; // green |
| 12 | public const ERROR = 'notice-error'; // red |
| 13 | public const WARNING = 'notice-warning'; // yellow |
| 14 | public const INFO = 'notice-info'; // blue |
| 15 | |
| 16 | protected string $message; |
| 17 | |
| 18 | protected string $type; |
| 19 | |
| 20 | protected string $id = ''; |
| 21 | |
| 22 | public function __construct(string $message, ?string $type = null) |
| 23 | { |
| 24 | $this->type = $type ?? self::SUCCESS; |
| 25 | $this->message = trim($message); |
| 26 | |
| 27 | $this->validate(); |
| 28 | } |
| 29 | |
| 30 | protected function validate(): void |
| 31 | { |
| 32 | if (empty($this->message)) { |
| 33 | throw new LogicException('Message cannot be empty.'); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | abstract public function render(): string; |
| 38 | |
| 39 | /** |
| 40 | * Display self::render to the screen |
| 41 | */ |
| 42 | public function display(): void |
| 43 | { |
| 44 | echo $this->render(); |
| 45 | } |
| 46 | |
| 47 | public function get_message(): string |
| 48 | { |
| 49 | return $this->message; |
| 50 | } |
| 51 | |
| 52 | public function get_type(): string |
| 53 | { |
| 54 | return $this->type; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return static |
| 59 | */ |
| 60 | public function set_type(string $type): self |
| 61 | { |
| 62 | $this->type = $type; |
| 63 | |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | public function get_id(): string |
| 68 | { |
| 69 | return $this->id; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @return static |
| 74 | */ |
| 75 | public function set_id(string $id): self |
| 76 | { |
| 77 | $this->id = $id; |
| 78 | |
| 79 | return $this; |
| 80 | } |
| 81 | |
| 82 | } |
| 83 |