示例#1
0
 /**
  * Export the object as xml text, OR xml file.
  *
  * If the file extension is svgz, the function will save it correctely;
  *
  * @param string $filename the file to save, is optional, you can output to a var
  * @return string the xml string if filename is not passed
  */
 public function asXML($filename = null)
 {
     //if is svgz use compres.zlib to load the compacted SVG
     if (SVGDocument::getFileExtension($filename) == self::EXTENSION_COMPACT) {
         //verify if zlib is installed
         if (!function_exists('gzopen')) {
             throw new Exception('GZip support not installed.');
             return false;
         }
         $filename = 'compress.zlib://' . $filename;
     }
     $xml = parent::asXML(null);
     //need to do it, if pass a null filename it return an error
     if ($filename) {
         return file_put_contents($filename, $xml);
     }
     return $xml;
 }