Debian Codegraph @

vendor/wikimedia/shellbox/src/Command/OutputFileToStream.php

raw
1 <?php
2
3 namespace Shellbox\Command;
4
5 use GuzzleHttp\Psr7\Utils;
6 use Psr\Http\Message\StreamInterface;
7 use Shellbox\FileUtils;
8 use Shellbox\Multipart\MultipartReader;
9
10 /**
11 * Encapsulation of an output file that is copied to a stream
12 */
13 class OutputFileToStream extends OutputFileWithContents {
14 /** @var StreamInterface */
15 private $stream;
16
17 /**
18 * @internal
19 * @param StreamInterface $stream
20 */
21 public function __construct( StreamInterface $stream ) {
22 $this->stream = $stream;
23 }
24
25 public function copyFromFile( $sourcePath ) {
26 Utils::copyToStream( FileUtils::openInputFileStream( $sourcePath ), $this->stream );
27 $this->setReceived();
28 }
29
30 public function getContents() {
31 $this->stream->rewind();
32 return $this->stream->getContents();
33 }
34
35 public function readFromMultipart( MultipartReader $multipartReader ) {
36 $multipartReader->copyPartToStream( $this->stream );
37 $this->setReceived();
38 }
39 }