mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-01 20:50:15 +02:00
fix PSR-0
This commit is contained in:
@@ -15,25 +15,6 @@ namespace DesignPatterns\Decorator;
|
||||
*
|
||||
*/
|
||||
|
||||
interface Renderer
|
||||
{
|
||||
public function renderData();
|
||||
}
|
||||
|
||||
class Webservice implements Renderer
|
||||
{
|
||||
protected $_data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
}
|
||||
|
||||
public function renderData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the Deoorator MUST implement the Renderer contract, this is the key-feature
|
||||
@@ -56,30 +37,3 @@ abstract class Decorator implements Renderer
|
||||
}
|
||||
}
|
||||
|
||||
class RenderInJson extends Decorator
|
||||
{
|
||||
public function renderData()
|
||||
{
|
||||
$output = $this->_wrapped->renderData();
|
||||
return json_encode($output);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderInXml extends Decorator
|
||||
{
|
||||
public function renderData()
|
||||
{
|
||||
$output = $this->_wrapped->renderData();
|
||||
// do some fany conversion to xml from array ...
|
||||
return simplexml_load_string($output);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a normal service
|
||||
$service = new Webservice(array('foo' => 'bar'));
|
||||
|
||||
// Wrap service with a JSON decorator for renderers
|
||||
$service = new RenderInJson($service);
|
||||
// Our Renderer will now output JSON instead of an array
|
||||
|
||||
echo $service->renderData();
|
||||
|
Reference in New Issue
Block a user