Debian Codegraph @

vendor/wikimedia/shellbox/src/Action/CallAction.php

raw
1 <?php
2
3 namespace Shellbox\Action;
4
5 /**
6 * PHP RPC handler
7 */
8 class CallAction extends MultipartAction {
9 /**
10 * @param string[] $pathParts @phan-unused-param
11 */
12 protected function execute( $pathParts ) {
13 $this->forgetConfig( 'secretKey' );
14
15 $functionName = $this->getRequiredParam( 'functionName' );
16 $binary = $this->getRequiredParam( 'binary' );
17 if ( $binary ) {
18 $params = [];
19 for ( $i = 0; ; $i++ ) {
20 $param = $this->getParam( "param$i" );
21 if ( $param === null ) {
22 break;
23 }
24 $params[] = $param;
25 }
26 } else {
27 $params = $this->getParam( 'params', [] );
28 }
29 $this->runSources();
30 $result = call_user_func_array( $functionName, $params );
31
32 if ( $binary ) {
33 $this->writeResult( [], [ 'returnValue' => (string)$result ] );
34 } else {
35 $this->writeResult( [ 'returnValue' => $result ] );
36 }
37 }
38
39 protected function getActionName() {
40 return 'call';
41 }
42
43 /**
44 * Execute the source files which were included in the request
45 */
46 private function runSources() {
47 $sources = $this->getParam( 'sources', [] );
48 foreach ( $sources as $sourceFileName ) {
49 require $this->tempDirManager->getPath( $sourceFileName );
50 }
51 }
52 }