extract object properties to data

@param object $object
@param array $map fieldName: propertyName

@return array
@throws \ReflectionException
325417
public function extract($object, array $map = null): array
    {
        $result = [];

        $className = \get_class($object);
        $reflection = $this->getReflection($className);

        if (!\is_array($map) || !$map) {
            $propertyList = $this->getReflectionPropertyList($className);
            $map = \array_combine($propertyList, $propertyList);
        }
        foreach ($map as $fieldName => $propertyName) {
            if ($reflection->hasProperty($propertyName)) {
                $property = $this->getProperty($reflection, $propertyName);
                $result[$fieldName] = $property->getValue($object);
            }
        }

        return $result;
    }
350949
public function extract($object)
    {
        if (!$object instanceof PageEntityInterface) {
            throw new Exception\InvalidArgumentException(
                '$object must be an instance of PlaygroundCms\Entity\PageInterface'
            );
        }

        /* @var $object PageInterface*/
        $data = parent::extract($object);
        $data = $this->mapField('id', 'page_id', $data);

        return $data;
    }
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;
    }
1244202
protected function extractAttributes($object, $format = null, array $context = []): array
    {
        $class = \get_class($object);

        if (false === isset($this->localStorage[$class]))
        {
            $this->localStorage[$class] = parent::extractAttributes($object, $format, $context);
        }

        return $this->localStorage[$class];
    }
1174152
public function extract($object)
    {
        $array = array();
        $properties = get_class_vars(get_class($object));
        foreach ($properties as $property => $value) {
            $key = StringUtil::snake($property);
            $array[$key] = $object->{$property};
        }

        return $array;
    }
1204218
protected function getIndexablePropertiesAndValuesFromObject($object)
    {
        $className = TypeHandling::getTypeForValue($object);
        $data = [];
        foreach ($this->indexInformer->getClassProperties($className) as $propertyName) {
            if (ObjectAccess::isPropertyGettable($object, $propertyName) === false) {
                continue;
            }

            $value = ObjectAccess::getProperty($object, $propertyName);
            if (($transformAnnotation = $this->reflectionService->getPropertyAnnotation($className, $propertyName, TransformAnnotation::class)) !== null) {
                $value = $this->transformerFactory->create($transformAnnotation->type)->transformByAnnotation($value, $transformAnnotation);
            }

            $data[$propertyName] = $value;
        }

        return $data;
    }
907007
private function getValue($object, \ReflectionProperty $property)
    {
        $value = null;

        if ($property->isPublic()) {
            $value = $property->getValue($object);
        } else {
            // Try to use accessor if property is not public
            $accessorName = $this->formatter->getPhpAccessor($property->getName(), false);
            $reflectedObject = new \ReflectionObject($object);
            $reflectedMethod = $reflectedObject->getMethod($accessorName);

            if (null !== $reflectedMethod) {
                $value = $reflectedMethod->invoke($object);
            }
        }

        return $value;
    }
87381
protected function parseObjectData($class, $object){
        $result = [];
        $reflection = new \ReflectionClass($class);
        foreach ($reflection->getProperties() as $property){
            $propertyName = $property->name;
            $method = 'get'.ucfirst($propertyName);
            $result[$propertyName] = $reflection->hasMethod($method) ? $object->$method() : null;
        }
        return $result;
    }
210929
protected function getPropertyValues(ReflectionClass $reflector, $object, $level)
    {
        $result = "";
        $indenting = str_repeat($this->config["array_indenting"], $level);

        foreach ($reflector->getProperties() as $property) {
            // Make the property readable (accessible) and then read its value.
            $property->setAccessible(true);

            // The issue fix: possible StackOverflowException.
            if (is_object($propertyValue = $property->getValue($object))) {
                $dumpedValue = $this->getGeneralObjectInfo($propertyValue);
            } else {
                $dumpedValue = $this->dump($propertyValue);
            }

            // Indent the output if it's an array.
            if (is_array($propertyValue)) {
                $lines = [];

                foreach (explode(PHP_EOL, $dumpedValue) as $line) {
                    if ($line !== "[") {
                        $lines[] = $indenting . $line;
                    } else {
                        $lines[] = $line;
                    }
                }

                $dumpedValue = implode(PHP_EOL, $lines);
            }

            $result .= sprintf(
                $indenting . "%s: %s" . PHP_EOL,
                $property->getName(),
                $dumpedValue
            );
        }

        return $result;
    }
945565
public function extract($object)
    {
        return [
            'type' => $object->getType(),
            'data' => $object->getData(),
            'store' => $object->getStore(),
            'download' => $object->isDownload(),
            'output_filename' => $object->getOutputFilename(),
            'category' => $object->getCategory(),
        ];
    }
1342074
public function extract($object)
    {
        if (!$object instanceof ServerInfo) {
            throw new \Exception('$object must be an instance of ServerInfo');
        }
        /* @var $object ServerInfo */
        $data = parent::extract($object);

        return $data;
    }
547091
public function extract($object)
    {
        $this->prepare($object);

        if ($this->byValue) {
            return $this->extractByValue($object);
        }

        return $this->extractByReference($object);
    }
922030
protected function objectToArray($object)
    {
        $class = get_class($object);
        $info = new \ReflectionClass($object);

        $this->commentMap[$class] = [];

        $methods = [];
        foreach ($info->getMethods() as $method) {
            if (!$method->isPublic()) {
                continue; // Only public
            }
            if ($method->class != $class) {
                continue; // Only locals
            }
            $name = $method->getName();
            if (in_array($name, $this->blockMethods)) {
                continue; // Blocked methods
            }
            if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) {
                continue; // AJAX methods
            }
            if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) {
                continue; // getSomethingOptions
            }
            if (substr($name, 0, 1) == '_') {
                continue; // Magic/hidden method
            }
            $name .= '()';
            $methods[$name] = '___METHOD___|'.$name;
            $this->commentMap[$name] = $this->evalDocBlock($method);
        }

        $vars = [];
        foreach ($info->getProperties() as $property) {
            if ($property->isStatic()) {
                continue; // Only non-static
            }
            if (!$property->isPublic()) {
                continue; // Only public
            }
            if ($property->class != $class) {
                continue; // Only locals
            }
            $name = $property->getName();
            $vars[$name] = $object->{$name};
            $this->commentMap[$name] = $this->evalDocBlock($property);
        }

        return $methods + $vars;
    }
588959
public static function fetchProperty($object, $property)
    {
        $refl = new \ReflectionObject($object);
        $prop = $refl->getProperty($property);
        $prop->setAccessible(true);

        return $prop->getValue($object);
    }
164519
public static function getPropertyValue($object, $property)
    {
        $ref = new \ReflectionClass($object);
        $prop = static::getPrivateProperty($ref, $property);
        $prop->setAccessible(true);
        $value = $prop->getValue($object);
        $prop->setAccessible(false);

        return $value;
    }
1123119
public function extract($object)
    {
        if (!$object instanceof BlockEntityInterface) {
            throw new Exception\InvalidArgumentException(
                '$object must be an instance of PlaygroundCms\Entity\BlockInterface'
            );
        }

        /* @var $object BlockInterface*/
        $data = parent::extract($object);
        //$data = $this->mapField('id', 'block_id', $data);
        return $data;
    }
1107428
protected function extractObjectProperties($object): array
    {
        $properties = [];

        $reflection = new \ReflectionObject($object);

        // obtain public, protected and private properties of the class itself:

        foreach ($reflection->getProperties() as $property) {
            if ($property->isStatic()) {
                continue; // omit static properties
            }

            $property->setAccessible(true);

            $properties["\${$property->name}"] = $property->getValue($object);
        }

        // obtain any inherited private properties from parent classes:

        while ($reflection = $reflection->getParentClass()) {
            foreach ($reflection->getProperties(\ReflectionProperty::IS_PRIVATE) as $property) {
                $property->setAccessible(true);

                $properties["{$reflection->name}::\${$property->name}"] = $property->getValue($object);
            }
        }

        return $properties;
    }