| 1 |
<?php |
| 2 |
|
| 3 |
namespace Shellbox\Command; |
| 4 |
|
| 5 |
use Shellbox\ShellboxError; |
| 6 |
|
| 7 |
/** |
| 8 |
* The base class for input files |
| 9 |
*/ |
| 10 |
abstract class InputFile { |
| 11 |
use UserDataTrait; |
| 12 |
|
| 13 |
/** |
| 14 |
* Get data for JSON serialization by the client. |
| 15 |
* |
| 16 |
* @internal |
| 17 |
* @return array |
| 18 |
*/ |
| 19 |
public function getClientData() { |
| 20 |
return []; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Get an InputFile object to represent a file already created by the server. |
| 25 |
* |
| 26 |
* @internal |
| 27 |
* @param array $data |
| 28 |
* @return InputFile |
| 29 |
*/ |
| 30 |
public static function newFromClientData( $data ) { |
| 31 |
if ( ( $data['type'] ?? '' ) === 'url' ) { |
| 32 |
if ( !isset( $data['url'] ) ) { |
| 33 |
throw new ShellboxError( 'Missing required parameter for URL file: "url"' ); |
| 34 |
} |
| 35 |
$file = new InputFileFromUrl( $data['url'] ); |
| 36 |
if ( isset( $data['headers'] ) ) { |
| 37 |
$file->headers( $data['headers'] ); |
| 38 |
} |
| 39 |
return $file; |
| 40 |
} |
| 41 |
return new InputFilePlaceholder; |
| 42 |
} |
| 43 |
} |