Skip to content

Phalcon messages

NOTE

All classes are prefixed with Phalcon

Messages\Exception

Source on GitHub

  • Namespace

    • Phalcon\Messages
  • Uses

  • Extends

    \Exception

  • Implements

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

Messages\Message

Source on GitHub

  • Namespace

    • Phalcon\Messages
  • Uses

    • JsonSerializable
  • Extends

  • Implements

    • JsonSerializable
    • MessageInterface

Phalcon\Messages\Message

Stores a message from various components

Properties

/**
 * @var int
 */
protected $code;

/**
 * @var string
 */
protected $field;

/**
 * @var string
 */
protected $message;

/**
 * @var string
 */
protected $type;

/**
 * @var array
 */
protected $metaData;

Methods

public function __construct( string $message, mixed $field = string, string $type = string, int $code = int, array $metaData = [] );
Phalcon\Messages\Message constructor

public function __toString(): string;
Magic __toString method returns verbose message

public function getCode(): int;
public function getField(): string;
public function getMessage(): string;
public function getMetaData(): array;
public function getType(): string;

public function jsonSerialize(): array;
Serializes the object for json_encode

public function setCode( int $code ): MessageInterface;
Sets code for the message

public function setField( mixed $field ): MessageInterface;
Sets field name related to message

public function setMessage( string $message ): MessageInterface;
Sets verbose message

public function setMetaData( array $metaData ): MessageInterface;
Sets message metadata

public function setType( string $type ): MessageInterface;
Sets message type

Messages\MessageInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Messages
  • Uses

  • Extends

  • Implements

Phalcon\Messages\MessageInterface

Interface for Phalcon\Messages\MessageInterface

Methods

public function __toString(): string;
Magic __toString method returns verbose message

public function getCode();
Returns the message code related to this message

public function getField();
Returns field name related to message

public function getMessage(): string;
Returns verbose message

public function getMetaData(): array;
Returns message metadata

public function getType(): string;
Returns message type

public function setCode( int $code ): MessageInterface;
Sets code for the message

public function setField( string $field ): MessageInterface;
Sets field name related to message

public function setMessage( string $message ): MessageInterface;
Sets verbose message

public function setMetaData( array $metaData ): MessageInterface;
Sets message metadata

public function setType( string $type ): MessageInterface;
Sets message type

Messages\Messages

Source on GitHub

  • Namespace

    • Phalcon\Messages
  • Uses

    • ArrayAccess
    • Countable
    • Iterator
    • JsonSerializable
  • Extends

  • Implements

    • ArrayAccess
    • Countable
    • Iterator
    • JsonSerializable

Represents a collection of messages

Properties

/**
 * @var int
 */
protected $position = ;

/**
 * @var array
 */
protected $messages;

Methods

public function __construct( array $messages = [] );
Phalcon\Messages\Messages constructor

public function appendMessage( MessageInterface $message );
Appends a message to the collection

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

public function appendMessages( mixed $messages );
Appends an array of messages to the collection

$messages->appendMessages($messagesArray);

public function count(): int;
Returns the number of messages in the list

public function current(): MessageInterface;
Returns the current message in the iterator

public function filter( string $fieldName ): array;
Filters the message collection by field name

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);

public function key(): int;
Returns the current position/key in the iterator

public function next(): void;
Moves the internal iteration pointer to the next position

public function offsetExists( mixed $index ): bool;
Checks if an index exists

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

public function offsetGet( mixed $index ): mixed;
Gets an attribute a message using the array syntax

print_r(
    $messages[0]
);

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");

public function offsetUnset( mixed $index ): void;
Removes a message from the list

unset($message["database"]);

public function rewind(): void;
Rewinds the internal iterator

public function valid(): bool;
Check if the current message in the iterator is valid