Return fields of mapper object as an associative array
@return array
@param bool|Cortex $obj
@param int|array $rel_depths depths to resolve relations
545091
public function cast($obj = NULL, $rel_depths = 1) {
		$fields = $this->mapper->cast( ($obj) ? $obj->mapper : null );
		if (!empty($this->vFields))
			foreach(array_keys($this->vFields) as $key)
				$fields[$key]=$this->get($key);
		if (is_int($rel_depths))
			$rel_depths = array('*'=>$rel_depths-1);
		elseif (is_array($rel_depths))
			$rel_depths['*'] = isset($rel_depths['*'])?--$rel_depths['*']:-1;
		if ($this->fieldConf) {
			$fields += array_fill_keys(array_keys($this->fieldConf),NULL);
			if ($this->whitelist)
				$fields = array_intersect_key($fields, array_flip($this->whitelist));
			$mp = $obj ? : $this;
			foreach ($fields as $key => &$val) {
				// post process configured fields
				if (isset($this->fieldConf[$key]) && is_array($this->fieldConf[$key])) {
					// handle relations
					$rd = isset($rel_depths[$key]) ? $rel_depths[$key] : $rel_depths['*'];
					if ((is_array($rd) || $rd >= 0) && $type=preg_grep('/[belongs|has]-(to-)*[one|many]/',
							array_keys($this->fieldConf[$key]))) {
						$relType=current($type);
						// cast relations
						$val = (($relType == 'belongs-to-one' || $relType == 'belongs-to-many')
							&& !$mp->exists($key)) ? NULL : $mp->get($key);
						if ($val instanceof Cortex)
							$val = $val->cast(null, $rd);
						elseif ($val instanceof CortexCollection)
							$val = $val->castAll($rd);
					}
					// extract array fields
					elseif (isset($this->fieldConf[$key]['type'])) {
						if ($this->dbsType == 'sql') {
							if ($this->fieldConf[$key]['type'] == self::DT_SERIALIZED)
								$val=unserialize($mp->mapper->{$key});
							elseif ($this->fieldConf[$key]['type'] == self::DT_JSON)
								$val=json_decode($mp->mapper->{$key}, true);
						}
						if ($this->exists($key)
							&& preg_match('/BOOL/i',$this->fieldConf[$key]['type'])) {
							$val = (bool) $mp->mapper->{$key};
						}
					}
				}
				if ($this->dbsType == 'mongo' && $key == '_id')
					$val = (string) $val;
				if ($this->dbsType == 'sql' && $key == 'id' && $this->standardiseID) {
					$fields['_id'] = $val;
					unset($fields[$key]);
				}
				unset($val);
			}
		}
		// custom getter
		foreach ($fields as $key => &$val) {
			$val = $this->emit('get_'.$key, $val);
			unset($val);
		}
		return $fields;
	}
171612
public static function array_set(string $key, $value, array $obj)
    {
        if (is_null($key)) {
            return json_encode($obj);
        }
        $keys = explode('.', $key);
        $tmp = &$obj;
        while (count($keys) > 0) {
            $key = array_shift($keys);

            // If the key doesn't exist at this depth, we will just create an empty array
            // to hold the next value, allowing us to create the arrays to hold final
            // values at the correct depth. Then we'll keep digging into the array.
            if (!isset($tmp[$key]) || !is_array($tmp[$key])) {
                $tmp[$key] = [];
            }

            $tmp = &$tmp[$key];
        }
        $tmp = $value;

        return $obj;
    }
736994
public function getCategoryValues($asArray = null)
    {
        if (!$this->owner->getIsNewRecord() && $this->_categoryValues === null) {
            $this->_categoryValues = [];

            /* @var ActiveRecord $category */
            foreach ($this->owner->{$this->categoryRelation} as $category) {
                $this->_categoryValues[] = $category->getAttribute($this->categoryValueAttribute);
            }
        }

        if ($asArray === null) {
            $asArray = $this->categoryValuesAsArray;
        }

        if ($asArray) {
            return $this->_categoryValues === null ? [] : $this->_categoryValues;
        } else {
            return $this->_categoryValues === null ? '' : implode(', ', $this->_categoryValues);
        }
    }
957402
public function toArray(Entity $entity, $depth=0) {
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($entity->getDefinition()->property($name) instanceof Property\EntityProperty) {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name, null, false) as $subentity)
						$res[$name][] = $subentity->toArray($depth-1);
				}
				else {
					if($subentity = $entity->get($name, null, false))
						$res[$name] = $subentity->toArray($depth-1);
					else
						$res[$name] = null;
				}
			}
			elseif($property->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name) as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
615337
protected function objectToArray($obj, $keepNullProperties = true)
    {
        $arr = array();
        $arrObj = $this->getObjectVars($obj);

        foreach ($arrObj as $key => $val) {
            $val = $this->isComplex($val)
                ? $this->objectToArray($val, $keepNullProperties)
                : $val;

            if ($keepNullProperties || $val !== null) {
                $val = ($val === null) ? '' : $val;
                $arr[$key] = $val;
            }
        }

        return $arr;
    }
1282866
protected static function deepCopy($obj)
    {
        if (is_array($obj)) {
            $copy = [];
            foreach ($obj as $k => $v) {
                $copy[$k] = self::deepCopy($v);
            }
            return $copy;
        } elseif ($obj instanceof StripeObject) {
            return $obj::constructFrom(
                self::deepCopy($obj->_values),
                clone $obj->_opts
            );
        } else {
            return $obj;
        }
    }
534266
public final function populateObjectList($input, $deep = true)
	{
		if($this instanceof ArrayAccess == false)
			throw new Exception("Cannot set properties on objects that are not children of 'ArrayAccess'");
		
		if(!is_array($input))
		{
			if($input instanceof Traversable && method_exists($input, "toArray"))
				$input = $input->toArray();
			elseif($input instanceof Traversable)
				$input = iterator_to_array($input);
			else
				$input = [];
		}
		
		if($deep)
		{
			foreach($input as $key => $value)
			{
				if(is_null($value) || is_scalar($value))
					$this[$key] = $value;
				else
					$this[$key] = (new static())->populateObjectList($value, $deep);
			}
		}
		else
		{
			foreach($input as $key => $value)
			{
				# if we're not in deep mode then all we're doing is going through
				# each of the items and tacking them onto the stack, or something
				$this[$key] = $value;
			}
		}
		
		return $this;
	}
1075984
public static function getProperties($obj)
    {
        $properties = array();
        try {
            $rc = new ReflectionClass($obj);
            do {
                $rp = array();

                // Note that we will not include any properties in traits
                $traits = $rc->getTraits();
                $skipProperties = array();
                if (!empty($traits)) {
                    foreach ($traits as $trait) {
                        foreach ($trait->getProperties() as $traitProperty) {
                            $skipProperties[] = $traitProperty->getName();
                        }
                    }
                }
                /* @var $p \ReflectionProperty */
                foreach ($rc->getProperties() as $p) {
                    if (in_array($p->getName(), $skipProperties, true)) {
                        continue;
                    }
                    $p->setAccessible(true);
                    $rp[$p->getName()] = $p->getValue($obj);
                }
                $properties = array_merge($rp, $properties);
            } while ($rc = $rc->getParentClass());
        } catch (ReflectionException $e) {
            //
        }
        return $properties;
    }
495220
public function parents($depth = null) {
        $condition = [
            'and',
            [$this->leftAttribute => ['$lt' => $this->owner->getAttribute($this->leftAttribute)]],
            [$this->rightAttribute => ['$gt' => $this->owner->getAttribute($this->rightAttribute)]],
        ];

        if ($depth !== null) {
            $condition[] = [$this->depthAttribute => ['$gte' => $this->owner->getAttribute($this->depthAttribute) - $depth]];
        }

        $this->applyTreeAttributeCondition($condition);

        return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
    }
465359
static function RecurseXmlObjToArr($obj, &$arr)
	{
		$children = $obj->children();
		foreach ($children as $elementName => $node)
		{
			$nextIdx = count($arr);
			$arr[$nextIdx] = array();
			$arr[$nextIdx]['@name'] = strtolower((string)$elementName);
			$arr[$nextIdx]['@attributes'] = array();
			$attributes = $node->attributes();
			foreach ($attributes as $attributeName => $attributeValue)
			{
				$attribName = strtolower(trim((string)$attributeName));
				$attribVal = trim((string)$attributeValue);
				$arr[$nextIdx]['@attributes'][$attribName] = $attribVal;
			}
			$text = (string)$node;
			$text = trim($text);
			if (strlen($text) > 0)
			{
				$arr[$nextIdx]['@text'] = $text;
			}
			$arr[$nextIdx]['@children'] = array();
			VerySimpleXmlUtil::RecurseXmlObjToArr($node, $arr[$nextIdx]['@children']);
		}
		return;
	}
625641
public function pegaAtributosDoObjeto($obj)
    {
        $properties      = [];
        $reflectionClass = new ReflectionClass($obj);
        $propriedades    = $reflectionClass->getProperties(
            ReflectionProperty::IS_PUBLIC |
            ReflectionProperty::IS_PROTECTED | 
            ReflectionProperty::IS_PRIVATE
        );
     
        $iterator = 0;
        $limit    = count($propriedades);
        for ($iterator = 0; $iterator < $limit; $iterator++) {
            $properties[$iterator] = $propriedades[$iterator]->name;
        }

        return $properties;
    }
1073030
public function castAll($rel_depths=1) {
		$out = array();
		foreach ($this->getArrayCopy() as $model)
			$out[] = $model->cast(null,$rel_depths);
		return $out;
	}
748258
private static function createFromResponseArrayAnchorObject(
        array $responseArray,
        int $depthCounter = null
    ) {
        if (empty($responseArray)) {
            return null;
        }

        if (is_null($depthCounter)) {
            $depthCounter = self::DEPTH_COUNTER_BEGIN;
        }

        $model = self::createInstanceFromResponseArray($responseArray);

        if ($model->isAllFieldNull() && $depthCounter < self::DEPTH_COUNTER_MAX) {
            $model = self::decodeInsideModelFields($responseArray, $model, $depthCounter);
        }

        return $model;
    }
879337
protected function normalizeAsArray($objects) : array
    {
        $key = $this->relation;

        if (!is_array($objects) && !$objects instanceof Collection) {
            throw new MappingException("column '$key' should be of type array or collection");
        }

        if ($objects instanceof Collection) {
            $objects = $objects->all();
        }

        $normalizedObjects = [];

        foreach ($objects as $object) {
            $wrapper = $this->factory->make($object);
            $normalizedObjects[] = $wrapper->getEntityAttributes();
        }

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

        return [$key => $normalizedObjects];
    }
1114166
function deepCopy(obj) {
			var ret = {}, key, val;
			for (key in obj) {
				if (obj.hasOwnProperty(key)) {
					val = obj[key];
					if (typeof val === 'object' && val !== null) {
						ret[key] = deepCopy(val);
					} else {
						ret[key] = val;
					}
				}
			}
			return ret;
		}
584968
private function getFieldsByFieldNormalizationMappings(
        NormalizerContextInterface $context,
        array $normalizationFieldMappings,
        string $path,
        $object
    ): array {
        $data = [];
        foreach ($normalizationFieldMappings as $normalizationFieldMapping) {
            if (!$this->isWithinGroup($context, $normalizationFieldMapping)) {
                continue;
            }

            $fieldNormalizer = $normalizationFieldMapping->getFieldNormalizer();

            $name = $normalizationFieldMapping->getName();

            $subPath = $this->getSubPathByName($path, $name);

            $this->logger->info('serialize: path {path}', ['path' => $subPath]);

            $data[$name] = $fieldNormalizer->normalizeField($subPath, $object, $context, $this);
        }

        return $data;
    }
1141064
public static function object_to_array($obj)
	{
		//$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
		if(is_object($obj) || is_array($obj)){
			if(is_object($obj)){
				$_arr = get_object_vars($obj);
			}else{
				$_arr = $obj;
			}
			foreach ($_arr as $key => $val)
			{
				$val = (is_array($val) || is_object($val)) ? self::object_to_array($val) : $val;
				$arr[$key] = $val;
			}
			return $arr;
		}else{
			return $obj;
		}
		
	}