PHP Class Overtrue\Validation\MessageBag

Inheritance: implements Countabl\Countable, implements JsonSerializabl\JsonSerializable
Show file Open project: overtrue/validation Class Usage Examples

Protected Properties

Property Type Description
$format string Default format for message output.
$messages array All of the registered messages.

Public Methods

Method Description
__construct ( array $messages = [] ) : MessageBag Create a new message bag instance.
__toString ( ) : string Convert the message bag to its string representation.
add ( string $key, string $message ) Add a message to the bag.
all ( string $format = null ) : array Get all of the messages for every key in the bag.
any ( ) : boolean Determine if the message bag has any messages.
count ( ) : integer Get the number of messages in the container.
first ( string $key = null, string $format = null ) : string Get the first message from the bag for a given key.
get ( string $key, string $format = null ) : array Get all of the messages from the bag for a given key.
getFormat ( ) : string Get the default message format.
getMessageBag ( ) : MessageBag Get the messages for the instance.
getMessages ( ) : array Get the raw messages in the container.
has ( string $key = null ) : boolean Determine if messages exist for a given key.
isEmpty ( ) : boolean Determine if the message bag has any messages.
jsonSerialize ( ) : array Convert the object into something JSON serializable.
merge ( array $messages ) Merge a new array of messages into the bag.
setFormat ( string $format = ':message' ) : MessageBag Set the default message format.
toArray ( ) : array Get the instance as an array.
toJson ( integer $options ) : string Convert the object to its JSON representation.

Protected Methods

Method Description
checkFormat ( string $format ) : string Get the appropriate format based on the given format.
isUnique ( string $key, string $message ) : boolean Determine if a key and message combination already exists.
transform ( array $messages, string $format, string $messageKey ) : array Format an array of messages.

Method Details

__construct() public method

Create a new message bag instance.
public __construct ( array $messages = [] ) : MessageBag
$messages array
return MessageBag

__toString() public method

Convert the message bag to its string representation.
public __toString ( ) : string
return string

add() public method

Add a message to the bag.
public add ( string $key, string $message )
$key string
$message string

all() public method

Get all of the messages for every key in the bag.
public all ( string $format = null ) : array
$format string
return array

any() public method

Determine if the message bag has any messages.
public any ( ) : boolean
return boolean

checkFormat() protected method

Get the appropriate format based on the given format.
protected checkFormat ( string $format ) : string
$format string
return string

count() public method

Get the number of messages in the container.
public count ( ) : integer
return integer

first() public method

Get the first message from the bag for a given key.
public first ( string $key = null, string $format = null ) : string
$key string
$format string
return string

get() public method

Get all of the messages from the bag for a given key.
public get ( string $key, string $format = null ) : array
$key string
$format string
return array

getFormat() public method

Get the default message format.
public getFormat ( ) : string
return string

getMessageBag() public method

Get the messages for the instance.
public getMessageBag ( ) : MessageBag
return MessageBag

getMessages() public method

Get the raw messages in the container.
public getMessages ( ) : array
return array

has() public method

Determine if messages exist for a given key.
public has ( string $key = null ) : boolean
$key string
return boolean

isEmpty() public method

Determine if the message bag has any messages.
public isEmpty ( ) : boolean
return boolean

isUnique() protected method

Determine if a key and message combination already exists.
protected isUnique ( string $key, string $message ) : boolean
$key string
$message string
return boolean

jsonSerialize() public method

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
return array

merge() public method

Merge a new array of messages into the bag.
public merge ( array $messages )
$messages array

setFormat() public method

Set the default message format.
public setFormat ( string $format = ':message' ) : MessageBag
$format string
return MessageBag

toArray() public method

Get the instance as an array.
public toArray ( ) : array
return array

toJson() public method

Convert the object to its JSON representation.
public toJson ( integer $options ) : string
$options integer
return string

transform() protected method

Format an array of messages.
protected transform ( array $messages, string $format, string $messageKey ) : array
$messages array
$format string
$messageKey string
return array

Property Details

$format protected property

Default format for message output.
protected string $format
return string

$messages protected property

All of the registered messages.
protected array $messages
return array