src/CFPropertyList/CFPropertyList.php
public function save($file = null, $format = null, $formatted_xml = false)
    {
        $file = $file ? $file : $this->file;
        $format = $format ? $format : $this->format;
        if ($format == self::FORMAT_AUTO) {
            $format = $this->detectedFormat;
        }

        if (!in_array($format, array( self::FORMAT_BINARY, self::FORMAT_XML ))) {
            throw new PListException("format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML");
        }

        if (!file_exists($file)) {
          // dirname("file.xml") == "" and is treated as the current working directory
            if (!is_writable(dirname($file))) {
                throw IOException::notWritable($file);
            }
        } elseif (!is_writable($file)) {
            throw IOException::notWritable($file);
        }

        $content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML($formatted_xml);

        $fh = fopen($file, 'wb');
        fwrite($fh, $content);
        fclose($fh);
    }
public function save($file = null, $format = null, $formatted_xml = false)
    {
        $file = $file ? $file : $this->file;
        $format = $format ? $format : $this->format;
        if ($format == self::FORMAT_AUTO) {
            $format = $this->detectedFormat;
        }

        if (!in_array($format, array( self::FORMAT_BINARY, self::FORMAT_XML ))) {
            throw new PListException("format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML");
        }

        if (!file_exists($file)) {
          // dirname("file.xml") == "" and is treated as the current working directory
            if (!is_writable(dirname($file))) {
                throw IOException::notWritable($file);
            }
        } elseif (!is_writable($file)) {
            throw IOException::notWritable($file);
        }

        $content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML($formatted_xml);

        $fh = fopen($file, 'wb');
        fwrite($fh, $content);
        fclose($fh);
    }
public function save ( $ file = null , $ format = null , $ formatted_xml = false ) { $ file = $ file ? $ file : $ this -> file ; $ format = $ format ? $ format : $ this -> format ; if ( $ format == self :: FORMAT_AUTO ) { $ format = $ this -> detectedFormat ; } if ( ! in_array ( $ format , array ( self :: FORMAT_BINARY , self :: FORMAT_XML ) ) ) { throw new PListException ( "format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML" ) ; } if ( ! file_exists ( $ file ) ) { // dirname("file.xml") == "" and is treated as the current working directory if ( ! is_writable ( dirname ( $ file ) ) ) { throw IOException :: notWritable ( $ file ) ; } } elseif ( ! is_writable ( $ file ) ) { throw IOException :: notWritable ( $ file ) ; } $ content = $ format == self :: FORMAT_BINARY ? $ this -> toBinary ( ) : $ this -> toXML ( $ formatted_xml ) ; $ fh = fopen ( $ file , 'wb' ) ; fwrite ( $ fh , $ content ) ; fclose ( $ fh ) ; }
Convert CFPropertyList to XML or binary and save to file.
@param string $file Path of PropertyList, defaults to {@link $file}
@param string $format Format of PropertyList, defaults to {@link $format}
@param bool $formatted_xml Print XML plist formatted (i.e. with newlines and whitespace indention) if true; defaults to false
@return void
@throws IOException if file could not be read
@throws PListException if evaluated $format is neither {@link FORMAT_XML} nor {@link FORMAL_BINARY}
@uses $file if $file was not specified
@uses $format if $format was not specified
Convert CFPropertyList to XML or binary and save to file .