src/CFPropertyList/CFPropertyList.php
public function load($file = null, $format = null)
    {
        $file = $file ? $file : $this->file;
        $format = $format !== null ? $format : $this->format;
        $this->value = array();

        if (!is_readable($file)) {
            throw IOException::notReadable($file);
        }

        switch ($format) {
            case CFPropertyList::FORMAT_BINARY:
                $this->readBinary($file);
                break;
            case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format
                $fd = fopen($file, "rb");
                if (($magic_number = fread($fd, 8)) === false) {
                    throw IOException::notReadable($file);
                }
                fclose($fd);

                $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->readBinary($file);
                    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->load($file)) {
                    $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 load($file = null, $format = null)
    {
        $file = $file ? $file : $this->file;
        $format = $format !== null ? $format : $this->format;
        $this->value = array();

        if (!is_readable($file)) {
            throw IOException::notReadable($file);
        }

        switch ($format) {
            case CFPropertyList::FORMAT_BINARY:
                $this->readBinary($file);
                break;
            case CFPropertyList::FORMAT_AUTO: // what we now do is ugly, but neccessary to recognize the file format
                $fd = fopen($file, "rb");
                if (($magic_number = fread($fd, 8)) === false) {
                    throw IOException::notReadable($file);
                }
                fclose($fd);

                $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->readBinary($file);
                    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->load($file)) {
                    $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 load ( $ file = null , $ format = null ) { $ file = $ file ? $ file : $ this -> file ; $ format = $ format !== null ? $ format : $ this -> format ; $ this -> value = array ( ) ; if ( ! is_readable ( $ file ) ) { throw IOException :: notReadable ( $ file ) ; } switch ( $ format ) { case CFPropertyList :: FORMAT_BINARY : $ this -> readBinary ( $ file ) ; break ; case CFPropertyList :: FORMAT_AUTO : // what we now do is ugly, but neccessary to recognize the file format $ fd = fopen ( $ file , "rb" ) ; if ( ( $ magic_number = fread ( $ fd , 8 ) ) === false ) { throw IOException :: notReadable ( $ file ) ; } fclose ( $ fd ) ; $ 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 -> readBinary ( $ file ) ; 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 -> load ( $ file ) ) { $ 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 ; } }
Load a plist file.
Load and import a plist file.
@param string $file Path of PropertyList, defaults to {@link $file}
@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 $file if argument $file was not specified
@uses $value reset to empty array
@uses import() for importing the values
Load a plist file . Load and import a plist file .