Created
September 11, 2018 17:56
-
-
Save rodmcnew/afe93fa819871011efd5aed28d8ab765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class KeepAliveStream implements \Psr\Http\Message\StreamInterface | |
{ | |
protected $doneMessage; | |
protected $keepAliveMessage; | |
protected $isDone = false; | |
public function __construct($keepAliveMessage = '.', $doneMessage = 'Done.') | |
{ | |
$this->doneMessage = $doneMessage; | |
$this->keepAliveMessage = $keepAliveMessage; | |
} | |
public function __toString() | |
{ | |
return '__toString() not supported by ' . __CLASS__; | |
} | |
public function close() | |
{ | |
//nothing needed | |
} | |
public function detach() | |
{ | |
return null; | |
} | |
public function getSize() | |
{ | |
return null; | |
} | |
public function tell() | |
{ | |
return null; | |
} | |
public function eof() | |
{ | |
return $this->isDone; | |
} | |
public function isSeekable() | |
{ | |
return false; | |
} | |
public function seek($offset, $whence = SEEK_SET) | |
{ | |
// TODO: Implement seek() method. | |
} | |
public function rewind() | |
{ | |
// TODO: Implement rewind() method. | |
} | |
public function isWritable() | |
{ | |
return false; | |
} | |
public function write($string) | |
{ | |
throw new \Exception('Writing not supported by ' . __CLASS__); | |
} | |
public function isReadable() | |
{ | |
return true; | |
} | |
public function read($length) | |
{ | |
throw new Exception('hello'); | |
return $this->isDone ? $this->doneMessage : $this->keepAliveMessage; | |
} | |
public function getContents() | |
{ | |
return '__getContents() not supported by ' . __CLASS__; | |
} | |
public function getMetadata($key = null) | |
{ | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment