2021-02-05 14:47:54 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\ServiceBundle\ArgumentResolver;
|
|
|
|
|
|
|
|
use RetailCrm\ServiceBundle\Exceptions\InvalidRequestArgumentException;
|
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
|
|
|
|
abstract class AbstractValueResolver
|
|
|
|
{
|
2022-07-20 13:51:43 +03:00
|
|
|
public function __construct(
|
|
|
|
protected ValidatorInterface $validator)
|
2021-02-05 14:47:54 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validate(object $data): void
|
|
|
|
{
|
|
|
|
$errors = $this->validator->validate($data);
|
|
|
|
if (0 !== count($errors)) {
|
|
|
|
throw new InvalidRequestArgumentException(
|
|
|
|
sprintf("Invalid request parameter %s", \get_class($data)),
|
|
|
|
400,
|
|
|
|
$errors
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|