Converts the current webfile into its xml representation.

@param boolean $usePreamble sets the option of using a preamble in xml - usually used for setting the version of xml an the encoding.
@return string returns the webfile as a marshalled String.
194489
public function marshall($usePreamble = true)
    {
        $out = "";
        $attributes = $this->getAttributes();
        if ($usePreamble) {
            $out .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        }
        $out .= "<object classname=\"" . static::$m__sClassName . "\">\n";
        foreach ($attributes as $attribute) {

            $attributeName = $attribute->getName();

            if (MWebfile::isSimpleDatatype($attributeName)) {
                $attribute->setAccessible(true);
                $attributeFieldName = static::getSimplifiedAttributeName($attributeName);
                $out .= "\t<" . $attributeFieldName . "><![CDATA[" . $attribute->getValue($this) . "]]></" . $attributeFieldName . ">\n";
            }
        }
        $out .= "</object>";

        return $out;
    }
413767
public function loadAsXML()
    {
        $this->checkFileExists();
        $xml = new \DomDocument ();
        libxml_use_internal_errors(true);
        $result = $xml->load($this->absoluteFileName);
        if ($result) {
            return $xml;
        }
        $messageObject = ArrayUtil::getFromArray(libxml_get_errors(), 0);
        $libXMLMessage = ObjectUtil::getFromObject($messageObject, "message");
        $message = sprintf(self::EXCEPTION_INVALID_XML, $this->absoluteFileName, $libXMLMessage);
        $e = new \Exception(libxml_get_errors()[0]->message);
        libxml_clear_errors();
        throw $e;
    }
323868
public function useXml($option = true)
    {
        if ($option) {
            $this->contentType = self::MEDIA_TYPE_XML;
            $this->rawResponse = true;
        } else {
            $this->contentType = self::MEDIA_TYPE_JSON;
            $this->rawResponse = false;
        }
    }
88222
function toString()
    {
        $uri = '';

        if ($this->getScheme())
            $uri .= $this->getScheme() . ':'. '//';

        $uri .= $this->getAuthority();
        $uri .= parent::toString();

        if ($this->getHost() && (!$this->getQuery()->isEmpty() || $this->getFragment()))
            $uri .= '/';

        $replace = function ($match) { return rawurlencode($match[0]); };
        if (\Poirot\Std\cast($this->getQuery())->toArray()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "?" . preg_replace_callback($regex, $replace, $this->getQuery()->toString());
        }

        if ($this->getFragment()) {
            $regex   = '/(?:[^' .'a-zA-Z0-9_\-\.~' .'!\$&\'\(\)\*\+,;=' .'%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/';
            $uri .= "#" . preg_replace_callback($regex, $replace, $this->getFragment());
        }

        return $uri;
    }
750536
function loadCRL($crl)
    {
        $asn1 = new File_ASN1();

        $temp = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $csr);
        $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false;
        if ($temp != false) {
            $crl = $temp;
        }
        $orig = $crl;

        if ($crl === false) {
            $this->currentCert = false;
            return false;
        }

        $asn1->loadOIDs($this->oids);
        $decoded = $asn1->decodeBER($crl);

        if (empty($decoded)) {
            $this->currentCert = false;
            return false;
        }

        $crl = $asn1->asn1map($decoded[0], $this->CertificateList);
        if (!isset($crl) || $crl === false) {
            $this->currentCert = false;
            return false;
        }

        $this->signatureSubject = substr($orig, $decoded[0]['content'][0]['start'], $decoded[0]['content'][0]['length']);

        $this->_mapInExtensions($crl, 'tbsCertList/crlExtensions', $asn1);
        $rclist = &$this->_subArray($crl,'tbsCertList/revokedCertificates');
        if (is_array($rclist)) {
            foreach ($rclist as $i => $extension) {
                $this->_mapInExtensions($rclist, "$i/crlEntryExtensions", $asn1);
            }
        }

        $this->currentKeyIdentifier = NULL;
        $this->currentCert = $crl;

        return $crl;
    }
52515
public function toJavaScript()
    {
        $lines = [];

        foreach (get_object_vars($this) as $key => $value) {
            if (!is_null($value)) {
                $line = $key . ": ";

                if ($key == 'version') {
                    $line .= 'new Version({ ' . $value->toJavaScript() . ' })';
                } elseif ($key == 'family') {
                    $line .= 'new Family({ ' . $value->toJavaScript() . ' })';
                } elseif ($key == 'using') {
                    $line .= 'new Using({ ' . $value->toJavaScript() . ' })';
                } else {
                    switch (gettype($value)) {
                        case 'boolean':
                            $line .= $value ? 'true' : 'false';
                            break;
                        case 'string':
                            $line .= '"' . addslashes($value) . '"';
                            break;
                        case 'integer':
                            $line .= $value;
                            break;
                    }
                }

                $lines[] = $line;
            }
        }

        return implode($lines, ", ");
    }
69583
public function toString($long = false)
    {
        if ($long) {
            $result = $this->longAddress;
        } else {
            if ($this->shortAddress === null) {
                if (strpos($this->longAddress, '0000:0000:0000:0000:0000:ffff:') === 0) {
                    $lastBytes = array_slice($this->getBytes(), -4);
                    $this->shortAddress = '::ffff:'.implode('.', $lastBytes);
                } else {
                    $chunks = array_map(
                        function ($word) {
                            return dechex($word);
                        },
                        $this->getWords()
                    );
                    $shortAddress = implode(':', $chunks);
                    $matches = null;
                    for ($i = 8; $i > 1; --$i) {
                        $search = '(?:^|:)'.rtrim(str_repeat('0:', $i), ':').'(?:$|:)';
                        if (preg_match('/^(.*?)'.$search.'(.*)$/', $shortAddress, $matches)) {
                            $shortAddress = $matches[1].'::'.$matches[2];
                            break;
                        }
                    }
                    $this->shortAddress = $shortAddress;
                }
            }
            $result = $this->shortAddress;
        }

        return $result;
    }
710473
public function parse($file, $use_include_path = true)
	{
		$this->getPathInfo($file, $use_include_path);

		$this->fopen($this->absolute_path, false);

		switch (strtolower($this->extension)) {
			case 'json':
				return json_decode($this->fileGetContents());

			case 'ini':
				return (object)parse_ini_string($this->fileGetContents(), true);

			case 'xml':
				return simplexml_load_string($this->fileGetContents());
			case 'csv':
				return $this->fileGetCSV();

			default:
				throw new \InvalidArgumentException(
					"{$this->extension} is not a supported extension."
				);
		}
	}
495138
public static function getMimeType(string $fullPathFile) : string
    {
        $mime_types = self::$arrMimeType;
        $ext = strtolower(self::getFilenameExtension($fullPathFile));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        $mimetype = self::getMimeTypeByMimeContentType($fullPathFile);
        if (isNotNullOrEmpty($mimetype)) {
            return $mimetype;
        }
        $mimetype = self::getMimeTypeByFinfo($fullPathFile);
        if (isNotNullOrEmpty($mimetype)) {
            return $mimetype;
        }
        return 'application/octet-stream';
    }
1175604
protected function _getUpdateFields($useSkipSaveFields = true)
    {
        $query = '';
        $useSeparator = false;

        foreach (array_keys($this->_aFieldNames) as $oneFieldName) {
            $longName = $this->_getFieldLongName($oneFieldName);
            $field = $this->$longName;

            if (!$this->checkFieldCanBeUpdated($oneFieldName)) {
                continue;
            }

            if (!$useSkipSaveFields || ($useSkipSaveFields && !in_array(strtolower($oneFieldName), $this->_aSkipSaveFields))) {
                $query .= (($useSeparator) ? ',' : '') . $oneFieldName . ' = ' . $this->_getUpdateFieldValue($oneFieldName, $field);
                $useSeparator = true;
            }
        }

        return $query;
    }
1132266
protected static function getPreferredFormat(string $accept): string
    {
        if (static::isCli()) {
            return 'plain';
        }

        $formats = [
            'json' => ['application/json'],
            'html' => ['text/html'],
            'xml' => ['text/xml'],
            'plain' => ['text/plain', 'text/css', 'text/javascript'],
        ];

        foreach ($formats as $format => $mimes) {
            foreach ($mimes as $mime) {
                if (stripos($accept, $mime) !== false) {
                    return $format;
                }
            }
        }

        return 'unknown';
    }
451839
public function loadConfigurations(IConfiguration $config, $configFolder, $usePrefix = false) {
        $diretory = new \DirectoryIterator($configFolder);
        foreach($diretory as $fileinfo) {
            if($fileinfo->isDot() ||
                    !$fileinfo->isFile() ||
                    !$fileinfo->isReadable() ||
                    substr($fileinfo->getFilename(), -strlen($this->extension), strlen($this->extension)) != $this->extension) {
                continue;
            }

            $prefix = "";
            if($usePrefix) {
                $prefix = substr($fileinfo->getFilename(), 0, -strlen($this->extension));
            }
            $config->loadFile($fileinfo->getPathname(), $prefix);
        }

        return $config;
    }
261641
public function hashToFieldValue($fieldValue, array $context = array())
    {
        $mimeType = '';
        $fileName = '';

        if ($fieldValue === null) {
            return new BinaryFileValue();
        } if (is_string($fieldValue)) {
            $filePath = $fieldValue;
        } else {
            $filePath = $fieldValue['path'];
            if (isset($fieldValue['filename'])) {
                $fileName = $fieldValue['filename'];
            }
            if (isset($fieldValue['mime_type'])) {
                $mimeType = $fieldValue['mime_type'];
            }
        }

        // default format: path is relative to the 'files' dir
        $realFilePath = dirname($context['path']) . '/files/' . $filePath;

        // but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well
        if (!is_file($realFilePath) && is_file($filePath)) {
            $realFilePath = $filePath;
        }

        return new BinaryFileValue(
            array(
                'path' => $realFilePath,
                'fileSize' => filesize($realFilePath),
                'fileName' => $fileName != '' ? $fileName : basename($realFilePath),
                'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath)
            )
        );
    }
408557
public function buildString(array $variables = [], bool $useExisting = true): string
    {
        if ($useExisting === true) {
            $variables = \array_merge($this->variables, $variables);
        }

        $tmp = [];
        foreach ($variables as $name => $val) {
            if ($val !== null) {
                $tmp[] = $name.'='.\urlencode((string)$val);
            }
        }

        $ret = '';
        if (\count($tmp) > 0) {
            $ret .= '?'.\implode('&', $tmp);
        }
        return $ret;
    }
1162736
public static function getDateFormat($noTime = false, $useTimezone = false, $useUtc = false)
    {
        // Do not use UTC time (Z) if timezone support is enabled.
        if ($useTimezone || !$useUtc) {
            return $noTime ? 'Ymd' : 'Ymd\THis';
        }

        return $noTime ? 'Ymd' : 'Ymd\THis\Z';
    }
639869
public function buildXML()
    {
        $xml = new EncodingRequest();

        $request = $xml->setDomQuery($this->client->getConfig('userid'), $this->client->getConfig('userkey'), $this->getName());

        foreach ($this->getOperation()->getParams() as $name => $arg) {

            if ($this->get($name) === true) {
                $request->appendChild($xml->createElement($name));
            } else {
                if (! is_null($this->get($name)) && $this->get($name) !== false) {

                    if (! is_array($this->get($name))) {
                        // Non Array Type - String, Integer, etc ..

                        $request->appendChild($xml->createElement($name, $this->get($name)));
                    } else {

                        if ($name == "source") {
                            // Build "Flat" Array to XML

                            foreach ($this->get($name) as $key => $value) {
                                $request->appendChild($xml->createElement($name, $value));
                            }
                        } else {
                            // Build Array to XML

                            $arrayRoot = $request->appendChild($xml->createElement($name));

                            foreach ($this->get($name) as $key => $value) {

                                if (! is_array($value)) {
                                    $arrayRoot->appendChild($xml->createElement($key, $value));
                                } else {
                                    if ($key == "destination") {
                                        // Build "Flat" Array to XML in a sub Element
                                        foreach ($value as $subValue) {
                                            $arrayRoot->appendChild($xml->createElement($key, $subValue));
                                        }
                                    } else {
                                        $arraySubRoot = $arrayRoot->appendChild($xml->createElement($key));

                                        foreach ($value as $subKey => $subValue) {
                                            $arraySubRoot->appendChild($xml->createElement($subKey, $subValue));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return $xml;
    }
213524
public function toXml($data = null, $structure = null, $basenode = null, $usecdata = null)
	{
		if ($data === null)
		{
			$data = $this->data;
		}

		if ($basenode === null)
		{
			$basenode = Arr::get($this->config, 'xml.basenode', 'xml');
		}

		if ($usecdata === null)
		{
			$usecdata = Arr::get($this->config, 'xml.usecdata', false);
		}

		if ($structure === null)
		{
			$structure = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$basenode />");
		}

		// Force it to be something useful
		if ( ! is_array($data) and ! is_object($data))
		{
			$data = (array) $data;
		}

		foreach ($data as $key => $value)
		{
			// replace anything not alpha numeric
			$key = preg_replace('/[^a-z_\-0-9]/i', '', $key);

			// no numeric keys in our xml please!
			if (is_numeric($key))
			{
				// make string key...
				$key = ($this->inflector->singularize($basenode) != $basenode) ? $this->inflector->singularize($basenode) : 'item';
			}

			// if there is another array found recrusively call this function
			if (is_array($value) or is_object($value))
			{
				$node = $structure->addChild($key);

				// recursive call if value is not empty
				if( ! empty($value))
				{
					$this->toXml($value, $node, $key, $usecdata);
				}
			}

			else
			{
				// add single node.
				$encoded = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');

				if ($usecdata and ($encoded !== (string) $value))
				{
					$dom = dom_import_simplexml($structure->addChild($key));
					$owner = $dom->ownerDocument;
					$dom->appendChild($owner->createCDATASection($value));
				}
				else
				{
					$structure->addChild($key, $encoded);
				}
			}
		}

		// pass back as string. or simple xml object if you want!
		return $structure->asXML();
	}