-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_runner.php
68 lines (57 loc) · 1.11 KB
/
code_runner.php
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
59
60
61
62
63
64
65
66
67
68
<?php
require_once "php_process.php";
class CodeRunner {
/**
*
* @var string
*/
public $cwd = null;
/**
*
* @var resource
*/
protected $_process;
/**
*
*/
public function __construct() {
$this->cwd = dirname(__FILE__);
}
/**
* Runs some php code through php process
*
* @param string $code
* @return array
*/
public function run_code($code) {
return $this->_get_process()->run($code);
}
/**
* Returns PHP config path
*
* @return string
*/
public function get_config_path() {
return '/home/'. $this->_discover_username() .'/html/php/php.ini';
}
private function _discover_username() {
$cwd = __DIR__;
$username = 'wzalewski';
if(preg_match('@^/home/([^/]*)/@', $cwd, $match)){
$username = $match[1];
}
return $username;
}
/**
* Returns process class instance
*
* @return PHPProcess
*/
protected function _get_process() {
if(null == $this->_process) {
$this->_process = new PHPProcess($this->get_config_path(), $this->cwd, array());
}
return $this->_process;
}
}
?>