You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
namespace Isekai\Widgets\Utils;
|
|
|
|
class NewPageTitleValidationResult {
|
|
private $hasError = false;
|
|
private $hasWarning = false;
|
|
|
|
private $warnings = [];
|
|
private $errors = [];
|
|
|
|
public function toArray(): array {
|
|
return [
|
|
'hasError' => $this->hasError ? 1 : 0,
|
|
'hasWarning' => $this->hasWarning ? 1 : 0,
|
|
'warnings' => $this->warnings,
|
|
'errors' => $this->errors,
|
|
];
|
|
}
|
|
|
|
public function __serialize(): array {
|
|
return $this->toArray();
|
|
}
|
|
|
|
public function __unserialize(array $data): void {
|
|
$this->hasError = (bool)$data['hasError'] ?? false;
|
|
$this->hasWarning = (bool)$data['hasWarning'] ?? false;
|
|
$this->warnings = $data['warnings'] ?? [];
|
|
$this->errors = $data['errors'] ?? [];
|
|
}
|
|
|
|
public function addError(string $errorCode, string $errorMessage): void {
|
|
$this->hasError = true;
|
|
$this->errors[] = [
|
|
'code' => $errorCode,
|
|
'message' => $errorMessage,
|
|
];
|
|
}
|
|
|
|
public function addWarning(string $warningCode, string $warningMessage): void {
|
|
$this->hasWarning = true;
|
|
$this->warnings[] = [
|
|
'code' => $warningCode,
|
|
'message' => $warningMessage,
|
|
];
|
|
}
|
|
} |