Builds xml string from provided array.

@param array $array
@return string
@author stev leibelt <artodeto@arcor.de>
@since 2013-06-03
499989
private function fromArrayToXmlString(array $array)
    {
        $string = '';

        foreach ($array as $key => $value) {
            $string .= '<' . $key . '>' .
                ((is_array($value))
                    ? $this->fromArrayToXmlString($value)
                    : $value) .
                '</' . $key . '>';
        }

        return $string;
    }
61715
public static function fromArray(array $array)
    {
        $hostname       = $array['hostname'] ?? null;
        $challengeTs    = $array['challenge_ts'] ?? null;
        $apkPackageName = $array['apk_package_name'] ?? null;

        if (isset($array['success']) && $array['success'] == true)
            return new static(true, [], $hostname, $challengeTs, $apkPackageName);

        if ( ! (isset($array['error-codes']) && is_array($array['error-codes'])))
            $array['error-codes'] = [ResponseV3::E_UNKNOWN_ERROR];

        return new static(false, $array['error-codes'], $hostname, $challengeTs, $apkPackageName);
    }
518453
static function build_line($array)
    {
        if (self::$data_sep)
        {
            $line = '';
            foreach ($array as $k => $v)
            {
                $line .= $k . self::$data_sep . $v . self::$col_sep;
            }
            return rtrim($line, self::$col_sep);
        }
        else
        {
            return implode(self::$col_sep, $array);
        }
    }
730150
protected function doCreateObject(array $array)
    {
        $raw = [];
        foreach ($array as $item) {
            $raw[$item['attributeId']]['id']               = $item['attributeId'];
            $raw[$item['attributeId']]['title']            = $item['title'];
            $raw[$item['attributeId']]['code']             = $item['code'];
            $raw[$item['attributeId']]['cssClass']         = $item['cssClass'];
            $raw[$item['attributeId']]['orderNumber']      = $item['orderNumber'];
            $raw[$item['attributeId']]['showInSpecList']   = $item['showInSpecList'];
            $raw[$item['attributeId']]['useInFilter']      = $item['useInFilter'];
            $raw[$item['attributeId']]['description']      = $item['description'];
            $raw[$item['attributeId']]['attributeGroupId'] = $item['attributeGroupId'];
            $raw[$item['attributeId']]['displayType']      = $item['displayType'];

            $raw[$item['attributeId']]['attributeValues'][] = [
                'id'     => $item['id'],
                'value'  => $item['value'],
                'cssClass' => $item['cssClass'],
                'title'  => $item['valueTitle'],
                'amount' => $item['amount'],
                'orderNumber' => $item['orderNumberAttributeValues'] ?? null
            ];
        }

        $mapper = new AttributesMapper();
        $result = [];
        foreach ($raw as $item) {
            $result[] = $mapper->createObject($item);
        }

        return $result;
    }
1096923
public static function arrayToXml($arr) {
        $xml = "<xml>";
        foreach ($arr as $key => $val){
            if (is_numeric($val)){
                $xml.="<$key>$val</$key>";
            }
            else
                $xml.="<$key><![CDATA[$val]]></$key>";
        }
        $xml.="</xml>";
        return $xml;
    }
603771
public static function buildObject($array) {
		$obj = new \stdClass();

		foreach ($array as $key => $value) {
			if (is_array($value)) {
				$obj->{$key} = self::buildObject($value);
			} else {
				$obj->{$key} = $value;
			}
		}

		return $obj;
	}
1300763
protected function doCreateObject(array $array)
    {
        $this->data = $array;
        $this->document = new Document($this->data);
        $this->setFunctionalNames()
             ->setAttributes()
             ->setMedia();

        return $this->document;
    }
877652
protected static function readArray(array $array): string
    {
        $data = [];

        foreach ($array as $key => $value) {
            $data[] = sprintf('%s => %s', $key, static::toString($value));
        }

        return sprintf('Array(%s)', implode(', ', $data));
    }
1374498
protected function buildMapDefinitions(array $array) {
		$result = [];
		foreach ($array as $alias => $value) {
			$result[] = "\t\t\t" . "'" . str_replace("'", "\'", $alias) . "' => " . $value . ',';
		}

		return implode(PHP_EOL, $result);
	}
1350479
public function copyToArray(array &$array)
    {
        parent::copyToArray($array);

        $array['action']                = LanguageUtility::toString($this->action);
        $array['clientId']              = $this->clientId;
        $array['subject']               = $this->subject;
        $array['scopes']                = $this->scopes;
        $array['existent']              = $this->existent;
        $array['usable']                = $this->usable;
        $array['sufficient']            = $this->sufficient;
        $array['refreshable']           = $this->refreshable;
        $array['responseContent']       = $this->responseContent;
        $array['expiresAt']             = $this->expiresAt;
        $array['properties']            = LanguageUtility::convertArrayOfArrayCopyableToArray($this->properties);
        $array['clientIdAlias']         = $this->clientIdAlias;
        $array['clientIdAliasUsed']     = $this->clientIdAliasUsed;
        $array['certificateThumbprint'] = $this->certificateThumbprint;
    }
1176281
public function copyToArray(array &$array)
    {
        parent::copyToArray($array);

        $array['action']                = LanguageUtility::toString($this->action);
        $array['responseContent']       = $this->responseContent;
        $array['accessToken']           = $this->accessToken;
        $array['accessTokenExpiresAt']  = LanguageUtility::orZero($this->accessTokenExpiresAt);
        $array['accessTokenDuration']   = LanguageUtility::orZero($this->accessTokenDuration);
        $array['refreshToken']          = $this->refreshToken;
        $array['refreshTokenExpiresAt'] = LanguageUtility::orZero($this->refreshTokenExpiresAt);
        $array['refreshTokenDuration']  = LanguageUtility::orZero($this->refreshTokenDuration);
        $array['clientId']              = $this->clientId;
        $array['clientIdAlias']         = $this->clientIdAlias;
        $array['subject']               = $this->subject;
        $array['scopes']                = $this->scopes;
        $array['properties']            = LanguageUtility::convertArrayOfArrayCopyableToArray($this->properties);
    }
979615
public static function fromArray($array=array())
    {
        $className = get_called_class();

        // hack that uses object deserialization to bypass constructor
        $object = unserialize(sprintf('O:%d:"%s":0:{}',
            strlen($className),
            $className));

        $object->_data = $array;
        $object->_saved = true;

        return $object;
    }
338184
public static function fromArray(array $array)
    {
        $hostname       = $array['hostname'] ?? null;
        $challengeTs    = $array['challenge_ts'] ?? null;
        $apkPackageName = $array['apk_package_name'] ?? null;
        $score          = isset($array['score']) ? floatval($array['score']) : null;
        $action         = $array['action'] ?? null;

        if (isset($array['success']) && $array['success'] == true)
            return new static(true, [], $hostname, $challengeTs, $apkPackageName, $score, $action);

        if ( ! (isset($array['error-codes']) && is_array($array['error-codes'])))
            $array['error-codes'] = [ResponseV3::E_UNKNOWN_ERROR];

        return new static(false, $array['error-codes'], $hostname, $challengeTs, $apkPackageName, $score, $action);
    }
221372
private function buildRequestRate($array)
    {
        $result = [];
        foreach ($array as $pair) {
            $string = self::DIRECTIVE_REQUEST_RATE . ':' . $pair['ratio'];
            if (isset($pair['from']) &&
                isset($pair['to'])
            ) {
                $string .= ' ' . $pair['from'] . '-' . $pair['to'];
            }
            $result[] = $string;
        }
        return $result;
    }
409524
public function packMap(array $array)
    {
        $size = count($array);
        $b = '';
        $b .= $this->getMapSizeMarker($size);

        foreach ($array as $k => $v) {
            $b .= $this->pack($k);
            $b .= $this->pack($v);
        }

        return $b;
    }
923220
public function htmlAttributes($array)
    {
        if (!isset($array)) {
            return null;
        }
       
        $str = "";
        foreach ($array as $key => $value) {
            if (!isset($value) || $value === false) {
                continue;
            }
            
            if ($value === true) {
                $value = $key;
            }
            
            $str .= ' ' . $key . '="' . addcslashes($value, '"') . '"';
        }
        
        return trim($str);
    }
1072299
public function build($array, $opts = array())
	{
		$this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
		$opts = array_merge(array(
			'xml_tag'		=> false,
			'xml_version'	=> '1.0',
			'xml_encoding'	=> 'utf-8',
			'empty_tags'	=> false,
			'empty_attribs' => false,
			'indent'		=> "\t",
			'wrap_tag'		=> null,
			'wrap_attribs'	=> array(),
			'debug_group'	=> false,
		), $opts);
		$w = new \XMLWriter();
		$w->openMemory();
		if ($opts['indent']) {
			$w->setIndent(true);
			$w->setIndentString("\t");
		}
		if ($opts['xml_tag']) {
			$w->startDocument($opts['xml_version'], $opts['xml_encoding']);
		}
		if ($opts['wrap_tag']) {
			$w->startElement($opts['wrap_tag']);
			foreach ($opts['wrap_attribs'] as $k => $v) {
				$w->writeAttribute($k, $v);
			}
		}
		$path = array();
		$levels = array(
			array(
				'startElement'		=> false,
				'keys'				=> array_keys($array),
				'pointer_source'	=> &$array,
			),
		);
		while (!empty($levels)) {
			$level =& $levels[count($levels)-1];
			if (empty($level['prepped'])) {
				#$this->debug->log('prepping');
				$level['prepped'] = true;
				#$this->debug->log('path', implode('/', $path));
				// make sure attribs is first in keys
				$key = array_search('attribs', $level['keys']);
				if ($key > 0) {
					unset($level['keys'][$key]);
					array_unshift($level['keys'], 'attribs');
				}
			}
			if (!empty($level['keys'])) {
				$key = array_shift($level['keys']);
				$val = &$level['pointer_source'][$key];
				$name = $key;
				if (is_int($key)) {
					$name = is_array($val) && isset($val['tag'])
						? $val['tag']
						: $path[count($path)-1];
				}
				#$this->debug->log('name a',$name);
				$collapsed = true;
				if (is_array($val)) {
					foreach ($val as $k => $v) {
						if (substr($k, 0, 1) == '_' && $k != '_text') {
							$k2 = substr($k, 1);
							$level['pointer_source'][$key]['attribs'][$k2] = $v;
							unset($level['pointer_source'][$key][$k]);
						}
					}
					if (isset($val['tag']) || isset($val['nodes']) || isset($val['text'])) {
						$collapsed = false;
						if (isset($val['tag'])) {
							$name = $val['tag'];
						}
						if (isset($val['prefix'])) {
							$name = $val['prefix'].':'.$name;
						}
					}
				}
				#$this->debug->log('name b',$name);
				if ($val === null || $val === array() || $val === '') {
					if ($opts['empty_tags']) {
						$w->writeElement($name, $val);
					}
					// else
					//	$this->debug->log('skip '.$key);
				} elseif (is_string($val) && $key === 'text') {
					$val = Str::toUtf8($val);
					$w->text($val);
				} elseif (is_array($val) && $key === 'attribs') {
					foreach ($val as $k => $v) {
						if (is_null($v)) {
							continue;
						}
						$w->writeAttribute($k, $v);
					}
				} elseif (is_array($val)) {
					if ($opts['debug_group']) {
						$this->debug->groupCollapsed($key);
					}
					#$this->debug->log('collapsed', $collapsed);
					if ($collapsed) {
						$level_new = array(
							'startElement'		=> ArrayUtil::isHash($val),
							'keys'				=> array_keys($val),
							'pointer_source'	=> &$level['pointer_source'][$key],
						);
					} else {
						$level_new = array(
							'startElement'		=> true,
							'keys'				=> !empty($val['nodes'])
														? array_keys($val['nodes'])
														: array(),
							'pointer_source'	=> isset($val['text'])
														? $val['text']
														: null,
						);
						if (!empty($val['nodes'])) {
							$level_new['pointer_source'] =& $level['pointer_source'][$key]['nodes'];
						}
					}
					#$this->debug->log('level_new', $level_new);
					$levels[] = $level_new;
					$path[] = $key;
					if ($level_new['startElement']) {
						$w->startElement($name);
						if (!$collapsed && !empty($val['attribs'])) {
							foreach ($val['attribs'] as $k => $v) {
								$w->writeAttribute($k, $v);
							}
						}
						if (empty($level_new['keys']) && isset($level_new['pointer_source']) && $level_new['pointer_source'] !== '') {
							$w->text($level_new['pointer_source']);
						}
					}
				} else {
					if ($name == '_text') {
						$name = 'text';
					}
					$val = Str::toUtf8($val);
					$w->writeElement($name, $val);
				}
			} else {
				array_pop($levels);
				$p = array_pop($path);
				if ($level['startElement']) {
					$w->endElement();
				}
				if ($opts['debug_group'] && $p !== null) {
					$this->debug->groupEnd();
				}
			}
		}
		if ($opts['wrap_tag']) {
			$w->endElement();
		}
		if ($opts['xml_tag']) {
			$w->endDocument();
		}
		$xml = $w->flush();
		if (!$opts['empty_tags']) {
			$xml = preg_replace('#'.$opts['indent'].'*<[\w:]+/>\n#', '', $xml);
		}
		$this->debug->groupEnd();
		return $xml;
	}