UserFrosting API

SessionAlertStream extends AlertStream

SessionAlertStream Class Implements a message stream for use between HTTP requests, with i18n support via the Translator class Using the session storage to store the alerts.

Implements an alert stream for use between HTTP requests, with i18n support via the Translator class

Tags
author

Alex Weissman (https://alexanderweissman.com)

Table of Contents

$session Session
$messagesKey string
$translator Translator|null
__construct() Create a new message stream. mixed
messages() Get the messages from this message stream. array
resetMessageStream() Clear all messages from this message stream. mixed
saveMessages() Save messages to the stream. mixed
__construct() Create a new message stream. mixed
setTranslator() Set the translator to be used for all message streams. Must be done before `addMessageTranslated` can be used. self
addMessage() Adds a raw text message to the cache message stream. self
addMessageTranslated() Adds a text message to the cache message stream, translated into the currently selected language. self
getAndClearMessages() Get the messages and then clear the message stream. array
addValidationErrors() Add error messages from a ServerSideValidator object to the message stream. mixed
translator() Return the translator for this message stream. Translator
messages() Get the messages from this message stream. array
resetMessageStream() Clear all messages from this message stream. mixed
saveMessages() Save messages to the stream. mixed

Properties

Methods

__construct()

Create a new message stream.

public __construct( $messagesKey : string [, $translator : Translator|null = null ] , $session : Session ) : mixed
Parameters
$messagesKey : string

Store the messages under this key

$translator : Translator|null = null
$session : Session
Return values
mixed

messages()

Get the messages from this message stream.

public messages( ) : array
Return values
array

An array of messages, each of which is itself an array containing "type" and "message" fields.

resetMessageStream()

Clear all messages from this message stream.

public resetMessageStream( ) : mixed
Return values
mixed

saveMessages()

Save messages to the stream.

protected saveMessages( $messages : array ) : mixed
Parameters
$messages : array

The message

Return values
mixed

__construct()

Create a new message stream.

public __construct( $messagesKey : string [, $translator : Translator|null = null ] ) : mixed
Parameters
$messagesKey : string
$translator : Translator|null = null
Return values
mixed

setTranslator()

Set the translator to be used for all message streams. Must be done before `addMessageTranslated` can be used.

public setTranslator( [ $translator : Translator|null = null ] ) : self
Parameters
$translator : Translator|null = null

A Translator to be used to translate messages when added via addMessageTranslated.

Return values
self

addMessage()

Adds a raw text message to the cache message stream.

public addMessage( $type : string , $message : string ) : self
Parameters
$type : string

The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".

$message : string

The message to be added to the message stream.

Return values
self

this MessageStream object.

addMessageTranslated()

Adds a text message to the cache message stream, translated into the currently selected language.

public addMessageTranslated( $type : string , $messageId : string [, $placeholders : array = [] ] ) : self
Parameters
$type : string

The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".

$messageId : string

The message id for the message to be added to the message stream.

$placeholders : array = []

An optional hash of placeholder names => placeholder values to substitute into the translated message.

Tags
throws
RuntimeException
Return values
self

this MessageStream object.

getAndClearMessages()

Get the messages and then clear the message stream.

public getAndClearMessages( ) : array

This function does the same thing as messages(), except that it also clears all messages afterwards. This is useful, because typically we don't want to view the same messages more than once.

Return values
array

An array of messages, each of which is itself an array containing "type" and "message" fields.

translator()

Return the translator for this message stream.

public translator( ) : Translator
Return values
Translator

The translator for this message stream.

messages()

Get the messages from this message stream.

public abstract messages( ) : array
Return values
array

An array of messages, each of which is itself an array containing "type" and "message" fields.

resetMessageStream()

Clear all messages from this message stream.

public abstract resetMessageStream( ) : mixed
Return values
mixed

saveMessages()

Save messages to the stream.

protected abstract saveMessages( $messages : array ) : mixed
Parameters
$messages : array
Return values
mixed

Search results