Example #1
0
 /**
  * Signs the Phar using a private key file.
  *
  * @param string $file     The private key file name.
  * @param string $password The private key password.
  *
  * @throws Exception\Exception
  * @throws FileException If the private key file could not be read.
  */
 public function signUsingFile($file, $password = null)
 {
     if (false === is_file($file)) {
         throw FileException::create('The file "%s" does not exist or is not a file.', $file);
     }
     if (false === ($key = @file_get_contents($file))) {
         throw FileException::lastError();
     }
     $this->sign($key, $password);
 }
Example #2
0
 /**
  * Reads a number of bytes from the file.
  *
  * @param integer $bytes The number of bytes.
  *
  * @return string The read bytes.
  *
  * @throws Exception
  * @throws FileException If the file could not be read.
  */
 private function read($bytes)
 {
     if (false === ($read = @fread($this->handle(), $bytes))) {
         throw FileException::lastError();
     }
     if (($actual = strlen($read)) !== $bytes) {
         throw FileException::create('Only read %d of %d bytes from "%s".', $actual, $bytes, $this->file);
     }
     return $read;
 }