public function __construct($message = null, $code = 0, \Exception $previous = null, $path = null)
 {
     if (null === $message) {
         if (null === $path) {
             $message = 'File could not be found.';
         } else {
             $message = sprintf('File "%s" could not be found.', $path);
         }
     }
     parent::__construct($message, $code, $previous, $path);
 }
 /**
  * Read a binary plist file
  * @param string $file The file to read
  * @return void
  * @throws IOException if read error occurs
  */
 function readBinary($file)
 {
     $this->uniqueTable = array();
     $this->countObjects = 0;
     $this->stringSize = 0;
     $this->intSize = 0;
     $this->miscSize = 0;
     $this->objectRefs = 0;
     $this->writtenObjectCount = 0;
     $this->objectTable = array();
     $this->objectRefSize = 0;
     $this->offsets = array();
     $fd = fopen($file, "rb");
     // first, we read the trailer: 32 byte from the end
     fseek($fd, -32, SEEK_END);
     $buff = fread($fd, 32);
     $infos = unpack("x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset", $buff);
     // after that, get the offset table
     fseek($fd, $infos['table_offset'], SEEK_SET);
     $coded_offset_table = fread($fd, $infos['number_of_objects'] * $infos['offset_size']);
     if (strlen($coded_offset_table) != $infos['number_of_objects'] * $infos['offset_size']) {
         throw IOException::readError($file);
     }
     $this->countObjects = $infos['number_of_objects'];
     // decode offset table
     $formats = array("", "C*", "n*", "(H6)*", "N*");
     $this->offsets = unpack($formats[$infos['offset_size']], $coded_offset_table);
     if ($infos['offset_size'] == 3) {
         foreach ($this->offsets as $k => $v) {
             $this->offsets[$k] = hexdec($v);
         }
     }
     $this->uniqueTable = array();
     $this->objectRefSize = $infos['object_ref_size'];
     $top = $this->readBinaryObjectAt($file, $fd, $infos['top_object'] + 1);
     $this->add($top);
     fclose($fd);
 }
 /**
  * Parse a binary plist string
  * @return void
  * @throws IOException if read error occurs
  */
 public function parseBinaryString()
 {
     $this->uniqueTable = array();
     $this->countObjects = 0;
     $this->stringSize = 0;
     $this->intSize = 0;
     $this->miscSize = 0;
     $this->objectRefs = 0;
     $this->writtenObjectCount = 0;
     $this->objectTable = array();
     $this->objectRefSize = 0;
     $this->offsets = array();
     // first, we read the trailer: 32 byte from the end
     $buff = substr($this->content, -32);
     if (strlen($buff) < 32) {
         throw new PListException('Error in PList format: content is less than at least necessary 32 bytes!');
     }
     $infos = unpack("x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset", $buff);
     // after that, get the offset table
     $coded_offset_table = substr($this->content, $infos['table_offset'], $infos['number_of_objects'] * $infos['offset_size']);
     if (strlen($coded_offset_table) != $infos['number_of_objects'] * $infos['offset_size']) {
         throw IOException::readError("");
     }
     $this->countObjects = $infos['number_of_objects'];
     // decode offset table
     $formats = array("", "C*", "n*", NULL, "N*");
     if ($infos['offset_size'] == 3) {
         # since PHP does not support parenthesis in pack/unpack expressions,
         # "(H6)*" does not work and we have to work round this by repeating the
         # expression as often as it fits in the string
         $this->offsets = array(NULL);
         while ($coded_offset_table) {
             $str = unpack("H6", $coded_offset_table);
             $this->offsets[] = hexdec($str[1]);
             $coded_offset_table = substr($coded_offset_table, 3);
         }
     } else {
         $this->offsets = unpack($formats[$infos['offset_size']], $coded_offset_table);
     }
     $this->uniqueTable = array();
     $this->objectRefSize = $infos['object_ref_size'];
     $top = $this->readBinaryObjectAt($infos['top_object'] + 1);
     $this->add($top);
 }
Exemple #4
0
 /**
  * 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}
  * @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
  */
 public function save($file = null, $format = null)
 {
     $file = $file ? $file : $this->file;
     $format = $format ? $format : $this->format;
     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);
         }
     } else {
         if (!is_writable($file)) {
             throw IOException::notWritable($file);
         }
     }
     $content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML();
     $fh = fopen($file, 'wb');
     fwrite($fh, $content);
     fclose($fh);
 }
Exemple #5
0
 function __construct(Socket $socket)
 {
     parent::__construct($socket, 'Can\'t write to socket');
 }
 public function parseBinaryString()
 {
     $this->uniqueTable = array();
     $this->countObjects = 0;
     $this->stringSize = 0;
     $this->intSize = 0;
     $this->miscSize = 0;
     $this->objectRefs = 0;
     $this->writtenObjectCount = 0;
     $this->objectTable = array();
     $this->objectRefSize = 0;
     $this->offsets = array();
     $buff = substr($this->content, -32);
     $infos = unpack("x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset", $buff);
     $coded_offset_table = substr($this->content, $infos['table_offset'], $infos['number_of_objects'] * $infos['offset_size']);
     if (strlen($coded_offset_table) != $infos['number_of_objects'] * $infos['offset_size']) {
         throw IOException::readError("");
     }
     $this->countObjects = $infos['number_of_objects'];
     $formats = array("", "C*", "n*", NULL, "N*");
     if ($infos['offset_size'] == 3) {
         $this->offsets = array(NULL);
         while ($coded_offset_table) {
             $str = unpack("H6", $coded_offset_table);
             $this->offsets[] = hexdec($str[1]);
             $coded_offset_table = substr($coded_offset_table, 3);
         }
     } else {
         $this->offsets = unpack($formats[$infos['offset_size']], $coded_offset_table);
     }
     $this->uniqueTable = array();
     $this->objectRefSize = $infos['object_ref_size'];
     $top = $this->readBinaryObjectAt($infos['top_object'] + 1);
     $this->add($top);
 }
 public function __construct($url, $message)
 {
     parent::__construct("[" . $url . "] " . $message);
 }
 /**
  * Constructor.
  *
  * @param string          $path
  * @param \Exception|null $previous
  */
 public function __construct($path, \Exception $previous = null)
 {
     parent::__construct('File already exists at path: ' . $path, $path, 0, $previous);
 }
Exemple #9
0
 function __construct(Socket $socket)
 {
     parent::__construct($socket, 'Can\'t read from socket');
 }
 /**
  * Constructor.
  *
  * @param string     $path
  * @param \Exception $previous
  */
 public function __construct($path, \Exception $previous = null)
 {
     parent::__construct('Failed to create directory: ' . $path, $path, 0, $previous);
 }
 /**
  * Constructor.
  *
  * @param string          $path
  * @param \Exception|null $previous
  */
 public function __construct($path, \Exception $previous = null)
 {
     parent::__construct('File not found at path: ' . $path, $path, 0, $previous);
 }