Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
LuaSandboxCallback | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__call | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Scribunto\Engines\LuaSandbox; |
4 | |
5 | use LuaSandboxRuntimeError; |
6 | use MediaWiki\Extension\Scribunto\Engines\LuaCommon\LuaError; |
7 | |
8 | class LuaSandboxCallback { |
9 | |
10 | /** |
11 | * @var callable |
12 | */ |
13 | protected $callback; |
14 | |
15 | /** |
16 | * @param callable $callback |
17 | */ |
18 | public function __construct( $callback ) { |
19 | $this->callback = $callback; |
20 | } |
21 | |
22 | /** |
23 | * We use __call with a variable function name so that LuaSandbox will be |
24 | * able to return a meaningful function name in profiling data. |
25 | * @param string $funcName |
26 | * @param array $args |
27 | * @return mixed |
28 | */ |
29 | public function __call( $funcName, $args ) { |
30 | try { |
31 | return ( $this->callback )( ...$args ); |
32 | } catch ( LuaError $e ) { |
33 | throw new LuaSandboxRuntimeError( $e->getLuaMessage() ); |
34 | } |
35 | } |
36 | } |