Esempio n. 1
0
 /**
  * serialize data
  *
  * @access   public
  * @param    mixed    $data data to serialize
  * @return   boolean  true on success, pear error on failure
  */
 function serialize($data, $options = null)
 {
     // if options have been specified, use them instead
     // of the previously defined ones
     if (is_array($options)) {
         $optionsBak = $this->options;
         if (isset($options['overrideOptions']) && $options['overrideOptions'] == true) {
             $this->options = array_merge($this->_defaultOptions, $options);
         } else {
             $this->options = array_merge($this->options, $options);
         }
     } else {
         $optionsBak = null;
     }
     //  start depth is zero
     $this->_tagDepth = 0;
     $this->_serializedData = '';
     // serialize an array
     if (is_array($data)) {
         if (isset($this->options['rootName'])) {
             $tagName = $this->options['rootName'];
         } else {
             $tagName = 'array';
         }
         $this->_serializedData .= $this->_serializeArray($data, $tagName, $this->options['rootAttributes']);
     }
     // add doctype declaration
     if ($this->options['addDoctype'] === true) {
         $this->_serializedData = PEAR_PackageFile_Generator_v2_XML_Util::getDoctypeDeclaration($tagName, $this->options['doctype']) . $this->options['linebreak'] . $this->_serializedData;
     }
     //  build xml declaration
     if ($this->options['addDecl']) {
         $atts = array();
         if (isset($this->options['encoding'])) {
             $encoding = $this->options['encoding'];
         } else {
             $encoding = null;
         }
         $this->_serializedData = PEAR_PackageFile_Generator_v2_XML_Util::getXMLDeclaration('1.0', $encoding) . $this->options['linebreak'] . $this->_serializedData;
     }
     if ($optionsBak !== null) {
         $this->options = $optionsBak;
     }
     return true;
 }