You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
<?php
|
|
|
|
namespace IQBall\Core\Validation;
|
|
|
|
use JsonSerializable;
|
|
|
|
class ValidationFail implements JsonSerializable {
|
|
private string $kind;
|
|
|
|
private string $message;
|
|
|
|
/**
|
|
* @param string $message
|
|
* @param string $kind
|
|
*/
|
|
public function __construct(string $kind, string $message) {
|
|
$this->message = $message;
|
|
$this->kind = $kind;
|
|
}
|
|
|
|
public function getMessage(): string {
|
|
return $this->message;
|
|
}
|
|
|
|
public function getKind(): string {
|
|
return $this->kind;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function jsonSerialize(): array {
|
|
return ["error" => $this->kind, "message" => $this->message];
|
|
}
|
|
|
|
/**
|
|
* @param string $message
|
|
* @return ValidationFail validation fail for unknown resource access
|
|
*/
|
|
public static function notFound(string $message): ValidationFail {
|
|
return new ValidationFail("Not found", $message);
|
|
}
|
|
|
|
/**
|
|
* @param string $message
|
|
* @return ValidationFail validation fail for unauthorized accesses
|
|
*/
|
|
public static function unauthorized(string $message = "Unauthorized"): ValidationFail {
|
|
return new ValidationFail("Unauthorized", $message);
|
|
}
|
|
|
|
public static function error(string $message): ValidationFail {
|
|
return new ValidationFail("Error", $message);
|
|
}
|
|
|
|
}
|