Beispiel #1
0
 /**
  * Generates a new raw SHA-1 hash signature for a Sqon file manager.
  *
  * @param FileInterface $file   The Sqon file manager.
  * @param boolean       $signed The Sqon has a signature?
  *
  * @return string The new raw SHA-1 hash.
  */
 public function generate(FileInterface $file, $signed = false)
 {
     $context = hash_init('sha1');
     $bytes = 0;
     if ($signed) {
         $bytes = $file->size() - 20;
     }
     $file->seek(0);
     foreach ($file->iterate($bytes) as $buffer) {
         hash_update($context, $buffer);
     }
     return hash_final($context, true);
 }
Beispiel #2
0
 /**
  * Returns the size of the Sqon.
  *
  * @return integer The size of the Sqon.
  */
 private function getSize()
 {
     if (null === $this->size) {
         $position = $this->file->tell();
         $this->size = $this->file->size();
         $this->file->seek($position);
     }
     return $this->size;
 }
Beispiel #3
0
 /**
  * Writes the contents of the Sqon.
  *
  * @param FileInterface $sqon      The Sqon file manager.
  * @param FileInterface $bootstrap The PHP bootstrap script file manager.
  * @param FileInterface $database  The database file manager.
  */
 public function write(FileInterface $sqon, FileInterface $bootstrap, FileInterface $database)
 {
     $sqon->stream($bootstrap);
     $sqon->stream($database);
     $sqon->seek(0);
     $sqon->write((new Signature())->generate($sqon));
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function stream(FileInterface $file, $bytes = 0, $buffer = 1024)
 {
     foreach ($file->iterate($bytes, $buffer) as $chunk) {
         $this->write($chunk);
     }
 }