annotate vendor/psy/psysh/src/ExecutionLoop.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2018 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy;
Chris@0 13
Chris@0 14 use Psy\Exception\ErrorException;
Chris@0 15
Chris@0 16 /**
Chris@0 17 * The Psy Shell execution loop.
Chris@0 18 */
Chris@0 19 class ExecutionLoop
Chris@0 20 {
Chris@0 21 /**
Chris@0 22 * Run the execution loop.
Chris@0 23 *
Chris@0 24 * @throws ThrowUpException if thrown by the `throw-up` command
Chris@0 25 *
Chris@0 26 * @param Shell $shell
Chris@0 27 */
Chris@0 28 public function run(Shell $shell)
Chris@0 29 {
Chris@0 30 $this->loadIncludes($shell);
Chris@0 31
Chris@0 32 $closure = new ExecutionLoopClosure($shell);
Chris@0 33 $closure->execute();
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Load user-defined includes.
Chris@0 38 *
Chris@0 39 * @param Shell $shell
Chris@0 40 */
Chris@0 41 protected function loadIncludes(Shell $shell)
Chris@0 42 {
Chris@0 43 // Load user-defined includes
Chris@0 44 $load = function (Shell $__psysh__) {
Chris@0 45 set_error_handler([$__psysh__, 'handleError']);
Chris@0 46 foreach ($__psysh__->getIncludes() as $__psysh_include__) {
Chris@0 47 try {
Chris@0 48 include $__psysh_include__;
Chris@0 49 } catch (\Error $_e) {
Chris@0 50 $__psysh__->writeException(ErrorException::fromError($_e));
Chris@0 51 } catch (\Exception $_e) {
Chris@0 52 $__psysh__->writeException($_e);
Chris@0 53 }
Chris@0 54 }
Chris@0 55 restore_error_handler();
Chris@0 56 unset($__psysh_include__);
Chris@0 57
Chris@0 58 // Override any new local variables with pre-defined scope variables
Chris@0 59 extract($__psysh__->getScopeVariables(false));
Chris@0 60
Chris@0 61 // ... then add the whole mess of variables back.
Chris@0 62 $__psysh__->setScopeVariables(get_defined_vars());
Chris@0 63 };
Chris@0 64
Chris@0 65 $load($shell);
Chris@0 66 }
Chris@0 67 }