30 lines
541 B
PHP
Raw Normal View History

2013-05-11 02:50:05 +02:00
<?php
namespace DesignPatterns\Structural\Decorator;
2013-05-11 02:50:05 +02:00
2013-09-11 16:18:40 +02:00
/**
* Class RenderInXml
*/
2013-05-11 02:50:05 +02:00
class RenderInXml extends Decorator
{
2013-09-11 16:18:40 +02:00
/**
* render data as XML
*
* @return mixed|string
*/
2013-05-11 02:50:05 +02:00
public function renderData()
{
2013-09-11 16:18:40 +02:00
$output = $this->wrapped->renderData();
// do some fancy conversion to xml from array ...
2013-05-11 02:50:05 +02:00
$doc = new \DOMDocument();
2013-09-11 16:18:40 +02:00
2013-05-11 02:50:05 +02:00
foreach ($output as $key => $val) {
2014-01-30 11:59:25 -02:00
$doc->appendChild($doc->createElement($key, $val));
2013-05-11 02:50:05 +02:00
}
2013-05-11 02:51:57 +02:00
2013-05-11 02:50:05 +02:00
return $doc->saveXML();
}
}