| 1 |
<?php |
| 2 |
|
| 3 |
namespace Shellbox\Command; |
| 4 |
|
| 5 |
use Shellbox\FileUtils; |
| 6 |
use Shellbox\Multipart\MultipartReader; |
| 7 |
|
| 8 |
/** |
| 9 |
* Encapsulation of an output file that is copied to a local file |
| 10 |
*/ |
| 11 |
class OutputFileToFile extends OutputFileWithContents { |
| 12 |
/** @var string */ |
| 13 |
private $path; |
| 14 |
|
| 15 |
/** |
| 16 |
* @internal |
| 17 |
* @param string $path |
| 18 |
*/ |
| 19 |
public function __construct( $path ) { |
| 20 |
$this->path = $path; |
| 21 |
} |
| 22 |
|
| 23 |
public function copyFromFile( $sourcePath ) { |
| 24 |
FileUtils::copy( $sourcePath, $this->path ); |
| 25 |
$this->setReceived(); |
| 26 |
} |
| 27 |
|
| 28 |
public function getContents() { |
| 29 |
return FileUtils::getContents( $this->path ); |
| 30 |
} |
| 31 |
|
| 32 |
public function readFromMultipart( MultipartReader $multipartReader ) { |
| 33 |
$multipartReader->copyPartToStream( FileUtils::openOutputFileStream( $this->path ) ); |
| 34 |
$this->setReceived(); |
| 35 |
} |
| 36 |
} |