AlertStream
AlertStream Class.
Implements an alert stream for use between HTTP requests, with i18n support via the Translator class
Tags
Table of Contents
| $messagesKey | string | |
|---|---|---|
| $translator | Translator|null | |
| __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
$messagesKey
        protected
                string
        $messagesKey
            
            
$translator
        protected
                Translator|null
        $translator
            
            
Methods
__construct()
Create a new message stream.
        public
                                __construct(
                    
                            $messagesKey :
                string
                            
                    
            [,                 $translator :
                Translator|null
                 = null ]            
                )
        : mixed
    
    
            Parameters
- $messagesKey : string
 - $translator : Translator|null = null
 
Return values
mixedsetTranslator()
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
selfaddMessage()
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
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.
addValidationErrors()
Add error messages from a ServerSideValidator object to the message stream.
        public
                                addValidationErrors(
                    
                            $validator :
                ServerSideValidator
                            
                )
        : mixed
    
    
            Parameters
- $validator : ServerSideValidator
 
Return values
mixedtranslator()
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
mixedsaveMessages()
Save messages to the stream.
        protected
        abstract                        saveMessages(
                    
                            $messages :
                array
                            
                )
        : mixed
    
    
            Parameters
- $messages : array