Converts object to an array.

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

@return array
777726
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;
    }
20990
public function fields(array $fields)
    {
        $newFields = array();
        $this->fields = '';
        $this->fieldsArguments = array();

        foreach ($fields as $field) {
            if (is_scalar($field)) {
                $newFields[] = '?f:alias:.?f';
                $this->fieldsArguments[] = $field;
            } else {
                if (!isset($field[0]) or !isset($field[1]) or !is_array($field[1])) {
                    throw new \BadMethodCallException('Must be exist 0 and 1 index in array and second one must be an array');
                }
                $newFields[] = $field[0];
                $this->fieldsArguments = array_merge($this->fieldsArguments, $field[1]);
            }
        }

        $this->fields = implode(', ', $newFields);

        return $this;
    }
1285087
public static function serialize($object) : array
    {
        $serializer = new static();
        $data = $serializer->serializeObject($object);

        if (sizeof($serializer->referencesUsed)) {
            foreach ($serializer->referencesUsed as $index) {
                $data['@references'][$index] = $serializer->references[$index];
            }
        }

        return $data;
    }
322306
protected function _toArray($object)
    {
        $reflectionClass = new \ReflectionClass(get_class($object));
        $array           = array();
        foreach ($reflectionClass->getProperties() as $property)
        {
            $property->setAccessible(true);
            $array[$property->getName()] = $property->getValue($object);
            $property->setAccessible(false);
        }
        return $array;
    }
384661
protected function entityToArray($class, $object)
    {
        if (is_object($object) && get_class($object) == $class) {
            $object = $object->toArray();
        }
        return $object;
    }
1190405
protected function normalizeAsArray($object) : array
    {
        $wrapper = $this->factory->make($object);

        $value = $wrapper->getEntityAttributes();

        if ($this->asJson) {
            $value = json_encode($value);
        }

        return [$this->relation => $value];
    }
951747
private static function toArray($object)
    {
        $json = array();
        $props = self::getProperties($object);
        foreach ($props as $key => $value) {
            $check_references = explode("_", $key);
            $getter = "";
            if (count($check_references) > 0) {
                foreach ($check_references as $reference) {
                    $getter .= ucfirst($reference);
                }
            } else {
                $getter = ucfirst($key);
            }
            $getter = "get" . $getter;

            if (!method_exists($object, $getter)) {
                continue;
            }
            $key = self::toSnakeCase($key);
            $value = $object->$getter();
            if (self::isNull($value)) {
                continue;
            }
            if ($value instanceof \Iterator) {
                $value = iterator_to_array($value);
            }
            if (is_object($value)) {
                $json[$key] = self::toArray($value);
            } else {
                if (is_array($value)) {
                    $json[$key] = array();
                    if (ArrayHelper::isAssoc($value)) {
                        foreach ($value as $k => $anObject) {
                            if (is_object($anObject)) {
                                $json[$key][$k] = self::toArray($anObject);
                            } else {
                                $json[$key][$k] = $anObject;
                            }
                        }
                    } else {
                        foreach ($value as $anObject) {
                            if (is_object($anObject)) {
                                $json[$key][] = self::toArray($anObject);
                            } else {
                                $json[$key][] = $anObject;
                            }
                        }
                    }
                } else {
                    $json[$key] = $value;
                }
            }
        }

        return $json;
    }
964238
public static function stdClassToArray(\stdClass $object)
    {
        $object = (array) $object;
        foreach ($object as &$value) {
            if ($value instanceof \stdClass) {
                $value = self::stdClassToArray($value);
                continue;
            }
            if (is_array($value)) {
                foreach ($value as &$arrayValue) {
                    if ($arrayValue instanceof \stdClass) {
                        $arrayValue = self::stdClassToArray($arrayValue);
                        continue;
                    }
                }
            }
        }

        return $object;
    }
592066
public function fields(array $fields = null) {
        if ($fields === null) {
            return $this->fields;
        }

        $this->fields = $fields;

        return $this;
    }
864829
private function convert(Array $object): Array {
    $parse = Array();
    foreach ($object as $key => $value) {
      if ($value instanceof stdClass) {
        $parse[$key] = $this->convert((Array) $value);
      } else {
        $parse[$key] = $value;
      }
    }
    return $parse;
  }
895996
private static function toArrayRecursive($object)
    {
        $output = get_object_vars($object);

        foreach ($output as $key => $value) {
            if ($value instanceof \DateTime) {
                $output[$key] = $value->format('c');
            } elseif (is_object($value)) {
                $output[$key] = static::toArrayRecursive($value);
            }
        }

        return $output;
    }
35247
private function buildMapSubject(array $objects)
    {
        $subjects = [];

        foreach ($objects as $object) {
            $subject = SubjectIdentity::fromObject($object);
            $id = SharingUtils::getCacheId($subject);
            $subjects[$id] = $subject;
        }

        return $subjects;
    }
1079710
protected function doExtract($object)
    {
        $originalFieldNames = $this->metadata->getOriginalFieldNames();

        /*
        $filter = $object instanceof FilterProviderInterface
            ? $object->getFilter()
            : $this->filterComposite;
        */

        $data = [];
        if (! $this->metadata->hasCustomHydrator()) {

            $this->executeMethods($object, $this->metadata->getPreExtractListeners());

            foreach ($originalFieldNames as $originalFieldName) {
                $mappedFieldName = $this->metadata->getMappedFieldName($originalFieldName);

                if ($this->metadata->isNotManaged($mappedFieldName)) {
                    continue;
                }

                if ($this->metadata->isValueObject($mappedFieldName)) {
                    continue;
                }

                /*if ($filter && !$filter->filter($mappedFieldName)) {
                    continue;
                }*/

                try {
                    $value = $this->memberAccessStrategy->getValue($object, $mappedFieldName);             
                } catch (NotFoundMemberException $e) {
                    continue;
                }

                if (null === $value) {
                    $data[$originalFieldName] = null;
                    continue;
                }

                if ($fieldClass = $this->metadata->getClassOfMappedField($mappedFieldName)) {
                    $fieldHydrator = $this->objectManager->createHydratorFor($fieldClass);
                    $fieldValue = $value;

                    /*if (! is_array($fieldValue)) {
                        throw new ObjectMappingException(
                            sprintf(
                                'Cannot hydrate field "%s" of class "%s" from raw data.'
                                . ' Raw data should be an array but got "%s".', 
                                $mappedFieldName,
                                $fieldClass,
                                is_object($fieldValue) ? get_class($fieldValue) : gettype($fieldValue)
                                )
                        );
                    }   */
                    
                    reset($fieldValue);
                    if (0 !== count($fieldValue) && ! is_numeric(key($fieldValue))) {
                        $fieldRawData = $fieldHydrator->extract($fieldValue);
                        $data[$originalFieldName] = $fieldRawData;                              
                    } else {

                        $fieldRawData = [];
                        foreach ($fieldValue as $itemFieldValue) {              
                            $fieldRawData[] = $fieldHydrator->extract($itemFieldValue);                
                        }
                        $data[$originalFieldName] = $fieldRawData;
                    }   
                } else {
                    $value = $this->extractValue($mappedFieldName, $value, $object, $data);
                    $data[$originalFieldName] = $value;    
                }
            }
        } else {
            list($customHydratorClass, , $customExtractMethod) = $this->metadata->getCustomHydratorInfo();            
            $this->executeMethod($object, new ClassMetadata\Model\Method($customHydratorClass, $customExtractMethod, [$object]));
        }

        //Value objects extraction.
        foreach ($this->metadata->getFieldsWithValueObjects() as $mappedFieldName) {

            if ($this->metadata->isNotManaged($mappedFieldName)) {
                continue;
            }

            $info = $this->metadata->getValueObjectInfo($mappedFieldName);
            list($voClassName, $voResource, $voResourceType) = $info;

            $valueObjectHydrator = $this->objectManager->createHydratorFor($voClassName);
            $objectKey = $this->pushRuntimeConfiguration($mappedFieldName, $object, $voClassName, $voResourceType, $voResource);

            $valueObject = $this->memberAccessStrategy->getValue($object, $mappedFieldName);
            $valueObjectData = $valueObjectHydrator->extract($valueObject, $objectKey);
            $this->popRuntimeConfiguration();

            $data = array_merge($data, $valueObjectData);
        }

        $this->executeMethods($object, $this->metadata->getPostExtractListeners());

        return $data;
    }
959967
public static function getFields($object)
    {
        $objectClass = BeanFactory::getObjectClass($object);
        if(!isset(static::$fields[$objectClass]))
        {
            $annotationsSet = AnnotationManager::getPropertiesAnnotations($objectClass, Column::class);
            $fields = [];
            foreach($annotationsSet as $propertyName => $annotations)
            {
                $annotation = $annotations[0];
                $fields[$annotation->name ?? $propertyName] = $annotation;
            }
            static::$fields[$objectClass] = $fields;
        }
        return static::$fields[$objectClass];
    }
1103067
public function toArray($object)
    {
        $this->assertObjectInstance($object);

        return array_map(
            function (Field $field) use ($object) {
                return $field->get($object);
            },
            $this->getFields()
        );
    }
1277971
public static function toArray( $object )
    {
        if ( is_object( $object ) )
        {
            return get_object_vars( $object );
        }

        if ( is_array( $object ) )
        {
            return array_map(
                array(
                    __CLASS__,
                    'toArray'
                ),
                $object
            );
        }

        // Return array
        return $object;
    }
1027765
public function getCustomFields($object)
    {
        $customFields = [];
        foreach ($object->getCustomFields() as $field) {
            $customFields[$field->getInternalFieldName()] = $field->getValue();
        }

        return $customFields;
    }