- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
This commit is contained in:
40
app/Data/Validation/ValidationResult.php
Normal file
40
app/Data/Validation/ValidationResult.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data\Validation;
|
||||
|
||||
class ValidationResult
|
||||
{
|
||||
private bool $error;
|
||||
private ?string $errorMessage;
|
||||
|
||||
public function __construct(bool $error, ?string $errorMessage = null)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->errorMessage = $errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void|never
|
||||
*/
|
||||
final public function assertIsSuccess(): void
|
||||
{
|
||||
if ($this->isError()) {
|
||||
throw new ValidationException($this->getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function isError(): bool
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
return !$this->isError();
|
||||
}
|
||||
|
||||
public function getErrorMessage(): ?string
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user