for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace floor12\DalliApi\Models;
use ReflectionClass;
use ReflectionException;
use SimpleXMLElement;
class DalliApiBody extends BaseXmlObject
{
/** @var string */
protected $authToken;
protected $apiMethodName = 'testMehod';
/** @var SimpleXMLElement */
protected $mainElement;
public function __construct(string $apiMethodName, string $authToken)
$this->apiMethodName = $apiMethodName;
$this->authToken = $authToken;
$this->mainElement = new SimpleXMLElement("<$this->apiMethodName></$this->apiMethodName>");
$auth = $this->mainElement->addChild('auth');
$auth->addAttribute('token', $this->authToken);
}
/**
* @param BaseXmlObject $object
* @return $this
* @throws ReflectionException
*/
public function add(BaseXmlObject $object): self
$className = mb_strtolower((new ReflectionClass($object))->getShortName());
$mainElement = $this->mainElement->addChild($className);
foreach ($object as $attributeName => $attributeValue) {
$this->processAttributeNameAndValue($mainElement, $attributeName, $attributeValue);
return $this;
* @param BaseXmlObject|null $object
* @return string
public function getAsXmlString(BaseXmlObject $object = null): string
return $this->mainElement->asXML();