forked from devsam/core
dep: DTO
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\DataTransferObject\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Spatie\DataTransferObject\Caster;
|
||||
|
||||
class InvalidCasterClass extends Exception
|
||||
{
|
||||
public function __construct(string $className)
|
||||
{
|
||||
$expected = Caster::class;
|
||||
|
||||
parent::__construct(
|
||||
"Class `{$className}` doesn't implement {$expected} and can't be used as a caster"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\DataTransferObject\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UnknownProperties extends Exception
|
||||
{
|
||||
public static function new(string $dtoClass, array $fields): self
|
||||
{
|
||||
$properties = json_encode($fields);
|
||||
|
||||
return new self("Unknown properties provided to `{$dtoClass}`: {$properties}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\DataTransferObject\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
|
||||
class ValidationException extends Exception
|
||||
{
|
||||
public function __construct(
|
||||
public DataTransferObject $dataTransferObject,
|
||||
public array $validationErrors,
|
||||
) {
|
||||
$className = $dataTransferObject::class;
|
||||
|
||||
$messages = [];
|
||||
|
||||
foreach ($validationErrors as $fieldName => $errorsForField) {
|
||||
/** @var \Spatie\DataTransferObject\Validation\ValidationResult $errorForField */
|
||||
foreach ($errorsForField as $errorForField) {
|
||||
$messages[] = "\t - `{$className}->{$fieldName}`: {$errorForField->message}";
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct("Validation errors:" . PHP_EOL . implode(PHP_EOL, $messages));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user