Answer the question
In order to leave comments, you need to log in
Access to RequestStack bypassing SQRS DTOs?
When we access the command, query, event handler of the RequestStack we bypass the command itself. That is, you can get a bunch of other parameters from the request + the same ones that were passed in the command. What makes the command like a validation DTO, but the developer can take data from the request itself.
So responsibility and boundaries are blurred a little, RequestStack is like a hack to bypass the ATT.
For example, commands can always be empty, we get access to data from the RequestStack and inside the Handler we create a validation DTO and perform other validations.
class ValidateRegistration {
// Assert/NotBlunk
// Assert/Type('string')
// Assert/Length(['min' => 3])
public string $email;
}
class RegisterUserCommand { // can be filled with data to validate }
class RegisterUserCommandHandler {
public function __construct (RequestStack $requestStack, IValidationService $validator)
// init
$this->lastReuqest = $reqeustStack->getLastRequest();
}
public function __invoke(RegisterUserCommand $command) {
$this->validator->validate(...)
// or
$dto = new ValidateRegistration($this->lastRequest->request->get('email'))
$this->validator->validate($dto);
// $dto for validation could be self-contained with Annotations, so we could validate its params without calling validator
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question