Debian Codegraph @

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

raw
1 <?php
2
3 namespace Shellbox\Command;
4
5 use Shellbox\ShellboxError;
6
7 /**
8 * A BoxedExecutor for internal use by the Server.
9 *
10 * The Server reads input files directly from the multipart stream into the
11 * temporary directory. So regular input files do not need to be created, we
12 * only need to download the URL files. Similarly, output file destruction is
13 * deferred until after the response has been sent.
14 *
15 * @internal
16 */
17 class ServerBoxedExecutor extends LocalBoxedExecutor {
18 protected function createResult() {
19 return new ServerBoxedResult;
20 }
21
22 protected function createInputFiles( BoxedCommand $command ) {
23 $filesToDownload = [];
24 foreach ( $command->getInputFiles() as $boxedName => $file ) {
25 if ( $file instanceof InputFileFromUrl ) {
26 $filesToDownload[$boxedName] = $file;
27 }
28 }
29 if ( $filesToDownload ) {
30 $this->downloadFiles( $filesToDownload );
31 }
32 }
33
34 protected function collectOutputFiles( BoxedCommand $command, BoxedResult $result ) {
35 if ( !( $result instanceof ServerBoxedResult ) ) {
36 throw new ShellboxError( "Unexpected result class" );
37 }
38 $generatedFilesNames = [];
39 $filesToUpload = [];
40 foreach ( $this->findOutputFiles( $command, $result ) as $boxedName => $file ) {
41 if ( $file instanceof OutputFileToUrl ) {
42 $filesToUpload[$boxedName] = $file;
43 }
44 $generatedFilesNames[] = $boxedName;
45 }
46
47 if ( $filesToUpload ) {
48 $this->uploadFiles( $filesToUpload );
49 }
50 $sentFileNames = array_diff( $generatedFilesNames, array_keys( $filesToUpload ) );
51 $result->setFileNames( $generatedFilesNames, $sentFileNames );
52 }
53
54 protected function cleanup() {
55 }
56 }