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
|
|
|
/** |
16
|
|
|
* ExecutionClosure constructor. |
17
|
|
|
* |
18
|
|
|
* @param Shell $__psysh__ |
19
|
|
|
* @param [type] $__line__ |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public function __construct(Shell $__psysh__, $__line__) |
22
|
|
|
{ |
23
|
|
|
$this->setClosure($__psysh__, function () use ($__psysh__, $__line__) { |
24
|
|
|
try { |
25
|
|
|
try { |
26
|
|
|
// Restore execution scope variables |
27
|
|
|
\extract($__psysh__->getScopeVariables(false), EXTR_SKIP); |
|
|
|
|
28
|
|
|
$_ = new NoReturnValue(); |
29
|
|
|
$__psysh__->addCode($__line__); |
30
|
|
|
// Convert all errors to exceptions |
31
|
|
|
\set_error_handler([$__psysh__, 'handleError']); |
32
|
|
|
// Evaluate the current code buffer |
33
|
|
|
$_ = eval($__psysh__->onExecute($__psysh__->flushCode() ?: self::NOOP_INPUT)); |
34
|
|
|
} catch (\Throwable $_e) { |
35
|
|
|
// Clean up on our way out. |
36
|
|
|
\restore_error_handler(); |
37
|
|
|
|
38
|
|
|
throw $_e; |
39
|
|
|
} catch (\Exception $_e) { |
40
|
|
|
// Clean up on our way out. |
41
|
|
|
\restore_error_handler(); |
42
|
|
|
|
43
|
|
|
throw $_e; |
44
|
|
|
} |
45
|
|
|
} catch (BreakException $_e) { |
46
|
|
|
$__psysh__->writeException($_e); |
47
|
|
|
|
48
|
|
|
return; |
49
|
|
|
} catch (ThrowUpException $_e) { |
50
|
|
|
$__psysh__->writeException($_e); |
51
|
|
|
|
52
|
|
|
throw $_e; |
53
|
|
|
} catch (\TypeError $_e) { |
54
|
|
|
$__psysh__->writeException(TypeErrorException::fromTypeError($_e)); |
55
|
|
|
} catch (\Error $_e) { |
56
|
|
|
$__psysh__->writeException(ErrorException::fromError($_e)); |
57
|
|
|
} catch (\Exception $_e) { |
58
|
|
|
$__psysh__->writeException($_e); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
\restore_error_handler(); |
62
|
|
|
$__psysh__->writeReturnValue($_); |
63
|
|
|
// Save execution scope variables for next time |
64
|
|
|
$__psysh__->setScopeVariables(\get_defined_vars()); |
65
|
|
|
|
66
|
|
|
return $_; |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.