Extracts the public properties from an iteratable object

@param mixed $obj    At first, feed this a Garp_Spawn_Model_Abstract, after which
it calls itself with an array.
@return array
502216
protected function _convertToArray($obj) {
        $arr    = array();
        $arrObj = is_object($obj) ? get_object_vars($obj) : $obj;

        foreach ($arrObj as $key => $val) {
            if (is_object($val)) {
                switch (get_class($val)) {
                case 'Garp_Spawn_Relation_Set':
                    $val = $val->getRelations();
                    break;
                case 'Garp_Spawn_Behaviors':
                    $val = $val->getBehaviors();
                    break;
                case 'Garp_Spawn_Fields':
                    $val = $val->getFields();
                }

                $val = $this->_convertToArray($val);
            } elseif (is_array($val)) {
                $val = $this->_convertToArray($val);
            }
            $arr[$key] = $val;
        }

        return $arr;
    }
615691
protected function invokeProperty($obj, $property = null)
    {
        if (null === $property) {
            return null;
        }

        if (!settype($property, 'string')) {
            return null;
        }

        $property = trim($property);
        if (0 === mb_strlen($property)) {
            return null;
        }

        if (!is_object($obj)) {
            return null;
        }

        $methods = [
            $this->createMethodName('get', $property),
            $this->createMethodName('is', $property),
            $property
        ];

        $r = new \ReflectionObject($obj);
        foreach ($methods as $method) {
            if ($r->hasMethod($method)) {
                $result = $r->getMethod($method)->invoke($obj);

                return $result;
            }
        }

        if ($r->hasProperty($property)) {
            $rProperty = $r->getProperty($property);
            if ($rProperty->isPublic()) {
                $result = $rProperty->getValue($obj);

                return $result;
            }
        }

        return null;
    }
929864
private function toArray($obj) {
        $arr = array();

        if (is_array($obj)) {
            foreach ($obj as $value) {
                $arr[] = $this->toArray($value);
            }
        } else if (is_object($obj)) {
            $arObj = (array) $obj;
            foreach ($arObj as $key => $value) {
                $attribute = str_replace(get_class($obj), "", $key);
                if (is_object($value) || is_array($value)) {
                    $value = $this->toArray($value);
                } else {
                    $arr[$attribute] = $this->utf8_encode_all($value);
                }
            }
        } else {
            $arr = $this->utf8_encode_all($obj);
        }
        return $arr;
    }
987704
private function buildDataFromObject($object)
    {
        $result = array();

        $stack = new \SplStack();
        $stack->push($object);

        while (!$stack->isEmpty()) {
            $current = $stack->pop();
            if (is_object($current)) {
                array_push($result, $current);
            }

            foreach ($this->getDataFromItem($current) as $propertyName => $propertyValue) {
                if (is_object($propertyValue) || is_array($propertyValue)) {
                    $stack->push($propertyValue);
                }
            }
        }

        return $result;
    }
569367
protected function objectToArray($obj, $keepNullProperties = true)
    {
        $arr = array();
        $arrObj = is_object($obj) ? get_object_vars($obj) : $obj;
        foreach ($arrObj as $key => $val) {
            $val = (is_array($val) || is_object($val)) ? $this->objectToArray($val, $keepNullProperties) : $val;
            if ($keepNullProperties || $val !== null) {
                $val = ($val === null) ? $val = '' : $val;
                $arr[$key] = is_scalar($val) ? ((string) $val) : $val;
            }
        }
        return $arr;
    }
255742
private static function objectToString($obj)
    {
        return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_hash($obj);
    }
173886
public function methods($object)
    {
        $methods = (new ReflectionClass($object))->getMethods(ReflectionMethod::IS_PUBLIC);

        $iterator = function(ReflectionMethod $method)
        {
            return $method->getName();
        };

        return array_map($iterator, $methods);
    }
497554
public function getGettablePropertiesOfObject($object)
    {
        $className = get_class($object);

        if (false === isset($this->gettablePropertiesOfObjects[$className])) {
            $this->gettablePropertiesOfObjects[$className] = [];
            $properties = $this->getReflectionService()->getClassPropertyNames($className);

            foreach ($properties as $propertyName) {
                if (true === $this->isPropertyGettable($object, $propertyName)) {
                    $this->gettablePropertiesOfObjects[$className][] = $propertyName;
                }
            }
        }

        return $this->gettablePropertiesOfObjects[$className];
    }
263590
protected function getGeneratedProperties(): array
    {
        $reflectionObject = new \ReflectionObject($this);
        $properties = $reflectionObject->getProperties(\ReflectionProperty::IS_PUBLIC);
        $result = [];
        foreach ($properties as $property) {
            if (!$property->isPublic() || @$property->isDefault()) {
                continue;
            }

            $result[] = $property;
        }

        return $result;
    }
1136107
protected function getBlobMeta($obj)
    {
        $date = $obj->uploadDate->toDateTime();
        $return = [
            'oid'            => (string)$obj->_id,
            'name'           => $obj->filename,
            'content_type'   => (isset($obj->contentType)) ? $obj->contentType : '',
            'content_length' => $obj->length,
            'last_modified'  => $date->format(\DateTime::ATOM),
            'path'           => $obj->filename,
        ];

        return $return;
    }
820584
public static function objectToArray($obj)
    {
        if (is_object($obj)) {
            if (method_exists($obj, 'toArray')) {
                $obj = $obj->toArray();
            } elseif (method_exists($obj, '__toArray')) {
                $obj = $obj->__toArray();
            } else {
                $obj = (array)$obj;
            }
        }
        if (is_array($obj)) {
            $new = [];
            foreach ($obj as $key => $val) {
                $new[$key] = self::objectToArray($val);
            }
        } else {
            $new = $obj;
        }

        return $new;
    }
1326077
public function formatObject($oObj)
    {
        return [
            'id'         => $oObj->id,
            'first_name' => $oObj->first_name,
            'last_name'  => $oObj->last_name,
            'email'      => $oObj->email,
        ];
    }
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;
    }
11899
public function renderBeforeStep($obj)
    {
        $print = array();
        foreach ($this->rendererList as $name => $renderer) {
            $print[$name] = $renderer->renderBeforeStep($obj);
        }

        return $print;
    }
873119
protected function getLocales($obj)
    {
        $result = [];
        if ($obj instanceof LocaleEntity) {
            $result[] = $obj;
        } elseif (is_string($obj)) {
            $app = Application::getFacadeApplication();
            $l = $app->make(LocaleRepository::class)->findApproved($obj);
            if ($l === null) {
                throw new UserMessageException(t('Invalid locale specified'));
            }
            $result[] = $l;
        } elseif (is_array($obj)) {
            foreach ($obj as $item) {
                $result = array_merge($result, $this->getLocales($item));
            }
        }
        if (empty($result)) {
            throw new UserMessageException(t('Invalid locale specified'));
        }

        return $result;
    }
362577
protected function exportObj($i, $obj)
    {
        if (array_search($obj, $this->outputObjects, true) !== false) {
            return $i . ' [recursion, skipped]<br />';
        }

        $this->outputObjects[] = $obj;

        $list = (array)$obj;

        $protectedLength = strlen(get_class($obj)) + 2;

        $out = array();

        if ($this->outputMethods) {
            $ref = new ReflectionObject($obj);

            foreach ($ref->getMethods() as $method) {
                if (!$method->isPublic()) {
                    continue;
                }

                if (empty($out['method'])) {
                    $out['method'] = '';
                }

                $params = array();
                foreach ($method->getParameters() as $param) {
                    $params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : '');
                }

                $out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />';
            }
        }

        foreach ($list as $attributeName => $attributeValue) {
            if (property_exists($obj, $attributeName)) {
                $key = 'public';
            } elseif (substr($attributeName, 0, 3) === "\0*\0") {
                $key           = 'protected';
                $attributeName = substr($attributeName, 3);
            } else {
                $key           = 'private';
                $attributeName = substr($attributeName, $protectedLength);
            }

            if (empty($out[$key])) {
                $out[$key] = '';
            }

            $out[$key] .= '(' . $key . ') ';

            if (is_array($attributeValue)) {
                $out[$key] .= $attributeName . ' (array):<br />
							<div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>';
            } elseif (is_object($attributeValue)) {
                $out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue);
            } else {
                $out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue);
            }
        }

        $return = $i . '<br /><div style="padding-left:20px;">';

        if (!empty($out['method'])) {
            $return .= $out['method'];
        }

        if (!empty($out['public'])) {
            $return .= $out['public'];
        }

        if (!empty($out['protected'])) {
            $return .= $out['protected'];
        }

        if (!empty($out['private'])) {
            $return .= $out['private'];
        }

        return $return . '</div>';
    }
909051
public function mapOneFromResult($obj_result)
    {
        // Key & Ancestry
        list($obj_gds_entity, $bol_schema_match) = $this->createEntityWithKey($obj_result);
        /** @var Entity $obj_gds_entity */

        // Properties
        if(isset($obj_result->entity->properties)) {
            $arr_property_definitions = $this->obj_schema->getProperties();
            foreach ($obj_result->entity->properties as $str_field => $obj_property) {
                if ($bol_schema_match && isset($arr_property_definitions[$str_field])) {
                    $obj_gds_entity->__set($str_field, $this->extractPropertyValue($arr_property_definitions[$str_field]['type'], $obj_property));
                } else {
                    $obj_gds_entity->__set($str_field, $this->extractPropertyValue(Schema::PROPERTY_DETECT, $obj_property));
                }
            }
        }

        // Done
        return $obj_gds_entity;
    }