public function render(MessageCollection $messages) { $output = ''; if ($messages->count()) { if ($this->wrapOutput) { $output .= "<script type=\"text/javascript\">\n"; } foreach ($messages as $message) { switch ($message->get('_type')) { case AlertType::ERROR: $output .= $this->renderError($message); break; case AlertType::NOTICE: $output .= $this->renderNotice($message); break; case AlertType::WARNING: $output .= $this->renderWarning($message); break; case AlertType::SUCCESS: $output .= $this->renderSuccess($message); break; default: // Don't know how to handle this type break; } } if ($this->wrapOutput) { $output .= "</script>\n"; } } return $output; }
public function retrieve(MessageCollection $messages) { if (isset($_SESSION[$this->sessionKey])) { foreach ($_SESSION[$this->sessionKey] as $msg) { $messages->add(new Message($msg[0], $msg[1])); } // Remove from session unset($_SESSION[$this->sessionKey]); } }
/** * Render the given MessageCollection as Bootstrap HTML * See: http://getbootstrap.com/ * * @param MessageCollection $messages * @return string */ public function render(MessageCollection $messages) { $output = ''; foreach ($messages->pluck('_type') as $type) { switch ($type) { case 'success': $output .= '<div class="alert alert-success">' . implode("<br>", $messages->filter(['_type' => $type])->getMessages()) . '</div>'; break; case 'notice': $output .= '<div class="alert alert-info">' . implode("<br>", $messages->filter(['_type' => $type])->getMessages()) . '</div>'; break; case 'warning': $output .= '<div class="alert alert-warning">' . implode("<br>", $messages->filter(['_type' => $type])->getMessages()) . '</div>'; break; case 'error': $output .= '<div class="alert alert-danger">' . implode("<br>", $messages->filter(['_type' => $type])->getMessages()) . '</div>'; break; } } return $output; }
/** * Clears all the messages */ public function clear() { $this->messages->clear(); }