Split Output into Output(Generator) and Transport. Needed for later
switching between different mail transports.
This commit is contained in:
parent
d7d6ee890e
commit
320c58be50
@ -6,8 +6,10 @@ use \Frs\FieldDefinition;
|
|||||||
use \Frs\SessionManager;
|
use \Frs\SessionManager;
|
||||||
use \Frs\Output\HtmlOutput;
|
use \Frs\Output\HtmlOutput;
|
||||||
use \Frs\Output\MailOutput;
|
use \Frs\Output\MailOutput;
|
||||||
|
use \Frs\Output\Transport\StdoutTransport;
|
||||||
|
|
||||||
$ho = new HtmlOutput(dirname(__FILE__) . '/templates');
|
$stdout = new StdoutTransport();
|
||||||
|
$ho = new HtmlOutput($stdout, dirname(__FILE__) . '/templates');
|
||||||
$ho->setTemplateVar('session_time_left', 0);
|
$ho->setTemplateVar('session_time_left', 0);
|
||||||
|
|
||||||
$sm = new SessionManager();
|
$sm = new SessionManager();
|
||||||
@ -125,4 +127,4 @@ if (!$tpl_done && $sm->hasSessionToken()) {
|
|||||||
$ho->setTemplate('index_html');
|
$ho->setTemplate('index_html');
|
||||||
}
|
}
|
||||||
|
|
||||||
$ho->sendOutputToStdout();
|
$ho->send();
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace Frs\Output;
|
namespace Frs\Output;
|
||||||
|
|
||||||
class GenericOutput
|
class GenericOutput implements OutputInterface
|
||||||
{
|
{
|
||||||
|
private $transport;
|
||||||
private $templatesPath;
|
private $templatesPath;
|
||||||
private $partialsPath;
|
private $partialsPath;
|
||||||
private $templateEngine;
|
private $templateEngine;
|
||||||
@ -13,11 +14,13 @@ class GenericOutput
|
|||||||
/**
|
/**
|
||||||
* Creates new output object for generic output.
|
* 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 $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!
|
* @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->templatesPath = $templatesPath;
|
||||||
$this->partialsPath = $templatesPath . DIRECTORY_SEPARATOR . $partialsPath;
|
$this->partialsPath = $templatesPath . DIRECTORY_SEPARATOR . $partialsPath;
|
||||||
$this->templateEngine = new \Mustache_Engine(array(
|
$this->templateEngine = new \Mustache_Engine(array(
|
||||||
@ -53,4 +56,10 @@ class GenericOutput
|
|||||||
{
|
{
|
||||||
return $this->template->render($this->templateVars);
|
return $this->template->render($this->templateVars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function send()
|
||||||
|
{
|
||||||
|
$this->transport->setContent($this->getRenderedOutput());
|
||||||
|
$this->transport->transmit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,4 @@ use \Frs\Output\GenericOutput;
|
|||||||
|
|
||||||
class HtmlOutput extends GenericOutput
|
class HtmlOutput extends GenericOutput
|
||||||
{
|
{
|
||||||
public function sendOutputToStdout()
|
|
||||||
{
|
|
||||||
echo $this->getRenderedOutput();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
8
lib/Frs/Output/OutputInterface.php
Normal file
8
lib/Frs/Output/OutputInterface.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Frs\Output;
|
||||||
|
|
||||||
|
interface OutputInterface
|
||||||
|
{
|
||||||
|
public function send();
|
||||||
|
}
|
18
lib/Frs/Output/Transport/StdoutTransport.php
Normal file
18
lib/Frs/Output/Transport/StdoutTransport.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
10
lib/Frs/Output/Transport/TransportInterface.php
Normal file
10
lib/Frs/Output/Transport/TransportInterface.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Frs\Output\Transport;
|
||||||
|
|
||||||
|
interface TransportInterface
|
||||||
|
{
|
||||||
|
public function setContent($content);
|
||||||
|
|
||||||
|
public function transmit();
|
||||||
|
}
|
Reference in New Issue
Block a user