1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RedMoon\TinkerServer\Shell; |
4
|
|
|
|
5
|
|
|
use Psy\Shell; |
6
|
|
|
use Psy\Exception\BreakException; |
7
|
|
|
use Psy\Exception\ErrorException; |
8
|
|
|
use Psy\CodeCleaner\NoReturnValue; |
9
|
|
|
use Psy\Exception\ThrowUpException; |
10
|
|
|
use Psy\Exception\TypeErrorException; |
11
|
|
|
use Psy\ExecutionClosure as BaseExecutionClosure; |
12
|
|
|
|
13
|
|
|
class ExecutionClosure extends BaseExecutionClosure |
14
|
|
|
{ |
15
|
|
|
public function __construct(Shell $__psysh__, $__line__) |
16
|
|
|
{ |
17
|
|
|
$this->setClosure($__psysh__, function () use ($__psysh__, $__line__) { |
18
|
|
|
try { |
19
|
|
|
try { |
20
|
|
|
// Restore execution scope variables |
21
|
|
|
\extract($__psysh__->getScopeVariables(false), EXTR_SKIP); |
|
|
|
|
22
|
|
|
|
23
|
|
|
$_ = new NoReturnValue(); |
24
|
|
|
|
25
|
|
|
$__psysh__->addCode($__line__); |
26
|
|
|
|
27
|
|
|
// Convert all errors to exceptions |
28
|
|
|
\set_error_handler([$__psysh__, 'handleError']); |
29
|
|
|
|
30
|
|
|
// Evaluate the current code buffer |
31
|
|
|
$_ = eval($__psysh__->onExecute($__psysh__->flushCode() ?: ExecutionClosure::NOOP_INPUT)); |
32
|
|
|
} catch (\Throwable $_e) { |
33
|
|
|
// Clean up on our way out. |
34
|
|
|
\restore_error_handler(); |
35
|
|
|
|
36
|
|
|
throw $_e; |
37
|
|
|
} catch (\Exception $_e) { |
38
|
|
|
// Clean up on our way out. |
39
|
|
|
\restore_error_handler(); |
40
|
|
|
|
41
|
|
|
throw $_e; |
42
|
|
|
} |
43
|
|
|
} catch (BreakException $_e) { |
44
|
|
|
$__psysh__->writeException($_e); |
45
|
|
|
|
46
|
|
|
return; |
47
|
|
|
} catch (ThrowUpException $_e) { |
48
|
|
|
$__psysh__->writeException($_e); |
49
|
|
|
|
50
|
|
|
throw $_e; |
51
|
|
|
} catch (\TypeError $_e) { |
52
|
|
|
$__psysh__->writeException(TypeErrorException::fromTypeError($_e)); |
53
|
|
|
} catch (\Error $_e) { |
54
|
|
|
$__psysh__->writeException(ErrorException::fromError($_e)); |
55
|
|
|
} catch (\Exception $_e) { |
56
|
|
|
$__psysh__->writeException($_e); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
\restore_error_handler(); |
60
|
|
|
|
61
|
|
|
$__psysh__->writeReturnValue($_); |
62
|
|
|
|
63
|
|
|
// Save execution scope variables for next time |
64
|
|
|
$__psysh__->setScopeVariables(\get_defined_vars()); |
65
|
|
|
|
66
|
|
|
return $_; |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|