$data Values behind the message, such as the limit that was exceeded. */ public function __construct( private string $field = '', private string $code = '', private string $message = '', private array $data = array() ) {} /** * Returns the field key. */ public function field(): string { return $this->field; } /** * Returns the machine readable reason. */ public function code(): string { return $this->code; } /** * Returns the sentence shown to the visitor. */ public function message(): string { return $this->message; } /** * Returns the values behind the message. * * @return array The data. */ public function data(): array { return $this->data; } /** * Returns a copy bound to a field. * * Rules build errors without knowing the key they will be filed under; the * engine stamps it on the way out. * * @param string $field Field key. */ public function for_field( string $field ): ValidationError { return new self( $field, $this->code, $this->message, $this->data ); } /** * Returns the error as an array. * * @return array The payload. */ public function to_array(): array { return array( 'field' => $this->field, 'code' => $this->code, 'message' => $this->message, 'data' => $this->data, ); } }