diff --git a/src/Actions/SortPriceAction.php b/src/Actions/SortPriceAction.php new file mode 100644 index 0000000000000000000000000000000000000000..067f67ed9020bbdfacb7f88dfae057eec402b6fc --- /dev/null +++ b/src/Actions/SortPriceAction.php @@ -0,0 +1,27 @@ +act($request->serialise())); + } +} diff --git a/src/Requests/BaseRequest.php b/src/Requests/BaseRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..b2fb49ed286c374885e1b073732ab13a0366d5a0 --- /dev/null +++ b/src/Requests/BaseRequest.php @@ -0,0 +1,71 @@ +populate(); + + if (self::AUTO_VALIDATE) { + $this->validate(); + } + } + + protected function populate(): void + { + foreach ($this->getRequest()->toArray() as $property => $value) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } + } + + /** + * валидация и выброкса ошибки при валидации + * @return void + */ + public function validate() + { + $errors = $this->validator->validate($this); + + $messages = [ + 'message' => 'validation_failed', + 'errors' => [] + ]; + + foreach ($errors as $error) { + $messages['errors'][] = [ + 'property' => $error->getPropertyPath(), + 'value' => $error->getInvalidValue(), + 'message' => $error->getMessage(), + ]; + } + + if (count($messages['errors']) > 0) { + $response = new JsonResponse($messages, 201); + $response->send(); + + throw new ValidatorException('Validation failed', $messages); + } + } + + public function getRequest(): Request + { + return Request::createFromGlobals(); + } + + abstract public function serialise(): mixed; +} \ No newline at end of file diff --git a/src/Requests/PricesRequest.php b/src/Requests/PricesRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..dadac42991ac8f9fab940eccac3de760d24cbff3 --- /dev/null +++ b/src/Requests/PricesRequest.php @@ -0,0 +1,42 @@ + [ + new NotBlank(), + new Type('integer'), + ], + 'count' => [ + new NotBlank(), + new Type('integer'), + ], + ], + ) + ] + )] + public $prices; + + /** + * серализация реквеста под массив + * @return mixed + */ + public function serialise(): mixed + { + return $this->prices; + } +} diff --git a/templates/id_search/index.html.twig b/templates/id_search/index.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..69a280e448c95e97964807ec52c04cf17bff3994 --- /dev/null +++ b/templates/id_search/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello IdSearchController!{% endblock %} + +{% block body %} + + +
/home/tamanit/myProj/iqdevTranningProgram/src/Controller/IdSearchController.php
/home/tamanit/myProj/iqdevTranningProgram/templates/id_search/index.html.twig