src/CFPropertyList/CFPropertyList.php
public function parse($str = null, $format = null)
    {
        $format = $format !== null ? $format : $this->format;
        $str = $str !== null ? $str : $this->content;
        if ($str === null || strlen($str) === 0) {
            throw IOException::readError('');
        }
        $this->value = array();

        switch ($format) {
            case CFPropertyList::FORMAT_BINARY:
                $this->parseBinary($str);
                break;
            case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format
                if (($magic_number = substr($str, 0, 8)) === false) {
                    throw IOException::notReadable("<string>");
                }

                $filetype = substr($magic_number, 0, 6);
                $version  = substr($magic_number, -2);

                if ($filetype == "bplist") {
                    if ($version != "00") {
                        throw new PListException("Wrong file format version! Expected 00, got $version!");
                    }
                    $this->detectedFormat = CFPropertyList::FORMAT_BINARY;
                    $this->parseBinary($str);
                    break;
                }
                $this->detectedFormat = CFPropertyList::FORMAT_XML;
              // else: xml format, break not neccessary
            case CFPropertyList::FORMAT_XML:
                $doc = new DOMDocument();
                $prevXmlErrors = libxml_use_internal_errors(true);
                libxml_clear_errors();
                if (!$doc->loadXML($str)) {
                    $message = $this->getLibxmlErrors();
                    libxml_clear_errors();
                    libxml_use_internal_errors($prevXmlErrors);
                    throw new DOMException($message);
                }
                libxml_use_internal_errors($prevXmlErrors);
                $this->import($doc->documentElement, $this);
                break;
        }
    }
public function parse($str = null, $format = null)
    {
        $format = $format !== null ? $format : $this->format;
        $str = $str !== null ? $str : $this->content;
        if ($str === null || strlen($str) === 0) {
            throw IOException::readError('');
        }
        $this->value = array();

        switch ($format) {
            case CFPropertyList::FORMAT_BINARY:
                $this->parseBinary($str);
                break;
            case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format
                if (($magic_number = substr($str, 0, 8)) === false) {
                    throw IOException::notReadable("<string>");
                }

                $filetype = substr($magic_number, 0, 6);
                $version  = substr($magic_number, -2);

                if ($filetype == "bplist") {
                    if ($version != "00") {
                        throw new PListException("Wrong file format version! Expected 00, got $version!");
                    }
                    $this->detectedFormat = CFPropertyList::FORMAT_BINARY;
                    $this->parseBinary($str);
                    break;
                }
                $this->detectedFormat = CFPropertyList::FORMAT_XML;
              // else: xml format, break not neccessary
            case CFPropertyList::FORMAT_XML:
                $doc = new DOMDocument();
                $prevXmlErrors = libxml_use_internal_errors(true);
                libxml_clear_errors();
                if (!$doc->loadXML($str)) {
                    $message = $this->getLibxmlErrors();
                    libxml_clear_errors();
                    libxml_use_internal_errors($prevXmlErrors);
                    throw new DOMException($message);
                }
                libxml_use_internal_errors($prevXmlErrors);
                $this->import($doc->documentElement, $this);
                break;
        }
    }
public function parse ( $ str = null , $ format = null ) { $ format = $ format !== null ? $ format : $ this -> format ; $ str = $ str !== null ? $ str : $ this -> content ; if ( $ str === null || strlen ( $ str ) === 0 ) { throw IOException :: readError ( '' ) ; } $ this -> value = array ( ) ; switch ( $ format ) { case CFPropertyList :: FORMAT_BINARY : $ this -> parseBinary ( $ str ) ; break ; case CFPropertyList :: FORMAT_AUTO : // what we now do is ugly, but neccessary to recognize the file format if ( ( $ magic_number = substr ( $ str , 0 , 8 ) ) === false ) { throw IOException :: notReadable ( "<string>" ) ; } $ filetype = substr ( $ magic_number , 0 , 6 ) ; $ version = substr ( $ magic_number , - 2 ) ; if ( $ filetype == "bplist" ) { if ( $ version != "00" ) { throw new PListException ( "Wrong file format version! Expected 00, got $version!" ) ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_BINARY ; $ this -> parseBinary ( $ str ) ; break ; } $ this -> detectedFormat = CFPropertyList :: FORMAT_XML ; // else: xml format, break not neccessary case CFPropertyList :: FORMAT_XML : $ doc = new DOMDocument ( ) ; $ prevXmlErrors = libxml_use_internal_errors ( true ) ; libxml_clear_errors ( ) ; if ( ! $ doc -> loadXML ( $ str ) ) { $ message = $ this -> getLibxmlErrors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ prevXmlErrors ) ; throw new DOMException ( $ message ) ; } libxml_use_internal_errors ( $ prevXmlErrors ) ; $ this -> import ( $ doc -> documentElement , $ this ) ; break ; } }
Parse a plist string.
Parse and import a plist string.
@param string $str String containing the PropertyList, defaults to {@link $content}
@param integer $format The format of the property list, see {@link FORMAT_XML}, {@link FORMAT_BINARY} and {@link FORMAT_AUTO}, defaults to {@link $format}
@return void
@throws PListException if file format version is not 00
@throws IOException if file could not be read
@throws DOMException if plist file could not be parsed properly
@uses $content if argument $str was not specified
@uses $value reset to empty array
@uses import() for importing the values
Parse a plist string . Parse and import a plist string .