Documentation

Message
in package

Message

Handles status messages on single pages or across redirects

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

version
3.0.0
subpackage

core

todo

Distinguish between flash and deferred messages

Table of Contents

Constants

CLASS_ERROR  : mixed = 'error'
The Message class names
CLASS_INFO  : mixed = 'information'
CLASS_OK  : mixed = 'ok'
CLASS_WARN  : mixed = 'warning'

Properties

$message_classes  : array<string|int, mixed>
Known message classes
$capturedMessages  : mixed
Caches messages for a request in CLI mode
$outputMessagesOnCli  : bool
Use captureCliMessages() to set to false, then use getCapturedMessages() to retrieve them.

Methods

add()  : void
Adds a message of the given class
captureCliMessages()  : void
If called messages in CLI mode are captured instead of output
clear()  : mixed
Clears the messages
error()  : bool
Adds a message of class "error"
get()  : string
Returns a message string, if any are present
getCapturedMessages()  : array<string|int, mixed>
Returns the captured messages and resets CLI output
have()  : string
Returns true if there are messages present
information()  : mixed
Adds a message of class "information"
ok()  : bool
Adds a message of class "ok"
random_class()  : string
Returns a random message class (for testing purposes only)
restore()  : mixed
Restores the messages from the stack, if any.
save()  : mixed
Saves the current messages on the stack
show()  : mixed
Shows the collected messages
toArray()  : array<string|int, mixed>
Formats variable of an unknown type into array and returns it
warning()  : mixed
Adds a message of class "warning"
checkForSession()  : bool
Check if there is a session present
show_backend()  : mixed
Shows the collected messages, if any
show_frontend()  : bool
Shows the collected messages, if any

Constants

CLASS_ERROR

The Message class names

public mixed CLASS_ERROR = 'error'

Properties

$message_classes

Known message classes

public static array<string|int, mixed> $message_classes = array(self::CLASS_ERROR, self::CLASS_WARN, self::CLASS_INFO, self::CLASS_OK)

Messages are grouped by class and shown in the order used here. Note: The order here is relevant, because some modules may only use one message class, which must then be the most urgent one! See show_frontend() for an example.

$capturedMessages

Caches messages for a request in CLI mode

protected static mixed $capturedMessages = array()

$outputMessagesOnCli

Use captureCliMessages() to set to false, then use getCapturedMessages() to retrieve them.

protected static bool $outputMessagesOnCli = \true

Set to false if messages on CLI should not be output

Methods

add()

Adds a message of the given class

public static add(string $message[, string $class = self::CLASS_INFO ]) : void

The optional $class defaults to the CLASS_INFO class constant. May be empty, or one of CLASS_OK, CLASS_INFO, CLASS_WARN, or CLASS_ERROR.

Parameters
$message : string

The message to add

$class : string = self::CLASS_INFO

The optional class. Defaults to CLASS_INFO

Tags
author

Reto Kohli reto.kohli@comvation.com

static

captureCliMessages()

If called messages in CLI mode are captured instead of output

public static captureCliMessages() : void

error()

Adds a message of class "error"

public static error(string $message) : bool

Returns false for convenience.

Parameters
$message : string

The message to add

Tags
author

Reto Kohli reto.kohli@comvation.com

static
Return values
bool —

False

get()

Returns a message string, if any are present

public static get() : string

Frontend use only. Returns a concatenation of messages by looking for them in the order defined by the $message_classes array. Only messages of the first class found are used. Does not clear() the messages; either do that yourself if necessary, or call show() after this.

Return values
string —

The message string, if any, or null

getCapturedMessages()

Returns the captured messages and resets CLI output

public static getCapturedMessages() : array<string|int, mixed>
Return values
array<string|int, mixed> —

First level is message type, second a simple list of messages

have()

Returns true if there are messages present

public static have([mixed $class = null ]) : string

The optional $class parameter restricts the test to the given class of messages, so true is only returned iff there is at least one message of that class.

Parameters
$class : mixed = null
Return values
string —

$class If set, restrict the test to that message class.

information()

Adds a message of class "information"

public static information(string $message) : mixed
Parameters
$message : string

The message to add

Tags
author

Reto Kohli reto.kohli@comvation.com

static

ok()

Adds a message of class "ok"

public static ok(string $message) : bool

Returns true for convenience.

Parameters
$message : string

The message to add

Tags
author

Reto Kohli reto.kohli@comvation.com

static
Return values
bool —

True

random_class()

Returns a random message class (for testing purposes only)

public static random_class() : string
Return values
string —

A random message class

restore()

Restores the messages from the stack, if any.

public static restore() : mixed

If the stack is empty, clears the current messages.

save()

Saves the current messages on the stack

public static save() : mixed

Clears the current messages. If there are no messages, does nothing. Restore the previous state by calling restore.

show()

Shows the collected messages

public static show([Sigma $objTemplateLocal = null ]) : mixed

Decides which view to use, and clears the messages

Parameters
$objTemplateLocal : Sigma = null

The optional Template

toArray()

Formats variable of an unknown type into array and returns it

public static toArray(type $var) : array<string|int, mixed>
Parameters
$var : type
Return values
array<string|int, mixed>

warning()

Adds a message of class "warning"

public static warning(string $message) : mixed
Parameters
$message : string

The message to add

Tags
author

Reto Kohli reto.kohli@comvation.com

static

checkForSession()

Check if there is a session present

protected static checkForSession() : bool

If a session is present, but has not yet initialized, then the session will be initialized.

Return values
bool —

TRUE if a session is present. Otherwise FALSE.

show_backend()

Shows the collected messages, if any

private static show_backend([Sigma $objTemplateLocal = null ]) : mixed

Backend use only.

Parameters
$objTemplateLocal : Sigma = null

The optional Template

Tags
todo

Add the missing classes CLASS_INFO and CLASS_WARN to the backend views

Unify the placeholders, and add the message block

show_frontend()

Shows the collected messages, if any

private static show_frontend([Sigma $objTemplateLocal = null ]) : bool

Frontend use only. Returns a status according to the message classes:

  • null, if no message is present
  • false, if any message of class CLASS_ERROR is encountered
  • true, if no messages of class CLASS_ERROR are found
Parameters
$objTemplateLocal : Sigma = null

The optional Template

Return values
bool —

The status

On this page

Search results