Created
April 1, 2014 04:29
-
-
Save trikitrok/1adee86e7c2ebed46753 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 EmailAndRedirectService | |
{ | |
private $redirection; | |
private $emailService; | |
function __construct( | |
FormEmailService $emailService, | |
Redirection $redirection | |
) { | |
$this->emailService = $emailService; | |
$this->redirection = $redirection; | |
} | |
public function sendAndRedirect($form) | |
{ | |
if ($form->isNotFilled()) { | |
$this->redirection->backToInitialPage(); | |
return; | |
} | |
$email = $this->createEmail($form); | |
$sendingSucceeded = $this->send($email); | |
$this->redirect($sendingSucceeded); | |
} | |
private function redirect($sendingSucceeded) | |
{ | |
if ($sendingSucceeded) { | |
$this->redirection->toSuccessPage(); | |
} else { | |
$this->redirection->toFailPage(); | |
} | |
} | |
private function createEmail($form) | |
{ | |
return $this->emailService->composeEmailFrom($form); | |
} | |
private function send(Email $email) | |
{ | |
return $this->emailService->send($email); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment