Last active
June 30, 2024 14:24
-
-
Save trikitrok/b91c4122952fae41e21c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SendingFormByEmailAndRedirecting | |
{ | |
private $form; | |
private $email; | |
private $formRedirection; | |
function __construct( | |
FormEmail $email, | |
Form $form, | |
FormRedirection $formRedirection | |
) { | |
$this->email = $email; | |
$this->form = $form; | |
$this->formRedirection = $formRedirection; | |
} | |
public function execute() | |
{ | |
if ($this->form->isNotFilled()) { | |
$this->formRedirection->backToFormPage(); | |
return; | |
} | |
$sendingSucceeded = $this->email->send( | |
$this->form->fields() | |
); | |
$this->redirect($sendingSucceeded); | |
} | |
private function redirect($sendingSucceeded) | |
{ | |
if ($sendingSucceeded) { | |
$this->formRedirection->toSuccessPage(); | |
} else { | |
$this->formRedirection->toFailPage(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment