4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
14 use Psy\Exception\ErrorException;
17 * The Psy Shell execution loop.
22 * Run the execution loop.
24 * @throws ThrowUpException if thrown by the `throw-up` command
28 public function run(Shell $shell)
30 $this->loadIncludes($shell);
32 $closure = new ExecutionLoopClosure($shell);
37 * Load user-defined includes.
41 protected function loadIncludes(Shell $shell)
43 // Load user-defined includes
44 $load = function (Shell $__psysh__) {
45 set_error_handler([$__psysh__, 'handleError']);
46 foreach ($__psysh__->getIncludes() as $__psysh_include__) {
48 include $__psysh_include__;
49 } catch (\Error $_e) {
50 $__psysh__->writeException(ErrorException::fromError($_e));
51 } catch (\Exception $_e) {
52 $__psysh__->writeException($_e);
55 restore_error_handler();
56 unset($__psysh_include__);
58 // Override any new local variables with pre-defined scope variables
59 extract($__psysh__->getScopeVariables(false));
61 // ... then add the whole mess of variables back.
62 $__psysh__->setScopeVariables(get_defined_vars());