private function transformToXml($data = [], $hypertextRoutes = [], $depth = 0)
     {
        // Set the xml string
        $xml = '';

        // Starting depth, so add the xml starting lines
        if ($depth === 0) {
            $xml = "<?xml version=\"1.0\"?>\n";
            $xml .= "<response>\n";
        }

        // Check if data is an array. If not, return a response with data to string.
        if (!is_array($data)) {
            return "<?xml version=\"1.0\"?>\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>";
        }

        // Loop through the data
        foreach ($data as $k => $v) {
            // Add tabs
            for ($i = 0; $i < $depth; $i++) {
                $xml .= "\t";
            }

            // Check if key is a number.
            // - XML doesn't allow <number></number> tags.
            $key = $k;
            if (is_int($k) || (int)$k > 0) {
                $key = "key_{$k}";
            }

            // Check if the value is an array. If so, generate xml for it.
            if (is_array($v)) {
                $xml .= "<{$key}>\n{$this->transformToXml($v, [], $depth+1)}\n</{$key}>\n";
            } else {
                $xml .= "<{$key}>{$v}</{$key}>\n";
            }
        }

        // Add the closing tag if this is depth 0
        if ($depth === 0) {
            $xml .= $this->getHypertextXml($hypertextRoutes);
            $xml .= "</response>\n";
        }

        // Return the xml string
        return $xml;
    }
private function transformToXml($data = [], $hypertextRoutes = [], $depth = 0)
     {
        // Set the xml string
        $xml = '';

        // Starting depth, so add the xml starting lines
        if ($depth === 0) {
            $xml = "<?xml version=\"1.0\"?>\n";
            $xml .= "<response>\n";
        }

        // Check if data is an array. If not, return a response with data to string.
        if (!is_array($data)) {
            return "<?xml version=\"1.0\"?>\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>";
        }

        // Loop through the data
        foreach ($data as $k => $v) {
            // Add tabs
            for ($i = 0; $i < $depth; $i++) {
                $xml .= "\t";
            }

            // Check if key is a number.
            // - XML doesn't allow <number></number> tags.
            $key = $k;
            if (is_int($k) || (int)$k > 0) {
                $key = "key_{$k}";
            }

            // Check if the value is an array. If so, generate xml for it.
            if (is_array($v)) {
                $xml .= "<{$key}>\n{$this->transformToXml($v, [], $depth+1)}\n</{$key}>\n";
            } else {
                $xml .= "<{$key}>{$v}</{$key}>\n";
            }
        }

        // Add the closing tag if this is depth 0
        if ($depth === 0) {
            $xml .= $this->getHypertextXml($hypertextRoutes);
            $xml .= "</response>\n";
        }

        // Return the xml string
        return $xml;
    }
private function transformToXml ( $ data = [ ] , $ hypertextRoutes = [ ] , $ depth = 0 ) { // Set the xml string $ xml = '' ; // Starting depth, so add the xml starting lines if ( $ depth === 0 ) { $ xml = "<?xml version=\"1.0\"?>\n" ; $ xml .= "<response>\n" ; } // Check if data is an array. If not, return a response with data to string. if ( ! is_array ( $ data ) ) { return "<?xml version=\"1.0\"?>\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>" ; } // Loop through the data foreach ( $ data as $ k => $ v ) { // Add tabs for ( $ i = 0 ; $ i < $ depth ; $ i ++ ) { $ xml .= "\t" ; } // Check if key is a number. // - XML doesn't allow <number></number> tags. $ key = $ k ; if ( is_int ( $ k ) || ( int ) $ k > 0 ) { $ key = "key_{$k}" ; } // Check if the value is an array. If so, generate xml for it. if ( is_array ( $ v ) ) { $ xml .= "<{$key}>\n{$this->transformToXml($v, [], $depth+1)}\n</{$key}>\n" ; } else { $ xml .= "<{$key}>{$v}</{$key}>\n" ; } } // Add the closing tag if this is depth 0 if ( $ depth === 0 ) { $ xml .= $ this -> getHypertextXml ( $ hypertextRoutes ) ; $ xml .= "</response>\n" ; } // Return the xml string return $ xml ; }
Recursively converts the response into an xml string.

@param mixed $data The data to transform.
@param optional array $hypertextRoutes An array with hypertext routes.

@return string The response as an xml string.
Recursively converts the response into an xml string .