Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created April 1, 2014 04:29
Show Gist options
  • Save trikitrok/1adee86e7c2ebed46753 to your computer and use it in GitHub Desktop.
Save trikitrok/1adee86e7c2ebed46753 to your computer and use it in GitHub Desktop.
<?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