Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
0.00%
0 / 12
CRAP
0.00%
0 / 57
Response
0.00%
0 / 1
0.00%
0 / 12
210
0.00%
0 / 57
 setOutput($output)
0.00%
0 / 1
2
0.00%
0 / 5
 getOutput()
0.00%
0 / 1
2
0.00%
0 / 4
 setPage(PageAbstract $page)
0.00%
0 / 1
2
0.00%
0 / 5
 getPage()
0.00%
0 / 1
2
0.00%
0 / 4
 setWasProcessed($wasProcessed)
0.00%
0 / 1
2
0.00%
0 / 5
 wasProcessed()
0.00%
0 / 1
2
0.00%
0 / 4
 setHelper(ResponseHelper $helper)
0.00%
0 / 1
2
0.00%
0 / 5
 getHelper()
0.00%
0 / 1
6
0.00%
0 / 4
 render()
0.00%
0 / 1
2
0.00%
0 / 5
 executeQueuedActions()
0.00%
0 / 1
6
0.00%
0 / 8
 __toString()
0.00%
0 / 1
2
0.00%
0 / 4
 executeHelper()
0.00%
0 / 1
2
0.00%
0 / 4
<?php
/**
* Dewdrop
*
* @link https://github.com/DeltaSystems/dewdrop
* @copyright Delta Systems (http://deltasys.com)
* @license https://github.com/DeltaSystems/dewdrop/LICENSE
*/
namespace Dewdrop\Admin;
use Dewdrop\Admin\ResponseHelper\Standard as ResponseHelper;
use Dewdrop\Admin\Page\PageAbstract;
/**
* This is the standard response implementation. It will actually
* execute helper actions that were setup during process and will
* tell the controlling component to render the response to the
* client.
*/
class Response
{
/**
* The output generated during the page's render() method
*
* @param string
*/
protected $output;
/**
* The page object currently being dispatched.
*
* @param \Dewdrop\Admin\Page\PageAbstract
*/
protected $page;
/**
* The response helper provided to the page's process() method
* for short-circuiting of the dispatch logic. Will only be
* present if process() is called.
*
* @param ResponseHelper
*/
protected $helper;
/**
* Whether the process() method was called (i.e. the page's
* shouldProcess() method returned true.
*
* @var boolean
*/
protected $wasProcessed;
/**
* Set the output generated during the request.
*
* @param string $output
*/
public function setOutput($output)
{
$this->output = $output;
return $this;
}
/**
* Return the generated output
*
* @return string
*/
public function getOutput()
{
return $this->output;
}
/**
* Set the page object generating the response so it can be interacted
* with during testing.
*
* @param PageAbstract $page
* @return $this
*/
public function setPage(PageAbstract $page)
{
$this->page = $page;
return $this;
}
/**
* Get the dispatched page object (usually only for testing)
*
* @return \Dewdrop\Admin\Page\PageAbstract
*/
public function getPage()
{
return $this->page;
}
/**
* Set whether the page's process method was called.
*
* @param boolean $wasProcessed
* @return $this
*/
public function setWasProcessed($wasProcessed)
{
$this->wasProcessed = $wasProcessed;
return $this;
}
/**
* Check to see if the page's process() method was called
*
* @return boolean
*/
public function wasProcessed()
{
return $this->wasProcessed;
}
/**
* Set the response helper associated with this response.
*
* @param ResponseHelper $helper
* @return $this
*/
public function setHelper(ResponseHelper $helper)
{
$this->helper = $helper;
return $this;
}
/**
* Get the response helper. If one hasn't been set (process wasn't
* run, we return a new instance of the page's process helper to
* make testing easier.
*
* @return \Dewdrop\Admin\ResponseHelper\Standard
*/
public function getHelper()
{
return ($this->helper ?: $this->page->createResponseHelper());
}
/**
* Render the output generated by the page
*
* @return \Dewdrop\Admin\Response
*/
public function render()
{
echo $this->output;
return $this;
}
/**
* Execute the queued helper actions.
*
* @return \Dewdrop\Admin\Response
*/
public function executeQueuedActions()
{
$result = $this->executeHelper();
if ($this->helper->willShortCircuitResponse()) {
return $result;
}
return false;
}
/**
* When this object is used as a string, return the output.
*
* @return string
*/
public function __toString()
{
return $this->getOutput();
}
/**
* This is separated into its own method to allow mocking of queued
* action execution during testing.
*
* @return mixed
*/
protected function executeHelper()
{
return $this->helper->execute();
}
}