| 1 |
<?php |
| 2 |
|
| 3 |
namespace React\Http\Io; |
| 4 |
|
| 5 |
use Evenement\EventEmitter; |
| 6 |
use Psr\Http\Message\StreamInterface; |
| 7 |
use React\Stream\ReadableStreamInterface; |
| 8 |
use React\Stream\Util; |
| 9 |
use React\Stream\WritableStreamInterface; |
| 10 |
|
| 11 |
/** |
| 12 |
* [Internal] Bridge between an empty StreamInterface from PSR-7 and ReadableStreamInterface from ReactPHP |
| 13 |
* |
| 14 |
* This class is used in the server to represent an empty body stream of an |
| 15 |
* incoming response from the client. This is similar to the `HttpBodyStream`, |
| 16 |
* but is specifically designed for the common case of having an empty message |
| 17 |
* body. |
| 18 |
* |
| 19 |
* Note that this is an internal class only and nothing you should usually care |
| 20 |
* about. See the `StreamInterface` and `ReadableStreamInterface` for more |
| 21 |
* details. |
| 22 |
* |
| 23 |
* @see HttpBodyStream |
| 24 |
* @see StreamInterface |
| 25 |
* @see ReadableStreamInterface |
| 26 |
* @internal |
| 27 |
*/ |
| 28 |
class EmptyBodyStream extends EventEmitter implements StreamInterface, ReadableStreamInterface |
| 29 |
{ |
| 30 |
private $closed = false; |
| 31 |
|
| 32 |
public function isReadable() |
| 33 |
{ |
| 34 |
return !$this->closed; |
| 35 |
} |
| 36 |
|
| 37 |
public function pause() |
| 38 |
{ |
| 39 |
// NOOP |
| 40 |
} |
| 41 |
|
| 42 |
public function resume() |
| 43 |
{ |
| 44 |
// NOOP |
| 45 |
} |
| 46 |
|
| 47 |
public function pipe(WritableStreamInterface $dest, array $options = array()) |
| 48 |
{ |
| 49 |
Util::pipe($this, $dest, $options); |
| 50 |
|
| 51 |
return $dest; |
| 52 |
} |
| 53 |
|
| 54 |
public function close() |
| 55 |
{ |
| 56 |
if ($this->closed) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$this->closed = true; |
| 61 |
|
| 62 |
$this->emit('close'); |
| 63 |
$this->removeAllListeners(); |
| 64 |
} |
| 65 |
|
| 66 |
public function getSize() |
| 67 |
{ |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
/** @ignore */ |
| 72 |
public function __toString() |
| 73 |
{ |
| 74 |
return ''; |
| 75 |
} |
| 76 |
|
| 77 |
/** @ignore */ |
| 78 |
public function detach() |
| 79 |
{ |
| 80 |
return null; |
| 81 |
} |
| 82 |
|
| 83 |
/** @ignore */ |
| 84 |
public function tell() |
| 85 |
{ |
| 86 |
throw new \BadMethodCallException(); |
| 87 |
} |
| 88 |
|
| 89 |
/** @ignore */ |
| 90 |
public function eof() |
| 91 |
{ |
| 92 |
throw new \BadMethodCallException(); |
| 93 |
} |
| 94 |
|
| 95 |
/** @ignore */ |
| 96 |
public function isSeekable() |
| 97 |
{ |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
/** @ignore */ |
| 102 |
public function seek($offset, $whence = SEEK_SET) |
| 103 |
{ |
| 104 |
throw new \BadMethodCallException(); |
| 105 |
} |
| 106 |
|
| 107 |
/** @ignore */ |
| 108 |
public function rewind() |
| 109 |
{ |
| 110 |
throw new \BadMethodCallException(); |
| 111 |
} |
| 112 |
|
| 113 |
/** @ignore */ |
| 114 |
public function isWritable() |
| 115 |
{ |
| 116 |
return false; |
| 117 |
} |
| 118 |
|
| 119 |
/** @ignore */ |
| 120 |
public function write($string) |
| 121 |
{ |
| 122 |
throw new \BadMethodCallException(); |
| 123 |
} |
| 124 |
|
| 125 |
/** @ignore */ |
| 126 |
public function read($length) |
| 127 |
{ |
| 128 |
throw new \BadMethodCallException(); |
| 129 |
} |
| 130 |
|
| 131 |
/** @ignore */ |
| 132 |
public function getContents() |
| 133 |
{ |
| 134 |
return ''; |
| 135 |
} |
| 136 |
|
| 137 |
/** @ignore */ |
| 138 |
public function getMetadata($key = null) |
| 139 |
{ |
| 140 |
return ($key === null) ? array() : null; |
| 141 |
} |
| 142 |
} |