Chris@13: loadIncludes($shell); Chris@13: Chris@16: $closure = new ExecutionLoopClosure($shell); Chris@16: $closure->execute(); Chris@13: } Chris@13: Chris@13: /** Chris@13: * Load user-defined includes. Chris@13: * Chris@13: * @param Shell $shell Chris@13: */ Chris@13: protected function loadIncludes(Shell $shell) Chris@13: { Chris@13: // Load user-defined includes Chris@13: $load = function (Shell $__psysh__) { Chris@17: \set_error_handler([$__psysh__, 'handleError']); Chris@13: foreach ($__psysh__->getIncludes() as $__psysh_include__) { Chris@13: try { Chris@13: include $__psysh_include__; Chris@13: } catch (\Error $_e) { Chris@13: $__psysh__->writeException(ErrorException::fromError($_e)); Chris@13: } catch (\Exception $_e) { Chris@13: $__psysh__->writeException($_e); Chris@13: } Chris@13: } Chris@17: \restore_error_handler(); Chris@13: unset($__psysh_include__); Chris@13: Chris@13: // Override any new local variables with pre-defined scope variables Chris@17: \extract($__psysh__->getScopeVariables(false)); Chris@13: Chris@13: // ... then add the whole mess of variables back. Chris@17: $__psysh__->setScopeVariables(\get_defined_vars()); Chris@13: }; Chris@13: Chris@13: $load($shell); Chris@13: } Chris@13: }