Answer the question
In order to leave comments, you need to log in
What approach to use for data validation?
I would like to organize a competent scalable architecture for validating incoming data while remaining flexible and informative for the user (give feedback on a specific form field, etc.).
How can I do that?
Current Approach:
public function validateRegistration($data) {
$data->phone ??= NULL;
$data->email ??= NULL;
$data->password ??= NULL;
if(!$this->validation->validatePhone($data->phone)) $this->helper->sendErrorResponse(['code' => BAD_REQUEST_CODE, 'message' => 'Некорректный телефон']);
if(!$this->validation->validateEmail($data->email)) $this->helper->sendErrorResponse(['code' => BAD_REQUEST_CODE, 'message' => 'Некорректный email']);
if(!$this->validation->validatePassword($data->password)) $this->helper->sendErrorResponse(['code' => BAD_REQUEST_CODE, 'message' => 'Пароль должен быть от 8 до 32 символов']);
return (object)$this->mapper->mapperRegistration($data);
}
Answer the question
In order to leave comments, you need to log in
Font rendering in a graphics editor and in a browser looks different, which is why such inaccuracies arise. Moreover, in different browsers and different operating systems, the display may differ. Do not bother, the main thing is to match vertically.
Oh, this Pixel Perfect. What if your site is open on a mac? There fonts are generally rendered differently. As such, the only correct strategy is to check for grid layout and padding.
Less bigotry. When the requirement "Layout must be done using a pixel perfect" is voiced, it is the grid that is primarily meant. Fonts in Photoshop, each browser and each OS are rendered differently and it is almost impossible to achieve complete identity, and is it necessary?
ps Well, the question in the title needs to be given more meaning. As I looked at him, I immediately thought for two minutes, what am I doing wrong in this life? Is it worth it to go into this topic at all if I myself cannot answer this question for myself;)
Pixel perfect is not possible. The main thing is that it should be similar. Otherwise it takes too long.
The main point is in fonts and in the correct arrangement of elements. And the fact that the letters go back and forth on the same line is not important.
What you did is already Pixel perfect, so congratulations, a very good result.
Validation, scalability and usability are completely different things.
For usability - validation at the front. Having entered something invalid, the user should see the problem immediately, and not when he finishes filling out the form, and sends everything to the back.
At the same time, the same validation must be present on the back so that it is not possible to save invalid data by direct requests.
For flexibility, the controller validates only the correspondence of the request structure (swears that there are not enough values, or the data was expected in one format, but came in another). Wrap the data itself during processing in self-validating ValueObjects, which, when created, will already check the data for compliance with more specific requirements.
At whatever stage the validation takes place - in case of errors, it should not send anything in response, but should simply throw an exception with the error text. In order to convert these exceptions into an intelligible response, a common handler is made for them, which will lead them to the API interface.
Etc. etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question