Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/ExecutionClosure.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
26 public function __construct(Shell $__psysh__) | 26 public function __construct(Shell $__psysh__) |
27 { | 27 { |
28 $this->setClosure($__psysh__, function () use ($__psysh__) { | 28 $this->setClosure($__psysh__, function () use ($__psysh__) { |
29 try { | 29 try { |
30 // Restore execution scope variables | 30 // Restore execution scope variables |
31 extract($__psysh__->getScopeVariables(false)); | 31 \extract($__psysh__->getScopeVariables(false)); |
32 | 32 |
33 // Buffer stdout; we'll need it later | 33 // Buffer stdout; we'll need it later |
34 ob_start([$__psysh__, 'writeStdout'], 1); | 34 \ob_start([$__psysh__, 'writeStdout'], 1); |
35 | 35 |
36 // Convert all errors to exceptions | 36 // Convert all errors to exceptions |
37 set_error_handler([$__psysh__, 'handleError']); | 37 \set_error_handler([$__psysh__, 'handleError']); |
38 | 38 |
39 // Evaluate the current code buffer | 39 // Evaluate the current code buffer |
40 $_ = eval($__psysh__->onExecute($__psysh__->flushCode() ?: ExecutionClosure::NOOP_INPUT)); | 40 $_ = eval($__psysh__->onExecute($__psysh__->flushCode() ?: ExecutionClosure::NOOP_INPUT)); |
41 } catch (\Throwable $_e) { | 41 } catch (\Throwable $_e) { |
42 // Clean up on our way out. | 42 // Clean up on our way out. |
43 restore_error_handler(); | 43 \restore_error_handler(); |
44 if (ob_get_level() > 0) { | 44 if (\ob_get_level() > 0) { |
45 ob_end_clean(); | 45 \ob_end_clean(); |
46 } | 46 } |
47 | 47 |
48 throw $_e; | 48 throw $_e; |
49 } catch (\Exception $_e) { | 49 } catch (\Exception $_e) { |
50 // Clean up on our way out. | 50 // Clean up on our way out. |
51 restore_error_handler(); | 51 \restore_error_handler(); |
52 if (ob_get_level() > 0) { | 52 if (\ob_get_level() > 0) { |
53 ob_end_clean(); | 53 \ob_end_clean(); |
54 } | 54 } |
55 | 55 |
56 throw $_e; | 56 throw $_e; |
57 } | 57 } |
58 | 58 |
59 // Won't be needing this anymore | 59 // Won't be needing this anymore |
60 restore_error_handler(); | 60 \restore_error_handler(); |
61 | 61 |
62 // Flush stdout (write to shell output, plus save to magic variable) | 62 // Flush stdout (write to shell output, plus save to magic variable) |
63 ob_end_flush(); | 63 \ob_end_flush(); |
64 | 64 |
65 // Save execution scope variables for next time | 65 // Save execution scope variables for next time |
66 $__psysh__->setScopeVariables(get_defined_vars()); | 66 $__psysh__->setScopeVariables(\get_defined_vars()); |
67 | 67 |
68 return $_; | 68 return $_; |
69 }); | 69 }); |
70 } | 70 } |
71 | 71 |
77 */ | 77 */ |
78 protected function setClosure(Shell $shell, \Closure $closure) | 78 protected function setClosure(Shell $shell, \Closure $closure) |
79 { | 79 { |
80 if (self::shouldBindClosure()) { | 80 if (self::shouldBindClosure()) { |
81 $that = $shell->getBoundObject(); | 81 $that = $shell->getBoundObject(); |
82 if (is_object($that)) { | 82 if (\is_object($that)) { |
83 $closure = $closure->bindTo($that, get_class($that)); | 83 $closure = $closure->bindTo($that, \get_class($that)); |
84 } else { | 84 } else { |
85 $closure = $closure->bindTo(null, $shell->getBoundClass()); | 85 $closure = $closure->bindTo(null, $shell->getBoundClass()); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
108 */ | 108 */ |
109 protected static function shouldBindClosure() | 109 protected static function shouldBindClosure() |
110 { | 110 { |
111 // skip binding on HHVM < 3.5.0 | 111 // skip binding on HHVM < 3.5.0 |
112 // see https://github.com/facebook/hhvm/issues/1203 | 112 // see https://github.com/facebook/hhvm/issues/1203 |
113 if (defined('HHVM_VERSION')) { | 113 if (\defined('HHVM_VERSION')) { |
114 return version_compare(HHVM_VERSION, '3.5.0', '>='); | 114 return \version_compare(HHVM_VERSION, '3.5.0', '>='); |
115 } | 115 } |
116 | 116 |
117 return true; | 117 return true; |
118 } | 118 } |
119 } | 119 } |