[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * This file is part of the POMO package. 5 */ 6 7 namespace POMO\Streams; 8 9 /** 10 * Provides file-like methods for manipulating a string instead 11 * of a physical file. 12 */ 13 class StringReader extends Reader implements StreamInterface 14 { 15 public $_str = ''; 16 17 public function __construct($str = '') 18 { 19 parent::__construct(); 20 $this->_str = $str; 21 $this->_pos = 0; 22 } 23 24 /** 25 * @param string $bytes 26 * @return string 27 */ 28 public function read($bytes) 29 { 30 $data = $this->substr($this->_str, $this->_pos, $bytes); 31 $this->_pos += $bytes; 32 if ($this->strlen($this->_str) < $this->_pos) { 33 $this->_pos = $this->strlen($this->_str); 34 } 35 return $data; 36 } 37 38 /** 39 * @param int $pos 40 * @return int 41 */ 42 public function seekto($pos) 43 { 44 $this->_pos = $pos; 45 if ($this->strlen($this->_str) < $this->_pos) { 46 $this->_pos = $this->strlen($this->_str); 47 } 48 return $this->_pos; 49 } 50 51 /** 52 * @return int 53 */ 54 public function length() 55 { 56 return $this->strlen($this->_str); 57 } 58 59 /** 60 * @return string 61 */ 62 public function read_all() 63 { 64 return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str)); 65 } 66 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Nov 9 05:10:01 2024 | Cross-referenced by PHPXref 0.7.1 |