alex-kalanis /
remote-request-psr
| 1 | <?php |
||
| 2 | |||
| 3 | namespace kalanis\RemoteRequestPsr\Traits; |
||
| 4 | |||
| 5 | |||
| 6 | use Psr\Http\Message\MessageInterface; |
||
| 7 | use Psr\Http\Message\StreamInterface; |
||
| 8 | use RuntimeException; |
||
| 9 | |||
| 10 | |||
| 11 | /** |
||
| 12 | * Trait TBody |
||
| 13 | * @package kalanis\RemoteRequestPsr\Traits |
||
| 14 | * Note: Contrary the PSR requirements this class does not offer immutability |
||
| 15 | * That's because you need to change request properties before you set them to RemoteRequest |
||
| 16 | */ |
||
| 17 | trait TBody |
||
| 18 | { |
||
| 19 | protected ?StreamInterface $body = null; |
||
| 20 | |||
| 21 | 6 | public function getBody(): StreamInterface |
|
| 22 | { |
||
| 23 | 6 | if (empty($this->body)) { |
|
| 24 | 1 | throw new RuntimeException('You must set the body first!'); |
|
| 25 | } |
||
| 26 | 5 | return $this->body; |
|
| 27 | } |
||
| 28 | |||
| 29 | 5 | public function withBody(StreamInterface $body): MessageInterface |
|
| 30 | { |
||
| 31 | 5 | $this->body = $body; |
|
| 32 | 5 | return $this; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 33 | } |
||
| 34 | } |
||
| 35 |