Skip to content

MessageBag

Properties

messages

All the registered messages.

public array $messages

format

Default format for message output.

protected string $format

Methods

__construct

Create a new message bag instance.

public __construct(array $messages = []): void

Parameters:

Parameter Type Description
$messages array

add

Add a message to the bag.

public add(string $key, string $message): self

Parameters:

Parameter Type Description
$key string
$message string

merge

Merge a new array of messages into the bag.

public merge(array $messages): self

Parameters:

Parameter Type Description
$messages array

isUnique

Determine if a key and message combination already exists.

protected isUnique(string $key, string $message): bool

Parameters:

Parameter Type Description
$key string
$message string

has

Determine if messages exist for a given key.

public has(?string $key = null): bool

Parameters:

Parameter Type Description
$key ?string

first

Get the first message from the bag for a given key.

public first(?string $key = null, ?string $format = null): string

Parameters:

Parameter Type Description
$key ?string
$format ?string

get

Get all the messages from the bag for a given key.

public get(string|null $key = null, string|null $format = null): array

Parameters:

Parameter Type Description
$key string|null
$format string|null

all

Get all the messages for every key in the bag.

public all(string|null $format = null): array

Parameters:

Parameter Type Description
$format string|null

transform

Format an array of messages.

protected transform(array $messages, string $format, string $messageKey): array

Parameters:

Parameter Type Description
$messages array
$format string
$messageKey string

checkFormat

Get the appropriate format based on the given format.

protected checkFormat(?string $format): ?string

Parameters:

Parameter Type Description
$format ?string

getMessageBag

Get the messages for the instance.

public getMessageBag(): \Qubus\Validation\MessageBag

getFormat

Get the default message format.

public getFormat(): string

setFormat

Set the default message format.

public setFormat(string $format = ':message'): \Qubus\Validation\MessageBag

Parameters:

Parameter Type Description
$format string

isEmpty

Determine if the message bag has any messages.

public isEmpty(): bool

any

Determine if the message bag has any messages.

public any(): bool

count

Get the number of messages in the container.

public count(): int

toArray

Get the instance as an array.

public toArray(): array

jsonSerialize

Convert the object into something JSON serializable.

public jsonSerialize(): array

toJson

Convert the object to its JSON representation.

public toJson(int $options): string

Parameters:

Parameter Type Description
$options int

__toString

Convert the message bag to its string representation.

public __toString(): string


Automatically generated on 2025-10-13