| 1 |
<?php |
| 2 |
|
| 3 |
namespace Shellbox\Command; |
| 4 |
|
| 5 |
use Shellbox\FileUtils; |
| 6 |
use Shellbox\Multipart\MultipartReader; |
| 7 |
use Shellbox\ShellboxError; |
| 8 |
|
| 9 |
/** |
| 10 |
* Encapsulation of an output file that is read into a string |
| 11 |
*/ |
| 12 |
class OutputFileToString extends OutputFileWithContents { |
| 13 |
/** @var string */ |
| 14 |
private $contents; |
| 15 |
|
| 16 |
public function copyFromFile( $sourcePath ) { |
| 17 |
$this->contents = FileUtils::getContents( $sourcePath ); |
| 18 |
$this->setReceived(); |
| 19 |
} |
| 20 |
|
| 21 |
public function getContents() { |
| 22 |
if ( $this->contents === null ) { |
| 23 |
throw new ShellboxError( __METHOD__ . ' was called too early or ' . |
| 24 |
'on a non-existent file' ); |
| 25 |
} |
| 26 |
return $this->contents; |
| 27 |
} |
| 28 |
|
| 29 |
public function readFromMultipart( MultipartReader $multipartReader ) { |
| 30 |
$this->contents = $multipartReader->readPartAsString(); |
| 31 |
$this->setReceived(); |
| 32 |
} |
| 33 |
} |