Message
class Message implements Stringable (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 | $number | The message number |
|
protected | $string | The locale string identifier |
|
protected | $message | The formatted message |
|
protected | $isDisplayed | Whether the message was already displayed |
|
protected | $useBBCode | Whether to use BB code when displaying. |
|
protected | $hash | Unique id |
|
protected array | $params | holds parameters |
|
protected (string|Message)[] | $addedMessages | holds additional messages |
Methods
No description
magic method: return string representation for this object
get Message for number of affected rows
get Message for number of deleted rows
get Message for number of inserted rows
get Message of type success with custom content
returns whether this message is a success message or not and optionally makes this message a success message
returns whether this message is a notice message or not and optionally makes this message a notice message
returns whether this message is an error message or not and optionally makes this message an error message
Set whether we should use BB Code when rendering.
set raw message (overrides string)
set string (does not take effect if raw message is set)
set message type number
add string or Message parameter
add parameter as raw HTML, usually in conjunction with strings
add a bunch of messages at once
add a bunch of messages at once
add another raw message to be concatenated on displaying
add another raw message to be concatenated on displaying
add another html message to be concatenated on displaying
set all params at once, usually used in conjunction with string
return all parameters
return all added messages
Sanitizes $message
decode $message, taking into account our special codes for formatting
returns unique Message::$hash, if not exists it will be created
returns compiled message
Returns only message string without image & other HTML.
returns Message::$string
returns Message::$number
returns level of message
returns HTML code for displaying this message
sets and returns whether the message was displayed or not
Returns the message with corresponding image icon
Details
__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
shorthand for getting a simple success message
static Message
error(string $string = '')
get Message of type error
shorthand for getting a simple error message
static Message
notice(string $string)
get Message of type notice
shorthand for getting a simple notice message
static Message
raw(string $message, int $type = self::NOTICE)
get Message with customized content
shorthand for getting a customized message
static Message
getMessageForAffectedRows(int $rows)
get Message for number of affected rows
shorthand for getting a customized message
static Message
getMessageForDeletedRows(int $rows)
get Message for number of deleted rows
shorthand for getting a customized message
static Message
getMessageForInsertedRows(int $rows)
get Message for number of inserted rows
shorthand for getting a customized message
static Message
rawError(string $message)
get Message of type error with custom content
shorthand for getting a customized error message
static Message
rawNotice(string $message)
get Message of type notice with custom content
shorthand for getting a customized notice message
static Message
rawSuccess(string $message)
get Message of type success with custom content
shorthand for getting a customized success message
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
usage
$message->addParam('[em]some string[/em]');
void
addParamHtml(string $param)
add parameter as raw HTML, usually in conjunction with strings
usage
$message->addParamHtml('<img src="img">');
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 string|array
sanitize(mixed $message)
Sanitizes $message
static string
decodeBB(string $message)
decode $message, taking into account our special codes for formatting
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