Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active June 30, 2024 14:24
Show Gist options
  • Save trikitrok/b91c4122952fae41e21c to your computer and use it in GitHub Desktop.
Save trikitrok/b91c4122952fae41e21c to your computer and use it in GitHub Desktop.
<?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