forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptRunner.php
More file actions
58 lines (52 loc) · 1.46 KB
/
ScriptRunner.php
File metadata and controls
58 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace ProcessMaker\ScriptRunners;
use ProcessMaker\Exception\ScriptLanguageNotSupported;
use ProcessMaker\Models\ScriptExecutor;
class ScriptRunner
{
/**
* Concrete script runner
*
* @var \ProcessMaker\ScriptRunners\Base $runner
*/
private $runner;
public function __construct(ScriptExecutor $executor)
{
$this->runner = $this->getScriptRunner($executor);
}
/**
* Run a script code.
*
* @param string $code
* @param array $data
* @param array $config
* @param integer $timeout
* @param \ProcessMaker\Models\User $user
*
* @return array
* @throws \RuntimeException
*/
public function run($code, array $data, array $config, $timeout = 60, $user)
{
return $this->runner->run($code, $data, $config, $timeout, $user);
}
/**
* Get a runner instance from executor
*
* @param ScriptExecutor $executor
*
* @return \ProcessMaker\ScriptRunners\Base
* @throws \ProcessMaker\Exception\ScriptLanguageNotSupported
*/
private function getScriptRunner(ScriptExecutor $executor)
{
$language = strtolower($executor->language);
$runner = config("script-runners.{$language}.runner");
if (!$runner) {
throw new ScriptLanguageNotSupported($language);
} else {
$class = "ProcessMaker\\ScriptRunners\\{$runner}";
return new $class($executor);
}
}
}