Skip to content

Phalcon messages

NOTE

All classes are prefixed with Phalcon

Messages\Exception

Class Source on GitHub

Exceptions thrown in Phalcon\Messages* classes will use this class

Messages\Exceptions\MessageNotObject

Class Source on GitHub

Uses Phalcon\Messages\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Messages\Exceptions\MessagesNotIterable

Class Source on GitHub

Uses Phalcon\Messages\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Messages\Message

Class Source on GitHub

Phalcon\Messages\Message

Stores a message from various components

Uses JsonSerializable

Method Summary

Properties

protected int $code
protected string $field
protected string $message
protected array $metaData = []
protected string $type

Methods

Public · 13

__construct()

public function __construct(
    string $message,
    string $field = "",
    string $type = "",
    int $code = 0,
    array $metaData = []
);

Phalcon\Messages\Message constructor

__toString()

public function __toString(): string;

Magic __toString method returns verbose message

getCode()

public function getCode(): int;

getField()

public function getField(): string;

getMessage()

public function getMessage(): string;

getMetaData()

public function getMetaData(): array;

getType()

public function getType(): string;

jsonSerialize()

public function jsonSerialize(): array;

Serializes the object for json_encode

setCode()

public function setCode( int $code ): MessageInterface;

Sets code for the message

setField()

public function setField( string $field ): MessageInterface;

Sets field name related to message

setMessage()

public function setMessage( string $message ): MessageInterface;

Sets verbose message

setMetaData()

public function setMetaData( array $metaData ): MessageInterface;

Sets message metadata

setType()

public function setType( string $type ): MessageInterface;

Sets message type

Messages\MessageInterface

Interface Source on GitHub

Phalcon\Messages\MessageInterface

Interface for Phalcon\Messages\MessageInterface

  • Phalcon\Messages\MessageInterface

Method Summary

Methods

Public · 11

__toString()

public function __toString(): string;

Magic __toString method returns verbose message

getCode()

public function getCode(): int;

Returns the message code related to this message

getField()

public function getField(): string;

Returns field name related to message

getMessage()

public function getMessage(): string;

Returns verbose message

getMetaData()

public function getMetaData(): array;

Returns message metadata

getType()

public function getType(): string;

Returns message type

setCode()

public function setCode( int $code ): MessageInterface;

Sets code for the message

setField()

public function setField( string $field ): MessageInterface;

Sets field name related to message

setMessage()

public function setMessage( string $message ): MessageInterface;

Sets verbose message

setMetaData()

public function setMetaData( array $metaData ): MessageInterface;

Sets message metadata

setType()

public function setType( string $type ): MessageInterface;

Sets message type

Messages\Messages

Class Source on GitHub

Represents a collection of messages

Messages are stored and iterated by integer position. An entry added under a string key through the ArrayAccess interface (for example $messages["database"] = $message) stays reachable by that offset but is not visited during iteration (foreach), which walks the integer sequence only. Use the append methods (appendMessage() / appendMessages()) when entries must take part in iteration.

Uses JsonSerializable · Phalcon\Contracts\Messages\Messages · Phalcon\Messages\Exceptions\MessageNotObject · Phalcon\Messages\Exceptions\MessagesNotIterable · Traversable

Method Summary

Properties

protected array $messages
protected int $position = 0

Methods

Public · 15

__construct()

public function __construct( array $messages = [] );

Phalcon\Messages\Messages constructor

appendMessage()

public function appendMessage( MessageInterface $message ): void;

Appends a message to the collection

$messages->appendMessage(
    new \Phalcon\Messages\Message("This is a message")
);

appendMessages()

public function appendMessages( mixed $messages );

Appends an array of messages to the collection

$messages->appendMessages($messagesArray);

count()

public function count(): int;

Returns the number of messages in the list

current()

public function current(): MessageInterface;

Returns the current message in the iterator

filter()

public function filter( string $fieldName ): array;

Filters the message collection by field name

jsonSerialize()

public function jsonSerialize(): array;

Returns serialised message objects as array for json_encode. Calls jsonSerialize on each object if present

$data = $messages->jsonSerialize();
echo json_encode($data);

key()

public function key(): int;

Returns the current position/key in the iterator

next()

public function next(): void;

Moves the internal iteration pointer to the next position

offsetExists()

public function offsetExists( mixed $index ): bool;

Checks if an index exists

var_dump(
    isset($message["database"])
);

offsetGet()

public function offsetGet( mixed $index ): mixed;

Gets an attribute a message using the array syntax

print_r(
    $messages[0]
);

offsetSet()

public function offsetSet(
    mixed $offset,
    mixed $value
): void;

Sets an attribute using the array-syntax

$messages[0] = new \Phalcon\Messages\Message("This is a message");

offsetUnset()

public function offsetUnset( mixed $index ): void;

Removes a message from the list

unset($message["database"]);

rewind()

public function rewind(): void;

Rewinds the internal iterator

valid()

public function valid(): bool;

Check if the current message in the iterator is valid