class Message (View source)

a single message

simple usage examples: // display simple error message 'Error' echo Message::error()->getDisplay();

// get simple success message 'Success' $message = Message::success();

// get special notice $message = Message::notice(__('This is a localized notice'));

more advanced usage example: // create another message, a hint, with a localized string which expects $hint = Message::notice('Read the %smanual%s'); // replace placeholders with the following params $hint->addParam('[doc@cfg_Example]'); $hint->addParam('[/doc]'); // add this hint as a tooltip $hint = showHint($hint);

// add the retrieved tooltip reference to the original message $message->addMessage($hint);

Constants

SUCCESS

NOTICE

ERROR

SANITIZE_NONE

SANITIZE_STRING

SANITIZE_PARAMS

SANITIZE_BOOTH

Properties

static array $level message levels
protected int $number The message number
protected string $string The locale string identifier
protected string $message The formatted message
protected bool $isDisplayed Whether the message was already displayed
protected bool $useBBCode Whether to use BB code when displaying.
protected string $hash Unique id
protected array $params holds parameters
protected array $addedMessages holds additional messages

Methods

__construct(string $string = '', int $number = self::NOTICE, array $params = [], int $sanitize = self::SANITIZE_NONE)

No description

string
__toString()

magic method: return string representation for this object

static Message
success(string $string = '')

get Message of type success

static Message
error(string $string = '')

get Message of type error

static Message
notice(string $string)

get Message of type notice

static Message
raw(string $message, int $type = self::NOTICE)

get Message with customized content

static Message
getMessageForAffectedRows(int $rows)

get Message for number of affected rows

static Message
getMessageForDeletedRows(int $rows)

get Message for number of deleted rows

static Message
getMessageForInsertedRows(int $rows)

get Message for number of inserted rows

static Message
rawError(string $message)

get Message of type error with custom content

static Message
rawNotice(string $message)

get Message of type notice with custom content

static Message
rawSuccess(string $message)

get Message of type success with custom content

bool
isSuccess(bool $set = false)

returns whether this message is a success message or not and optionally makes this message a success message

bool
isNotice(bool $set = false)

returns whether this message is a notice message or not and optionally makes this message a notice message

bool
isError(bool $set = false)

returns whether this message is an error message or not and optionally makes this message an error message

void
setBBCode(bool $useBBCode)

Set whether we should use BB Code when rendering.

void
setMessage(string $message, bool $sanitize = false)

set raw message (overrides string)

void
setString(string $string, bool|int $sanitize = true)

set string (does not take effect if raw message is set)

void
setNumber(int $number)

set message type number

void
addParam(mixed $param)

add string or Message parameter

void
addParamHtml(string $param)

add parameter as raw HTML, usually in conjunction with strings

void
addMessages(array $messages, string $separator = ' ')

add a bunch of messages at once

void
addMessagesString(array $messages, string $separator = ' ')

add a bunch of messages at once

void
addMessage(Message $message, string $separator = ' ')

add another raw message to be concatenated on displaying

void
addText(string $message, string $separator = ' ')

add another raw message to be concatenated on displaying

void
addHtml(string $message, string $separator = ' ')

add another html message to be concatenated on displaying

void
setParams(array $params, bool|int $sanitize = false)

set all params at once, usually used in conjunction with string

array
getParams()

return all parameters

array
getAddedMessages()

return all added messages

static mixed
sanitize(mixed $message)

Sanitizes $message

static string
decodeBB(string $message)

decode $message, taking into account our special codes for formatting

static string
format(array ...$params)

wrapper for sprintf()

string
getHash()

returns unique Message::$hash, if not exists it will be created

string
getMessage()

returns compiled message

string
getOnlyMessage()

Returns only message string without image & other HTML.

string
getString()

returns Message::$string

int
getNumber()

returns Message::$number

string
getLevel()

returns level of message

string
getDisplay()

returns HTML code for displaying this message

bool
isDisplayed(bool $isDisplayed = false)

sets and returns whether the message was displayed or not

string
getMessageWithIcon(string $message)

Returns the message with corresponding image icon

Details

__construct(string $string = '', int $number = self::NOTICE, array $params = [], int $sanitize = self::SANITIZE_NONE)

Parameters

string $string The message to be displayed
int $number A numeric representation of the type of message
array $params An array of parameters to use in the message
int $sanitize A flag to indicate what to sanitize, see constant definitions above

string __toString()

magic method: return string representation for this object

Return Value

string

static Message success(string $string = '')

get Message of type success

shorthand for getting a simple success message

Parameters

string $string A localized string e.g. __('Your SQL query has been executed successfully')

Return Value

Message

static Message error(string $string = '')

get Message of type error

shorthand for getting a simple error message

Parameters

string $string A localized string e.g. __('Error')

Return Value

Message

static Message notice(string $string)

get Message of type notice

shorthand for getting a simple notice message

Parameters

string $string A localized string e.g. __('The additional features for working with linked tables have been deactivated. To find out why click %shere%s.')

Return Value

Message

static Message raw(string $message, int $type = self::NOTICE)

get Message with customized content

shorthand for getting a customized message

Parameters

string $message A localized string
int $type A numeric representation of the type of message

Return Value

Message

static Message getMessageForAffectedRows(int $rows)

get Message for number of affected rows

shorthand for getting a customized message

Parameters

int $rows Number of rows

Return Value

Message

static Message getMessageForDeletedRows(int $rows)

get Message for number of deleted rows

shorthand for getting a customized message

Parameters

int $rows Number of rows

Return Value

Message

static Message getMessageForInsertedRows(int $rows)

get Message for number of inserted rows

shorthand for getting a customized message

Parameters

int $rows Number of rows

Return Value

Message

static Message rawError(string $message)

get Message of type error with custom content

shorthand for getting a customized error message

Parameters

string $message A localized string

Return Value

Message

static Message rawNotice(string $message)

get Message of type notice with custom content

shorthand for getting a customized notice message

Parameters

string $message A localized string

Return Value

Message

static Message rawSuccess(string $message)

get Message of type success with custom content

shorthand for getting a customized success message

Parameters

string $message A localized string

Return Value

Message

bool isSuccess(bool $set = false)

returns whether this message is a success message or not and optionally makes this message a success message

Parameters

bool $set Whether to make this message of SUCCESS type

Return Value

bool whether this is a success message or not

bool isNotice(bool $set = false)

returns whether this message is a notice message or not and optionally makes this message a notice message

Parameters

bool $set Whether to make this message of NOTICE type

Return Value

bool whether this is a notice message or not

bool isError(bool $set = false)

returns whether this message is an error message or not and optionally makes this message an error message

Parameters

bool $set Whether to make this message of ERROR type

Return Value

bool Whether this is an error message or not

void setBBCode(bool $useBBCode)

Set whether we should use BB Code when rendering.

Parameters

bool $useBBCode Use BB Code?

Return Value

void

void setMessage(string $message, bool $sanitize = false)

set raw message (overrides string)

Parameters

string $message A localized string
bool $sanitize Whether to sanitize $message or not

Return Value

void

void setString(string $string, bool|int $sanitize = true)

set string (does not take effect if raw message is set)

Parameters

string $string string to set
bool|int $sanitize whether to sanitize $string or not

Return Value

void

void setNumber(int $number)

set message type number

Parameters

int $number message type number to set

Return Value

void

void addParam(mixed $param)

add string or Message parameter

usage $message->addParam('[em]some string[/em]');

Parameters

mixed $param parameter to add

Return Value

void

void addParamHtml(string $param)

add parameter as raw HTML, usually in conjunction with strings

usage $message->addParamHtml('');

Parameters

string $param parameter to add

Return Value

void

void addMessages(array $messages, string $separator = ' ')

add a bunch of messages at once

Parameters

array $messages to be added
string $separator to use between this and previous string/message

Return Value

void

void addMessagesString(array $messages, string $separator = ' ')

add a bunch of messages at once

Parameters

array $messages to be added
string $separator to use between this and previous string/message

Return Value

void

void addMessage(Message $message, string $separator = ' ')

add another raw message to be concatenated on displaying

Parameters

Message $message to be added
string $separator to use between this and previous string/message

Return Value

void

void addText(string $message, string $separator = ' ')

add another raw message to be concatenated on displaying

Parameters

string $message to be added
string $separator to use between this and previous string/message

Return Value

void

void addHtml(string $message, string $separator = ' ')

add another html message to be concatenated on displaying

Parameters

string $message to be added
string $separator to use between this and previous string/message

Return Value

void

void setParams(array $params, bool|int $sanitize = false)

set all params at once, usually used in conjunction with string

Parameters

array $params parameters to set
bool|int $sanitize whether to sanitize params

Return Value

void

array getParams()

return all parameters

Return Value

array

array getAddedMessages()

return all added messages

Return Value

array

static mixed sanitize(mixed $message)

Sanitizes $message

Parameters

mixed $message the message(s)

Return Value

mixed the sanitized message(s)

static string decodeBB(string $message)

decode $message, taking into account our special codes for formatting

Parameters

string $message the message

Return Value

string the decoded message

static string format(array ...$params)

wrapper for sprintf()

Parameters

array ...$params Params

Return Value

string formatted

string getHash()

returns unique Message::$hash, if not exists it will be created

Return Value

string Message::$hash

string getMessage()

returns compiled message

Return Value

string complete message

string getOnlyMessage()

Returns only message string without image & other HTML.

Return Value

string

string getString()

returns Message::$string

Return Value

string Message::$string

int getNumber()

returns Message::$number

Return Value

int Message::$number

string getLevel()

returns level of message

Return Value

string level of message

string getDisplay()

returns HTML code for displaying this message

Return Value

string whole message box

bool isDisplayed(bool $isDisplayed = false)

sets and returns whether the message was displayed or not

Parameters

bool $isDisplayed whether to set displayed flag

Return Value

bool Message::$isDisplayed

string getMessageWithIcon(string $message)

Returns the message with corresponding image icon

Parameters

string $message the message(s)

Return Value

string message with icon