Split Output into Output(Generator) and Transport. Needed for later

switching between different mail transports.
This commit is contained in:
2016-08-04 15:35:50 +02:00
parent d7d6ee890e
commit 320c58be50
6 changed files with 51 additions and 8 deletions

View File

@@ -2,8 +2,9 @@
namespace Frs\Output;
class GenericOutput
class GenericOutput implements OutputInterface
{
private $transport;
private $templatesPath;
private $partialsPath;
private $templateEngine;
@@ -13,11 +14,13 @@ class GenericOutput
/**
* Creates new output object for generic output.
*
* @param \Frs\Output\Transport\TransportInterface Transport to send output to
* @param string $templatesPath Path to templates. Must be a folder, no slash at end!
* @param string $partialsPath Path to partials (relative to $templatesPath). Must be a folder, no slash at end!
*/
public function __construct($templatesPath = 'templates', $partialsPath = 'partials')
public function __construct(\Frs\Output\Transport\TransportInterface $transport, $templatesPath = 'templates', $partialsPath = 'partials')
{
$this->transport = $transport;
$this->templatesPath = $templatesPath;
$this->partialsPath = $templatesPath . DIRECTORY_SEPARATOR . $partialsPath;
$this->templateEngine = new \Mustache_Engine(array(
@@ -53,4 +56,10 @@ class GenericOutput
{
return $this->template->render($this->templateVars);
}
public function send()
{
$this->transport->setContent($this->getRenderedOutput());
$this->transport->transmit();
}
}

View File

@@ -6,8 +6,4 @@ use \Frs\Output\GenericOutput;
class HtmlOutput extends GenericOutput
{
public function sendOutputToStdout()
{
echo $this->getRenderedOutput();
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Frs\Output;
interface OutputInterface
{
public function send();
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Frs\Output\Transport;
class StdoutTransport implements TransportInterface
{
private $content;
public function setContent($content)
{
$this->content = $content;
}
public function transmit()
{
echo $this->content;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Frs\Output\Transport;
interface TransportInterface
{
public function setContent($content);
public function transmit();
}