/** * 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)); }
/** * 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; }
/** * 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); }