for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mhor\MediaInfo;
trait DumpTrait
{
/**
* Convert the object into json.
*
* @return array
*/
public function jsonSerialize()
return get_object_vars($this);
}
* Dump object to array.
public function __toArray()
return $this->jsonSerialize();
public function __toXML()
$components = explode('\\', get_class($this));
$rootNode = end($components);
$xml = new \SimpleXMLElement("<?xml version=\"1.0\"?><$rootNode></$rootNode>");
$array = json_decode(json_encode($this), true);
$this->composeXML($array, $xml);
return $xml;
protected function composeXML($data, &$xml)
foreach ($data as $key => $value) {
if (is_array($value)) {
if (is_numeric($key)) {
$key = 'item'.$key;
$subnode = $xml->addChild($key);
$this->composeXML($value, $subnode);
} else {
$xml->addChild("$key", htmlspecialchars("$value"));