cryptal  latest
Cryptography Abstraction Layer
Hexify.php
1 <?php
2 
4 
5 class Hexify extends \php_user_filter
6 {
7  protected $uppercase;
8 
9  public function onCreate()
10  {
11  $this->uppercase = isset($this->params['uppercase']) ? (bool) $this->params['uppercase'] : false;
12  }
13 
14  public function filter($in, $out, &$consumed, $closing)
15  {
16  while ($bucket = stream_bucket_make_writeable($in)) {
17  $consumed += $bucket->datalen;
18  $output = bin2hex($bucket->data);
19 
20  if ($this->uppercase) {
21  $output = strtoupper($output);
22  }
23 
24  $outBucket = stream_bucket_new($this->stream, $output);
25  stream_bucket_append($out, $outBucket);
26  }
27  return PSFS_PASS_ON;
28  }
29 }