PHP Class PMA\libraries\Message

simple usage examples: display simple error message 'Error' Message::error()->display(); 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);
Show file Open project: phpmyadmin/phpmyadmin Class Usage Examples

Public Properties

Property Type Description
$level array message levels

Protected Properties

Property Type Description
$addedMessages array holds additional messages
$hash string Unique id
$isDisplayed boolean Whether the message was already displayed
$message string The formatted message
$number integer The message number
$params array holds parameters
$string string The locale string identifier
$useBBCode boolean Whether to use BB code when displaying.

Public Methods

Method Description
__construct ( string $string = '', integer $number = Message::NOTICE, array $params = [], integer $sanitize = Message::SANITIZE_NONE ) Constructor
__toString ( ) : string magic method: return string representation for this object
addHtml ( string $message, string $separator = ' ' ) : void add another html message to be concatenated on displaying
addMessage ( Message $message, string $separator = ' ' ) : void add another raw message to be concatenated on displaying
addMessages ( Message[] $messages, string $separator = ' ' ) : void add a bunch of messages at once
addMessagesString ( string[] $messages, string $separator = ' ' ) : void add a bunch of messages at once
addParam ( mixed $param ) : void add string or Message parameter
addParamHtml ( string $param ) : void add parameter as raw HTML, usually in conjunction with strings
addText ( string $message, string $separator = ' ' ) : void add another raw message to be concatenated on displaying
decodeBB ( string $message ) : string decode $message, taking into account our special codes for formatting
display ( ) : void Displays the message in HTML
error ( string $string = '' ) : Message get Message of type error
format ( ) : string wrapper for sprintf()
getAddedMessages ( ) : array return all added messages
getDisplay ( ) : string returns HTML code for displaying this message
getHash ( ) : string returns unique Message::$hash, if not exists it will be created
getLevel ( ) : string returns level of message
getMessage ( ) : string returns compiled message
getMessageForAffectedRows ( integer $rows ) : Message get Message for number of affected rows
getMessageForDeletedRows ( integer $rows ) : Message get Message for number of deleted rows
getMessageForInsertedRows ( integer $rows ) : Message get Message for number of inserted rows
getMessageWithIcon ( string $message ) : string Returns the message with corresponding image icon
getNumber ( ) : integer returns Message::$number
getOnlyMessage ( ) : string Returns only message string without image & other HTML.
getParams ( ) : array return all parameters
getString ( ) : string returns Message::$string
isDisplayed ( boolean $isDisplayed = false ) : boolean sets and returns whether the message was displayed or not
isError ( boolean $set = false ) : boolean returns whether this message is an error message or not and optionally makes this message an error message
isNotice ( boolean $set = false ) : boolean returns whether this message is a notice message or not and optionally makes this message a notice message
isSuccess ( boolean $set = false ) : boolean returns whether this message is a success message or not and optionally makes this message a success message
notice ( string $string ) : Message get Message of type notice
raw ( string $message, integer $type = Message::NOTICE ) : Message get Message with customized content
rawError ( string $message ) : Message get Message of type error with custom content
rawNotice ( string $message ) : Message get Message of type notice with custom content
rawSuccess ( string $message ) : Message get Message of type success with custom content
sanitize ( mixed $message ) : mixed Sanitizes $message
setBBCode ( boolean $useBBCode ) : void Set whether we should use BB Code when rendering.
setMessage ( string $message, boolean $sanitize = false ) : void set raw message (overrides string)
setNumber ( integer $number ) : void set message type number
setParams ( array | string $params, boolean $sanitize = false ) : void set all params at once, usually used in conjunction with string
setString ( string $string, boolean $sanitize = true ) : void set string (does not take effect if raw message is set)
success ( string $string = '' ) : Message get Message of type success

Private Methods

Method Description
_addMessage ( mixed $message, string $separator ) : void Real implementation of adding message

Method Details

__construct() public method

Constructor
public __construct ( string $string = '', integer $number = Message::NOTICE, array $params = [], integer $sanitize = Message::SANITIZE_NONE )
$string string The message to be displayed
$number integer A numeric representation of the type of message
$params array An array of parameters to use in the message
$sanitize integer A flag to indicate what to sanitize, see constant definitions above

__toString() public method

magic method: return string representation for this object
public __toString ( ) : string
return string

addHtml() public method

add another html message to be concatenated on displaying
public addHtml ( string $message, string $separator = ' ' ) : void
$message string to be added
$separator string to use between this and previous string/message
return void

addMessage() public method

add another raw message to be concatenated on displaying
public addMessage ( Message $message, string $separator = ' ' ) : void
$message Message to be added
$separator string to use between this and previous string/message
return void

addMessages() public method

add a bunch of messages at once
public addMessages ( Message[] $messages, string $separator = ' ' ) : void
$messages Message[] to be added
$separator string to use between this and previous string/message
return void

addMessagesString() public method

add a bunch of messages at once
public addMessagesString ( string[] $messages, string $separator = ' ' ) : void
$messages string[] to be added
$separator string to use between this and previous string/message
return void

addParam() public method

usage $message->addParam('[em]some string[/em]');
public addParam ( mixed $param ) : void
$param mixed parameter to add
return void

addParamHtml() public method

usage $message->addParamHtml('');
public addParamHtml ( string $param ) : void
$param string parameter to add
return void

addText() public method

add another raw message to be concatenated on displaying
public addText ( string $message, string $separator = ' ' ) : void
$message string to be added
$separator string to use between this and previous string/message
return void

decodeBB() public static method

decode $message, taking into account our special codes for formatting
public static decodeBB ( string $message ) : string
$message string the message
return string the decoded message

display() public method

Displays the message in HTML
public display ( ) : void
return void

error() public static method

shorthand for getting a simple error message
public static error ( string $string = '' ) : Message
$string string A localized string e.g. __('Error')
return Message

format() public static method

wrapper for sprintf()
public static format ( ) : string
return string formatted

getAddedMessages() public method

return all added messages
public getAddedMessages ( ) : array
return array

getDisplay() public method

returns HTML code for displaying this message
public getDisplay ( ) : string
return string whole message box

getHash() public method

returns unique Message::$hash, if not exists it will be created
public getHash ( ) : string
return string Message::$hash

getLevel() public method

returns level of message
public getLevel ( ) : string
return string level of message

getMessage() public method

returns compiled message
public getMessage ( ) : string
return string complete message

getMessageForAffectedRows() public static method

shorthand for getting a customized message
public static getMessageForAffectedRows ( integer $rows ) : Message
$rows integer Number of rows
return Message

getMessageForDeletedRows() public static method

shorthand for getting a customized message
public static getMessageForDeletedRows ( integer $rows ) : Message
$rows integer Number of rows
return Message

getMessageForInsertedRows() public static method

shorthand for getting a customized message
public static getMessageForInsertedRows ( integer $rows ) : Message
$rows integer Number of rows
return Message

getMessageWithIcon() public method

Returns the message with corresponding image icon
public getMessageWithIcon ( string $message ) : string
$message string the message(s)
return string message with icon

getNumber() public method

returns Message::$number
public getNumber ( ) : integer
return integer Message::$number

getOnlyMessage() public method

Returns only message string without image & other HTML.
public getOnlyMessage ( ) : string
return string

getParams() public method

return all parameters
public getParams ( ) : array
return array

getString() public method

returns Message::$string
public getString ( ) : string
return string Message::$string

isDisplayed() public method

sets and returns whether the message was displayed or not
public isDisplayed ( boolean $isDisplayed = false ) : boolean
$isDisplayed boolean whether to set displayed flag
return boolean Message::$isDisplayed

isError() public method

returns whether this message is an error message or not and optionally makes this message an error message
public isError ( boolean $set = false ) : boolean
$set boolean Whether to make this message of ERROR type
return boolean Whether this is an error message or not

isNotice() public method

returns whether this message is a notice message or not and optionally makes this message a notice message
public isNotice ( boolean $set = false ) : boolean
$set boolean Whether to make this message of NOTICE type
return boolean whether this is a notice message or not

isSuccess() public method

returns whether this message is a success message or not and optionally makes this message a success message
public isSuccess ( boolean $set = false ) : boolean
$set boolean Whether to make this message of SUCCESS type
return boolean whether this is a success message or not

notice() public static method

shorthand for getting a simple notice message
public static notice ( string $string ) : Message
$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 Message

raw() public static method

shorthand for getting a customized message
public static raw ( string $message, integer $type = Message::NOTICE ) : Message
$message string A localized string
$type integer A numeric representation of the type of message
return Message

rawError() public static method

shorthand for getting a customized error message
public static rawError ( string $message ) : Message
$message string A localized string
return Message

rawNotice() public static method

shorthand for getting a customized notice message
public static rawNotice ( string $message ) : Message
$message string A localized string
return Message

rawSuccess() public static method

shorthand for getting a customized success message
public static rawSuccess ( string $message ) : Message
$message string A localized string
return Message

sanitize() public static method

Sanitizes $message
public static sanitize ( mixed $message ) : mixed
$message mixed the message(s)
return mixed the sanitized message(s)

setBBCode() public method

Set whether we should use BB Code when rendering.
public setBBCode ( boolean $useBBCode ) : void
$useBBCode boolean Use BB Code?
return void

setMessage() public method

set raw message (overrides string)
public setMessage ( string $message, boolean $sanitize = false ) : void
$message string A localized string
$sanitize boolean Whether to sanitize $message or not
return void

setNumber() public method

set message type number
public setNumber ( integer $number ) : void
$number integer message type number to set
return void

setParams() public method

set all params at once, usually used in conjunction with string
public setParams ( array | string $params, boolean $sanitize = false ) : void
$params array | string parameters to set
$sanitize boolean whether to sanitize params
return void

setString() public method

set string (does not take effect if raw message is set)
public setString ( string $string, boolean $sanitize = true ) : void
$string string string to set
$sanitize boolean whether to sanitize $string or not
return void

success() public static method

shorthand for getting a simple success message
public static success ( string $string = '' ) : Message
$string string A localized string e.g. __('Your SQL query has been executed successfully')
return Message

Property Details

$addedMessages protected property

holds additional messages
protected array $addedMessages
return array

$hash protected property

Unique id
protected string $hash
return string

$isDisplayed protected property

Whether the message was already displayed
protected bool $isDisplayed
return boolean

$level public static property

message levels
public static array $level
return array

$message protected property

The formatted message
protected string $message
return string

$number protected property

The message number
protected int $number
return integer

$params protected property

holds parameters
protected array $params
return array

$string protected property

The locale string identifier
protected string $string
return string

$useBBCode protected property

Whether to use BB code when displaying.
protected bool $useBBCode
return boolean