| Total Complexity | 17 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Reader |
||
| 6 | { |
||
| 7 | protected $stream = null; |
||
| 8 | |||
| 9 | public function __construct($stream) |
||
| 10 | { |
||
| 11 | $this->stream = $stream; |
||
| 12 | } |
||
| 13 | public static function fromString($data) |
||
| 14 | { |
||
| 15 | $stream = fopen('php://temp', 'r+'); |
||
| 16 | if ($stream !== false) { |
||
| 17 | fwrite($stream, $data); |
||
| 18 | rewind($stream); |
||
| 19 | return new static($stream); |
||
| 20 | } |
||
| 21 | throw new ASN1Exception('Could not create temp stream'); |
||
| 22 | } |
||
| 23 | public static function fromFile($path) |
||
| 26 | } |
||
| 27 | |||
| 28 | public function pos() |
||
| 29 | { |
||
| 30 | return ftell($this->stream); |
||
| 31 | } |
||
| 32 | public function byte() |
||
| 33 | { |
||
| 34 | return $this->bytes(1); |
||
| 35 | } |
||
| 36 | public function bytes($amount = null) |
||
| 37 | { |
||
| 38 | if ($amount === null) { |
||
| 39 | $buff = ''; |
||
| 40 | while (!feof($this->stream)) { |
||
| 41 | $buff .= fread($this->stream, 4096); |
||
| 42 | } |
||
| 43 | return $buff; |
||
| 44 | } |
||
| 45 | return fread($this->stream, $amount); |
||
| 46 | } |
||
| 47 | public function readUntil($val, $include = true) |
||
| 48 | { |
||
| 49 | $tmp = ''; |
||
| 50 | while (!feof($this->stream)) { |
||
| 51 | $tmp .= $this->byte(); |
||
| 52 | if (substr($tmp, strlen($val) * -1) === $val) { |
||
| 53 | break; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | return $include ? $tmp : substr($tmp, 0, strlen($val) * -1); |
||
| 57 | } |
||
| 58 | public function chunk($beg = 0, $length = null) |
||
| 61 | } |
||
| 62 | |||
| 63 | public function eof() |
||
| 66 | } |
||
| 67 | public function seek($pos) |
||
| 71 | } |
||
| 72 | public function rewind() |
||
| 73 | { |
||
| 74 | rewind($this->stream); |
||
| 75 | return $this; |
||
| 76 | } |
||
| 77 | } |
||
| 78 |