for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PSFS\base\dto;
use PSFS\base\Logger;
use PSFS\base\Singleton;
/**
* Class Dto
* @package PSFS\base\dto
*/
class Dto extends Singleton
{
* ToArray wrapper
* @return array
public function toArray()
return $this->__toArray();
}
* Convert dto to array representation
public function __toArray()
$dto = array();
try {
$reflectionClass = new \ReflectionClass($this);
$properties = $reflectionClass->getProperties();
if(count($properties) > 0) {
/** @var \ReflectionProperty $property */
foreach($properties as $property) {
$dto[$property->getName()] = $property->getValue($this);
} catch(\Exception $e) {
Logger::getInstance(get_class($this))->errorLog($e->getMessage());
return $dto;
* Convert to string representation
* @return string
public function __toString()
return get_class($this);
* Hydrate object from array
* @param array $object
public function fromArray(array $object = array())
if(count($object) > 0) {
foreach($object as $key => $value) {
if(property_exists($this, $key)) {
$this->$key = $value;