예제 #1
0
파일: Reader.php 프로젝트: sqon/sqon
 /**
  * Returns the size of the PHP bootstrap script.
  *
  * @return integer The size of the PHP bootstrap script.
  *
  * @throws ReaderException If the size could not be determined.
  */
 private function getBootstrapSize()
 {
     if (null === $this->bootstrapSize) {
         $position = $this->file->tell();
         $sequence = '__HALT_COMPILER();';
         $length = strlen($sequence);
         $offset = 0;
         $this->file->seek(0);
         /*
          * The purpose of iterating through the file is so that a pattern,
          * "__HALT_COMPILER();" can be found. Once this pattern is found,
          * the current position is used as the size of the PHP bootstrap
          * script. The problem is that this is very slow and can probably
          * be optimized in the future.
          */
         foreach ($this->file->iterate(0, 1) as $char) {
             if ($sequence[$offset] === $char) {
                 $offset++;
                 if ($offset === $length) {
                     $this->bootstrapSize = $this->file->tell();
                     break;
                 }
             } else {
                 $offset = 0;
             }
         }
         $this->file->seek($position);
         if (null === $this->bootstrapSize) {
             // @codeCoverageIgnoreStart
             throw new ReaderException('`__HALT_COMPILER();` is missing in the PHP bootstrap script.');
             // @codeCoverageIgnoreEnd
         }
     }
     return $this->bootstrapSize;
 }
예제 #2
0
파일: Signature.php 프로젝트: sqon/sqon
 /**
  * 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);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function stream(FileInterface $file, $bytes = 0, $buffer = 1024)
 {
     foreach ($file->iterate($bytes, $buffer) as $chunk) {
         $this->write($chunk);
     }
 }