feat: add content package schema validator
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Package validation result.
|
||||
*
|
||||
* @package WPContentSync
|
||||
*/
|
||||
|
||||
namespace WPContentSync\Package;
|
||||
|
||||
final class PackageValidationResult {
|
||||
/** @var array<int, string> */
|
||||
private array $errors;
|
||||
|
||||
/**
|
||||
* @param array<int, string> $errors Validation errors.
|
||||
*/
|
||||
private function __construct( array $errors ) {
|
||||
$this->errors = array_values( $errors );
|
||||
}
|
||||
|
||||
public static function valid(): self {
|
||||
return new self( array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $errors Validation errors.
|
||||
*/
|
||||
public static function invalid( array $errors ): self {
|
||||
return new self( $errors );
|
||||
}
|
||||
|
||||
public function isValid(): bool {
|
||||
return array() === $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function errors(): array {
|
||||
return $this->errors;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user