public function __toArray()
    {
        $dto = array();
        try {
            $reflectionClass = new \ReflectionClass($this);
            $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
            if (count($properties) > 0) {
                /** @var \ReflectionProperty $property */
                foreach ($properties as $property) {
                    $value = $property->getValue($this);
                    if(is_object($value) && method_exists($value, 'toArray')) {
                        $dto[$property->getName()] = $value->toArray();
                    } elseif(is_array($value)) {
                        foreach($value as &$arrValue) {
                            if($arrValue instanceof Dto) {
                                $arrValue = $arrValue->toArray();
                            }
                        }
                        $dto[$property->getName()] = $value;
                    } else {
                        $dto[$property->getName()] = $property->getValue($this);
                    }
                }
            }
        } catch (\Exception $e) {
            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
        }
        return $dto;
    }
public function __toArray()
    {
        $dto = array();
        try {
            $reflectionClass = new \ReflectionClass($this);
            $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
            if (count($properties) > 0) {
                /** @var \ReflectionProperty $property */
                foreach ($properties as $property) {
                    $value = $property->getValue($this);
                    if(is_object($value) && method_exists($value, 'toArray')) {
                        $dto[$property->getName()] = $value->toArray();
                    } elseif(is_array($value)) {
                        foreach($value as &$arrValue) {
                            if($arrValue instanceof Dto) {
                                $arrValue = $arrValue->toArray();
                            }
                        }
                        $dto[$property->getName()] = $value;
                    } else {
                        $dto[$property->getName()] = $property->getValue($this);
                    }
                }
            }
        } catch (\Exception $e) {
            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
        }
        return $dto;
    }
public function __toArray ( ) { $ dto = array ( ) ; try { $ reflectionClass = new \ ReflectionClass ( $ this ) ; $ properties = $ reflectionClass -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) ; if ( count ( $ properties ) > 0 ) { /** @var \ReflectionProperty $property */ foreach ( $ properties as $ property ) { $ value = $ property -> getValue ( $ this ) ; if ( is_object ( $ value ) && method_exists ( $ value , 'toArray' ) ) { $ dto [ $ property -> getName ( ) ] = $ value -> toArray ( ) ; } elseif ( is_array ( $ value ) ) { foreach ( $ value as & $ arrValue ) { if ( $ arrValue instanceof Dto ) { $ arrValue = $ arrValue -> toArray ( ) ; } } $ dto [ $ property -> getName ( ) ] = $ value ; } else { $ dto [ $ property -> getName ( ) ] = $ property -> getValue ( $ this ) ; } } } } catch ( \ Exception $ e ) { Logger :: log ( get_class ( $ this ) . ': ' . $ e -> getMessage ( ) , LOG_ERR ) ; } return $ dto ; }
Convert dto to array representation
@return array
Convert dto to array representation