Skip to content

Commit

Permalink
Prevent unnecessary reponse rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Mar 31, 2020
1 parent d19ae55 commit 79e453f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/FormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ public function registerHandler(FormHandlerInterface $handler): void

/**
* @param string|FormHandlerInterface $class
* @param mixed[] $options
* @param array<mixed> $options
*
* @return FormRequest
* @throws \Exception
*/
public function handle($class, array $options = []): FormRequest
{
Expand All @@ -113,11 +114,11 @@ public function handle($class, array $options = []): FormRequest

$form->handleRequest($this->request);

if ($handler instanceof FormHandlerResponseInterface) {
$formRequest->setResponse($handler->getResponse($formRequest));
}

if (!$form->isSubmitted()) {
if ($handler instanceof FormHandlerResponseInterface) {
$formRequest->setResponse($handler->getResponse($formRequest));
}

return $formRequest;
}

Expand All @@ -131,6 +132,8 @@ public function handle($class, array $options = []): FormRequest

if ($response = $event->getResponse()) {
$formRequest->setResponse($response);
} else if ($handler instanceof FormHandlerResponseInterface) {
$formRequest->setResponse($handler->getResponse($formRequest));
}

return $formRequest;
Expand Down

0 comments on commit 79e453f

Please sign in to comment.