Object to array.


@param SimpleXMLElement $obj

@return array
506341
protected static function normalize($obj)
    {
        $result = null;

        if (is_object($obj)) {
            $obj = (array) $obj;
        }

        if (is_array($obj)) {
            foreach ($obj as $key => $value) {
                $res = self::normalize($value);
                if (('@attributes' === $key) && ($key)) {
                    $result = $res; // @codeCoverageIgnore
                } else {
                    $result[$key] = $res;
                }
            }
        } else {
            $result = $obj;
        }

        return $result;
    }
801902
protected static function objectToArray($object)
    {
        if (!\is_object($object)) {
            return $object;
        }

        if (\is_object($object)) {
            $object = \get_object_vars($object);
        }

        return \array_map(['static', 'objectToArray'], $object);
    }
1159557
public static function jsonEncode( $obj )
    {
        if ( self::$nativeJsonEncode === null )
            self::$nativeJsonEncode = function_exists( 'json_encode' );

        if ( self::$nativeJsonEncode === true )
            return json_encode( $obj );

        $inst = self::getInstance();
        return $inst->phpJsonEncode( $obj );    
    }
430033
public function xmlToArray($xmlObject, $output = array())
    {
        foreach ((array) $xmlObject as $index => $node) {
            $output[$index] = ($node instanceof \SimpleXMLElement || is_array($node))
                ? $this->xmlToArray($node)
                : $node;
        }

        return $output;
    }
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;
    }
483665
private function convertToDB($obj)
    {
        $o = $this->getEmptyObject();

        foreach ($this->fields as $field) {
            if (!property_exists($obj, $field->identifier()))
                continue;

            if (is_null($obj->{$field->identifier()})) {
                $o->{$field->identifier()} = 'NULL';
                continue;
            }

            $val = $obj->{$field->identifier()};

            switch ($field->type()) {
                case self::FIELD_TYPE_BOOL :
                    $o->{$field->identifier()} = $val ? 1 : 0;
                    break;
                case self::FIELD_TYPE_INT :
                    $o->{$field->identifier()} = (int) $val;
                    break;
                case self::FIELD_TYPE_FLOAT :
                    $o->{$field->identifier()} = (float) $val;
                    break;
                case self::FIELD_TYPE_STR :
                    $o->{$field->identifier()} = $this->escape($val);
                    break;
                case self::FIELD_TYPE_DATETIME :
                    if ($val && !is_null($val)) {
                        $o->{$field->identifier()} = $val->getTimestamp();
                    } else {
                        $o->{$field->identifier()} = 0;
                    }

                    break;
                case self::FIELD_TYPE_STR_ARRAY :
                    $delimiter = '(^!)';
                    $o->{$field->identifier()} = '"' . implode($delimiter, array_map(function($v) use ($delimiter) {
                            str_replace($delimiter, '', $v);
                        }, $val)) . '"';
                    break;
                case self::FIELD_TYPE_INT_ARRAY :
                    $val = array_map(function($v){ return "'" . (int)$v . "'"; }, $val);
                    $o->{$field->identifier()} = '"' . implode(',', $val) . '"';
                    break;
                case self::FIELD_TYPE_OBJ :
                    $o->{$field->identifier()} = '"' . addslashes(json_encode($val)) . '"';
                    break;
                default :
                    throw new TypeNotExistException();
            }
        }

        return $o;
    }
529452
private Object[] _asArray(
                    final Object obj
                    )
    {
        Object[]  array = null;
        if (obj instanceof Object[]) {
            array = (Object[])obj;
            if (array.length == 0) {
                throw new IllegalArgumentException( "ERROR: empty array" );
            }
        } else {
            array = new Object[] { obj };
        }

        return array;
    }
249210
public static function to_array($object) {
        if (is_array($object)) return $object;
        if (!is_object($object) && !is_array($object)) return $object;
        if (is_object($object)) $object = get_object_vars($object);

        return array_map([
            __CLASS__,
            'to_array'
        ], $object);
    }
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;
	}
677809
public static function objectToArray($OBJ)
    {
        if (is_object($OBJ)) {
            // Gets the properties of the given object with get_object_vars function
            $OBJ = get_object_vars($OBJ);
        }
        if (is_array($OBJ)) {
            // Return array converted to object using __FUNCTION__ (Magic constant) for recursive call in THIS object class type
            return array_map([get_called_class(), __FUNCTION__], $OBJ);
        }

        return $OBJ;
    }
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;
    }
529019
public function getMetaObject(string $obj): self
    {
        static $STATIC_CACHE = [];

        $cacheKey = $obj;
        if (!empty($STATIC_CACHE[$cacheKey])) {
            return $STATIC_CACHE[$cacheKey];
        }

        $reflector = new \ReflectionClass($obj);
        $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
        $docComment = $reflector->getDocComment();
        if ($docComment) {
            $docblock = $factory->create($docComment);
            foreach ($docblock->getTagsByName('property') as $tag) {
                /** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
                $PropertyName = $tag->getVariableName();
                $this->{$PropertyName} = $PropertyName;
            }
        }

        $STATIC_CACHE[$cacheKey] = $this;

        return $this;
    }
407853
public function toArray(SimpleXMLElement $xml = null)
	{
		if ($xml === null) {
			$xml = $this->xml;
		}

		if (!$xml->children()) {
			return (string) $xml;
		}

		$arr = array();
		foreach ($xml->children() as $tag => $child) {
			if (count($xml->$tag) === 1) {
				$arr[$tag] = $this->toArray($child);
			} else {
				$arr[$tag][] = $this->toArray($child);
			}
		}

		return $arr;
	}
157859
function ( obj ) {
		var result = [];

		array.each( obj, function ( i ) {
			array.add( result, i );
		});

		return result;
	}
955667
protected function convertXmlObjectToArray($xml)
    {
        $array = (array) $xml;

        if (count($array) == 0 && ! is_array($xml)) {

            $array = [ (string) $xml ];
        }

        if (is_array($array)) {

            foreach ($array as $key => $value) {

                if (is_object($value)) {

                    if (strpos(get_class($value), "SimpleXML") !== false) {

                        $array[ $key ] = $this->convertXmlObjectToArray($value);

                    } else {

                        $array[ $key ] = $this->convertXmlObjectToArray( (array) $value );
                    }

                } elseif (is_array($value)) {

                    $array[ $key ] = $this->convertXmlObjectToArray($value);
                }
            }
        }

        return $array;
    }
417875
function makeArray( obj ) {
  var ary = [];
  if ( isArray( obj ) ) {
    // use object if already an array
    ary = obj;
  } else if ( typeof obj.length === 'number' ) {
    // convert nodeList to array
    for ( var i=0, len = obj.length; i < len; i++ ) {
      ary.push( obj[i] );
    }
  } else {
    // array of single index
    ary.push( obj );
  }
  return ary;
}
827002
protected function objectToArray($obj)
    {
        if (!is_array($obj) && !is_object($obj)) {
            return $obj;
        }

        if (is_array($obj)) {
            return $obj;
        }

        if (is_object($obj)) {
            $obj = get_object_vars($obj);
        }

        return array_map([$this, 'objectToArray'], $obj);
    }