public function convertToArray($object, $aliases = [], $fields = [])
    {
        if (empty($aliases)) {
            $aliases = $this->getAlias($object);
            if (count($fields) > 0) {
                $aliases = array_intersect_key($aliases, array_flip($fields));
            }
        }

        $array = [];

        // Variable $name defined in client.
        foreach ($aliases as $name => $alias) {
            if ($aliases[$name]['propertyType'] == 'private') {
                $value = $object->{$aliases[$name]['methods']['getter']}();
            } else {
                $value = $object->{$aliases[$name]['propertyName']};
            }

            if (isset($value)) {
                if (array_key_exists('aliases', $alias)) {
                    $new = [];
                    if ($alias['multiple']) {
                        $this->isCollection($aliases[$name]['propertyName'], $value);
                        foreach ($value as $item) {
                            $this->checkVariableType($item, [$alias['namespace']]);
                            $new[] = $this->convertToArray($item, $alias['aliases']);
                        }
                    } else {
                        $this->checkVariableType($value, [$alias['namespace']]);
                        $new = $this->convertToArray($value, $alias['aliases']);
                    }
                    $value = $new;
                }

                if ($value instanceof \DateTime) {
                    $value = $value->format(isset($alias['format']) ? $alias['format'] : \DateTime::ISO8601);
                }

                if (isset($alias['type'])) {
                    switch ($alias['type']) {
                        case 'float':
                            if (is_array($value)) {
                                foreach ($value as $key => $item) {
                                    $value[$key] = (float)$item;
                                }
                            } else {
                                $value = (float)$value;
                            }
                            break;
                        case 'integer':
                            if (is_array($value)) {
                                foreach ($value as $key => $item) {
                                    $value[$key] = (int)$item;
                                }
                            } else {
                                $value = (int)$value;
                            }
                            break;
                        default:
                            break;
                    }
                }

                $array[$name] = $value;
            }
        }

        return $array;
    }
public function convertToArray($object, $aliases = [], $fields = [])
    {
        if (empty($aliases)) {
            $aliases = $this->getAlias($object);
            if (count($fields) > 0) {
                $aliases = array_intersect_key($aliases, array_flip($fields));
            }
        }

        $array = [];

        // Variable $name defined in client.
        foreach ($aliases as $name => $alias) {
            if ($aliases[$name]['propertyType'] == 'private') {
                $value = $object->{$aliases[$name]['methods']['getter']}();
            } else {
                $value = $object->{$aliases[$name]['propertyName']};
            }

            if (isset($value)) {
                if (array_key_exists('aliases', $alias)) {
                    $new = [];
                    if ($alias['multiple']) {
                        $this->isCollection($aliases[$name]['propertyName'], $value);
                        foreach ($value as $item) {
                            $this->checkVariableType($item, [$alias['namespace']]);
                            $new[] = $this->convertToArray($item, $alias['aliases']);
                        }
                    } else {
                        $this->checkVariableType($value, [$alias['namespace']]);
                        $new = $this->convertToArray($value, $alias['aliases']);
                    }
                    $value = $new;
                }

                if ($value instanceof \DateTime) {
                    $value = $value->format(isset($alias['format']) ? $alias['format'] : \DateTime::ISO8601);
                }

                if (isset($alias['type'])) {
                    switch ($alias['type']) {
                        case 'float':
                            if (is_array($value)) {
                                foreach ($value as $key => $item) {
                                    $value[$key] = (float)$item;
                                }
                            } else {
                                $value = (float)$value;
                            }
                            break;
                        case 'integer':
                            if (is_array($value)) {
                                foreach ($value as $key => $item) {
                                    $value[$key] = (int)$item;
                                }
                            } else {
                                $value = (int)$value;
                            }
                            break;
                        default:
                            break;
                    }
                }

                $array[$name] = $value;
            }
        }

        return $array;
    }
public function convertToArray ( $ object , $ aliases = [ ] , $ fields = [ ] ) { if ( empty ( $ aliases ) ) { $ aliases = $ this -> getAlias ( $ object ) ; if ( count ( $ fields ) > 0 ) { $ aliases = array_intersect_key ( $ aliases , array_flip ( $ fields ) ) ; } } $ array = [ ] ; // Variable $name defined in client. foreach ( $ aliases as $ name => $ alias ) { if ( $ aliases [ $ name ] [ 'propertyType' ] == 'private' ) { $ value = $ object -> { $ aliases [ $ name ] [ 'methods' ] [ 'getter' ] } ( ) ; } else { $ value = $ object -> { $ aliases [ $ name ] [ 'propertyName' ] } ; } if ( isset ( $ value ) ) { if ( array_key_exists ( 'aliases' , $ alias ) ) { $ new = [ ] ; if ( $ alias [ 'multiple' ] ) { $ this -> isCollection ( $ aliases [ $ name ] [ 'propertyName' ] , $ value ) ; foreach ( $ value as $ item ) { $ this -> checkVariableType ( $ item , [ $ alias [ 'namespace' ] ] ) ; $ new [ ] = $ this -> convertToArray ( $ item , $ alias [ 'aliases' ] ) ; } } else { $ this -> checkVariableType ( $ value , [ $ alias [ 'namespace' ] ] ) ; $ new = $ this -> convertToArray ( $ value , $ alias [ 'aliases' ] ) ; } $ value = $ new ; } if ( $ value instanceof \ DateTime ) { $ value = $ value -> format ( isset ( $ alias [ 'format' ] ) ? $ alias [ 'format' ] : \ DateTime :: ISO8601 ) ; } if ( isset ( $ alias [ 'type' ] ) ) { switch ( $ alias [ 'type' ] ) { case 'float' : if ( is_array ( $ value ) ) { foreach ( $ value as $ key => $ item ) { $ value [ $ key ] = ( float ) $ item ; } } else { $ value = ( float ) $ value ; } break ; case 'integer' : if ( is_array ( $ value ) ) { foreach ( $ value as $ key => $ item ) { $ value [ $ key ] = ( int ) $ item ; } } else { $ value = ( int ) $ value ; } break ; default : break ; } } $ array [ $ name ] = $ value ; } } return $ array ; }
Converts object to an array.

@param mixed $object
@param array $aliases
@param array $fields

@return array
Converts object to an array .