Chris@0: getIncludes() as $__psysh_include__) { Chris@0: include $__psysh_include__; Chris@0: } Chris@0: } catch (\Exception $_e) { Chris@0: $__psysh__->writeException($_e); Chris@0: } Chris@0: restore_error_handler(); Chris@0: unset($__psysh_include__); Chris@0: Chris@0: extract($__psysh__->getScopeVariables(false)); Chris@0: Chris@0: do { Chris@0: $__psysh__->beforeLoop(); Chris@0: $__psysh__->setScopeVariables(get_defined_vars()); Chris@0: Chris@0: try { Chris@0: // read a line, see if we should eval Chris@0: $__psysh__->getInput(); Chris@0: Chris@0: // evaluate the current code buffer Chris@0: ob_start( Chris@0: array($__psysh__, 'writeStdout'), Chris@0: version_compare(PHP_VERSION, '5.4', '>=') ? 1 : 2 Chris@0: ); Chris@0: Chris@0: // Let PsySH inject some magic variables back into the Chris@0: // shell scope... things like $__class, and $__file set by Chris@0: // reflection commands Chris@0: extract($__psysh__->getSpecialScopeVariables(false)); Chris@0: Chris@0: // And unset any magic variables which are no longer needed Chris@0: foreach ($__psysh__->getUnusedCommandScopeVariableNames() as $__psysh_var_name__) { Chris@0: unset($$__psysh_var_name__, $__psysh_var_name__); Chris@0: } Chris@0: Chris@0: set_error_handler(array($__psysh__, 'handleError')); Chris@0: $_ = eval($__psysh__->flushCode() ?: Loop::NOOP_INPUT); Chris@0: restore_error_handler(); Chris@0: Chris@0: ob_end_flush(); Chris@0: Chris@0: $__psysh__->writeReturnValue($_); Chris@0: } catch (BreakException $_e) { Chris@0: restore_error_handler(); Chris@0: if (ob_get_level() > 0) { Chris@0: ob_end_clean(); Chris@0: } Chris@0: $__psysh__->writeException($_e); Chris@0: Chris@0: return; Chris@0: } catch (ThrowUpException $_e) { Chris@0: restore_error_handler(); Chris@0: if (ob_get_level() > 0) { Chris@0: ob_end_clean(); Chris@0: } Chris@0: $__psysh__->writeException($_e); Chris@0: Chris@0: throw $_e; Chris@0: } catch (\TypeError $_e) { Chris@0: restore_error_handler(); Chris@0: if (ob_get_level() > 0) { Chris@0: ob_end_clean(); Chris@0: } Chris@0: $__psysh__->writeException(TypeErrorException::fromTypeError($_e)); Chris@0: } catch (\Error $_e) { Chris@0: restore_error_handler(); Chris@0: if (ob_get_level() > 0) { Chris@0: ob_end_clean(); Chris@0: } Chris@0: $__psysh__->writeException(ErrorException::fromError($_e)); Chris@0: } catch (\Exception $_e) { Chris@0: restore_error_handler(); Chris@0: if (ob_get_level() > 0) { Chris@0: ob_end_clean(); Chris@0: } Chris@0: $__psysh__->writeException($_e); Chris@0: } Chris@0: Chris@0: $__psysh__->afterLoop(); Chris@0: } while (true); Chris@0: }; Chris@0: Chris@0: // bind the closure to $this from the shell scope variables... Chris@0: if (self::bindLoop()) { Chris@0: $that = $shell->getBoundObject(); Chris@0: if (is_object($that)) { Chris@0: $loop = $loop->bindTo($that, get_class($that)); Chris@0: } else { Chris@0: $loop = $loop->bindTo(null, null); Chris@0: } Chris@0: } Chris@0: Chris@0: $loop($shell); Chris@0: } Chris@0: Chris@0: /** Chris@0: * A beforeLoop callback. Chris@0: * Chris@0: * This is executed at the start of each loop iteration. In the default Chris@0: * (non-forking) loop implementation, this is a no-op. Chris@0: */ Chris@0: public function beforeLoop() Chris@0: { Chris@0: // no-op Chris@0: } Chris@0: Chris@0: /** Chris@0: * A afterLoop callback. Chris@0: * Chris@0: * This is executed at the end of each loop iteration. In the default Chris@0: * (non-forking) loop implementation, this is a no-op. Chris@0: */ Chris@0: public function afterLoop() Chris@0: { Chris@0: // no-op Chris@0: } Chris@0: Chris@0: /** Chris@0: * Decide whether to bind the execution loop. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: protected static function bindLoop() Chris@0: { Chris@0: // skip binding on HHVM <= 3.5.0 Chris@0: // see https://github.com/facebook/hhvm/issues/1203 Chris@0: if (defined('HHVM_VERSION')) { Chris@0: return version_compare(HHVM_VERSION, '3.5.0', '>='); Chris@0: } Chris@0: Chris@0: return version_compare(PHP_VERSION, '5.4', '>='); Chris@0: } Chris@0: }