| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | namespace Packetery\Module; |
| 11 | 11 | |
| 12 | 12 | use Packetery\Latte\Engine; |
| 13 | +use Packetery\Module\Framework\WpAdapter; | |
| 13 | 14 | |
| 14 | 15 | /** |
| 15 | 16 | * Class Message_Manager |
| 16 | 17 | * |
| @@ -34,21 +35,25 @@ | ||
| 34 | 35 | */ |
| 35 | 36 | private $latteEngine; |
| 36 | 37 | |
| 37 | 38 | /** |
| 39 | + * @var WpAdapter | |
| 40 | + */ | |
| 41 | + private $wpAdapter; | |
| 42 | + | |
| 43 | + /** | |
| 38 | 44 | * Messages to be displayed. |
| 39 | 45 | * |
| 40 | - * @var array | |
| 46 | + * @var array<array<string, string>> | |
| 41 | 47 | */ |
| 42 | 48 | private $messages = []; |
| 43 | 49 | |
| 44 | - /** | |
| 45 | - * Message_Manager constructor. | |
| 46 | - * | |
| 47 | - * @param Engine $latteEngine PacketeryLatte engine. | |
| 48 | - */ | |
| 49 | - public function __construct( Engine $latteEngine ) { | |
| 50 | + public function __construct( | |
| 51 | + Engine $latteEngine, | |
| 52 | + WpAdapter $wpAdapter | |
| 53 | + ) { | |
| 50 | 54 | $this->latteEngine = $latteEngine; |
| 55 | + $this->wpAdapter = $wpAdapter; | |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | /** |
| 54 | 59 | * Inits manager on plugin load. |
| @@ -53,10 +58,10 @@ | ||
| 53 | 58 | /** |
| 54 | 59 | * Inits manager on plugin load. |
| 55 | 60 | */ |
| 56 | 61 | public function init(): void { |
| 57 | - $messages = get_transient( $this->getTransientName() ); | |
| 58 | - if ( ! $messages ) { | |
| 62 | + $messages = $this->wpAdapter->getTransient( $this->getTransientName() ); | |
| 63 | + if ( $messages === false ) { | |
| 59 | 64 | $messages = []; |
| 60 | 65 | } |
| 61 | 66 | |
| 62 | 67 | $this->messages = $messages; |
| @@ -65,9 +70,9 @@ | ||
| 65 | 70 | /** |
| 66 | 71 | * Gets transient name. |
| 67 | 72 | */ |
| 68 | 73 | private function getTransientName(): string { |
| 69 | - return 'packetery_message_manager_messages_' . wp_get_session_token(); | |
| 74 | + return Transients::MESSAGE_MANAGER_MESSAGES_PREFIX . $this->wpAdapter->getSessionToken(); | |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | /** |
| 73 | 78 | * Flashes messages to end user. |
| @@ -108,9 +113,9 @@ | ||
| 108 | 113 | */ |
| 109 | 114 | private function flashMessageArray( array $message ): void { |
| 110 | 115 | $this->messages[] = $message; |
| 111 | 116 | |
| 112 | - set_transient( $this->getTransientName(), $this->messages, self::EXPIRATION ); | |
| 117 | + $this->wpAdapter->setTransient( $this->getTransientName(), $this->messages, self::EXPIRATION ); | |
| 113 | 118 | } |
| 114 | 119 | |
| 115 | 120 | /** |
| 116 | 121 | * Renders messages. |
| @@ -151,8 +156,9 @@ | ||
| 151 | 156 | |
| 152 | 157 | unset( $this->messages[ $key ] ); |
| 153 | 158 | } |
| 154 | 159 | |
| 155 | - set_transient( $this->getTransientName(), $this->messages, self::EXPIRATION ); | |
| 160 | + $this->wpAdapter->setTransient( $this->getTransientName(), $this->messages, self::EXPIRATION ); | |
| 161 | + | |
| 156 | 162 | return $output; |
| 157 | 163 | } |
| 158 | 164 | } |