8 class Hash extends \php_user_filter
12 public function onCreate()
14 if (!isset($this->params[
'algorithm']) ||
15 !is_object($this->params[
'algorithm']) ||
16 !($this->params[
'algorithm'] instanceof
HashEnum)) {
17 throw new \InvalidArgumentException(
'Invalid algorithm');
20 $allowUnsafe = isset($this->params[
'allowUnsafe']) ? (bool) $this->params[
'allowUnsafe'] :
false;
21 $this->context = Registry::buildHash($this->params[
'algorithm'], $allowUnsafe);
25 public function filter($in, $out, &$consumed, $closing)
27 while ($bucket = stream_bucket_make_writeable($in)) {
28 $this->context->update($bucket->data);
29 $consumed += $bucket->datalen;
33 $bucket = stream_bucket_new($this->stream, $this->context->finalize(
true));
34 stream_bucket_append($out, $bucket);