/** * Calculate a hash of a Stream * * @param StreamInterface $stream Stream to calculate the hash for * @param string $algo Hash algorithm (e.g. md5, crc32, etc) * @param bool $rawOutput Whether or not to use raw output * * @return bool|string Returns false on failure or a hash string on success */ public static function getHash(StreamInterface $stream, $algo, $rawOutput = false) { $pos = $stream->ftell(); if (!$stream->seek(0)) { return false; } $ctx = hash_init($algo); while ($data = $stream->read(8192)) { hash_update($ctx, $data); } $out = hash_final($ctx, (bool) $rawOutput); $stream->seek($pos); return $out; }
/** * Send HTTP response headers and body * * @return \Slim\Interfaces\Http\Response Self * @api */ public function send() { // Send headers if (headers_sent() === false) { if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', $this->getReasonPhrase())); } else { header(sprintf('%s %s', $this->getProtocolVersion(), $this->getReasonPhrase())); } foreach ($this->headers as $name => $value) { foreach ($value as $hVal) { header("{$name}: {$hVal}", false); } } } // Send body $this->body->seek(0); while ($this->body->feof() === false) { echo $this->body->read(1024); } return $this; }
/** * {@inheritdoc} */ protected function doRead($length) { return $this->stream->read($length); }