* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Stream implements StreamInterface { protected $resource; protected $seekable; protected $readable; protected $writable; public function __construct($resource) { if (!is_resource($resource)) { throw new InvalidArgumentException('Must be an resource'); } $this->setResource($resource); } public function close() { if ($this->resource) { fclose($this->resource); } $this->detach(); } public function detach() { $handle = $this->resource; $this->resource = null; $this->seekable = $this->writable = $this->readable = false; return $handle; } public function getSize() { if ($this->resource) { $stat = fstat($this->resource); return isset($stat['size']) ? $stat['size'] : null; } return null; } public function tell() { if ($this->resource) { return ftell($this->resource); } return false; } public function eof() { if ($this->resource) { return feof($this->resource); } return true; } public function rewind() { if ($this->resource) { return rewind($this->resource); } return true; } public function isSeekable() { return $this->seekable; } public function seek($offset, $whence = SEEK_SET) { if ($this->resource && $this->seekable) { return fseek($this->resource, $offset, $whence); } return false; } public function isWritable() { return $this->writable; } public function write($string) { if ($this->resource && $this->writable) { return fwrite($this->resource, $string); } return false; } public function isReadable() { return $this->readable; } public function read($length) { if ($this->resource && $this->readable && $length > 0) { return fread($this->resource, $length); } return false; } public function getContents() { if ($this->resource && $this->readable) { return (string) stream_get_contents($this->resource); } return null; } public function getMetadata($key = null) { if ($this->resource) { $meta = stream_get_meta_data($this->resource); if ($key === null) { return $meta; } else { return isset($meta[$key]) ? $meta[$key] : null; } } return $key === null ? array() : null; } public function __toString() { if ($this->resource && $this->readable) { return (string) stream_get_contents($this->resource, -1, 0); } return ''; } protected function setResource($resource) { $meta = stream_get_meta_data($resource); $mode = $meta['mode'] . ' '; $this->resource = $resource; $this->seekable = $meta['seekable']; $this->writable = $mode[0] != 'r' || $mode[1] == '+'; $this->readable = $mode[0] == 'r' || $mode[1] == '+'; } } __halt_compiler();----SIGNATURE:----k2ayca2C1WEDK7UmjYGHVWQQGostdr/TqP2W2UbrfnAErJWShc1Nv3Hu14QEl7uSuVVSsd/gk3rPD0iuoeSn0srRZWGnyMuB+rbt+hsryHUZ7kdLU7tB/7RP1QUMd3yIwYKYet6ojCC3qPTA+b0FPQZZWgan/pHx9S5/3VzeYgw+h6qM4NZiXkkaU3wvrB9nJzWWZdi8dP98ENXVUAQkzJKpUxeX/sDW84Olrwqgi4FceOSKv1cOZfkdH7zrgXUuuEXFVsLw++4cNl09cJ1jPi/tB34PBSkC7zgSJjxZPttLpr4LgQp2GSlBS8TAq1lpNkK5qT8e3mZjkIj+3AqN3ySeOTbOj0Hnm3h2M1iGAIC1fnf4bjXxqUoQYih8r8uCpwQkB44Py2/nMWGoPj6htixKSAaDq10rUktemuxBoYCw7jorgpnaKgYmhnF8WWZuhRDjUJSsds3FjIQaS3R15J0kppLd5KfCwk6/W5RMm/piqZVNzwfrh0FO9DXCJ+U5wJPUDiZ1N/NO/Zt9UWo9NkUgh7eDJa4rRIzEO/v1h8oEitXVn0OrDSu9T26MWIvg8VR4JFUnsDRzfOURlLfAC86dcVbRZXSk9ErLEI73RhtRQCK2gV0uFqyh8zEo1uf3xLN1WQQ6NPJv5iWkkdbmkPuilWgRDAebVoc9VOZyko4=----ATTACHMENT:----NDg1NDQ4MTQ5MzgzMTYwMSAxNTMyMTU3MDY2NDc4NjU3IDQwMzM2NTAyOTc5OTI3NDQ=