| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * (PHP 5) |
|---|
| 4 | * |
|---|
| 5 | * @package PHPonTrax |
|---|
| 6 | * @version $Id:$ |
|---|
| 7 | * @copyright (c) 2005 John Peterson |
|---|
| 8 | * |
|---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining |
|---|
| 10 | * a copy of this software and associated documentation files (the |
|---|
| 11 | * "Software"), to deal in the Software without restriction, including |
|---|
| 12 | * without limitation the rights to use, copy, modify, merge, publish, |
|---|
| 13 | * distribute, sublicense, and/or sell copies of the Software, and to |
|---|
| 14 | * permit persons to whom the Software is furnished to do so, subject to |
|---|
| 15 | * the following conditions: |
|---|
| 16 | * |
|---|
| 17 | * The above copyright notice and this permission notice shall be |
|---|
| 18 | * included in all copies or substantial portions of the Software. |
|---|
| 19 | * |
|---|
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|---|
| 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|---|
| 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|---|
| 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|---|
| 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|---|
| 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|---|
| 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | @ob_end_clean(); |
|---|
| 30 | error_reporting(E_ALL ^ E_NOTICE); |
|---|
| 31 | set_time_limit(0); |
|---|
| 32 | |
|---|
| 33 | require_once("php_shell/shell.php"); |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * default error-handler |
|---|
| 37 | * |
|---|
| 38 | * Instead of printing the NOTICE or WARNING from php we wan't the turn non-FATAL |
|---|
| 39 | * messages into exceptions and handle them in our own way. |
|---|
| 40 | * |
|---|
| 41 | * you can set your own error-handler by createing a function named |
|---|
| 42 | * __shell_error_handler |
|---|
| 43 | * |
|---|
| 44 | * @param integer $errno Error-Number |
|---|
| 45 | * @param string $errstr Error-Message |
|---|
| 46 | * @param string $errfile Filename where the error was raised |
|---|
| 47 | * @param interger $errline Line-Number in the File |
|---|
| 48 | * @param mixed $errctx ... |
|---|
| 49 | */ |
|---|
| 50 | function __shell_default_error_handler($errno, $errstr, $errfile, $errline, $errctx) { |
|---|
| 51 | ## ... what is this errno again ? |
|---|
| 52 | if ($errno == 2048 || $errno == 8) return; |
|---|
| 53 | throw new Exception(sprintf("%s:%d\r\n%s", $errfile, $errline, $errstr)); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | set_error_handler("__shell_default_error_handler"); |
|---|
| 57 | |
|---|
| 58 | $__shell = new PHP_Shell(); |
|---|
| 59 | |
|---|
| 60 | $f = <<<EOF |
|---|
| 61 | >> use '?' to open the inline help |
|---|
| 62 | EOF; |
|---|
| 63 | |
|---|
| 64 | printf($f, |
|---|
| 65 | $__shell->getVersion(), |
|---|
| 66 | $__shell->hasReadline() ? ', with readline() support' : ''); |
|---|
| 67 | unset($f); |
|---|
| 68 | |
|---|
| 69 | print $__shell->getColour("default"); |
|---|
| 70 | while($__shell->input()) { |
|---|
| 71 | try { |
|---|
| 72 | if ($__shell->parse() == 0) { |
|---|
| 73 | ## we have a full command, execute it |
|---|
| 74 | |
|---|
| 75 | if ($__shell->isAutoloadEnabled() && !function_exists('__autoload')) { |
|---|
| 76 | /** |
|---|
| 77 | * default autoloader |
|---|
| 78 | * |
|---|
| 79 | * If a class doesn't exist try to load it by guessing the filename |
|---|
| 80 | * class PHP_Shell should be located in PHP/Shell.php. |
|---|
| 81 | * |
|---|
| 82 | * you can set your own autoloader by defining __autoload() before including |
|---|
| 83 | * this file |
|---|
| 84 | * |
|---|
| 85 | * @param string $classname name of the class |
|---|
| 86 | */ |
|---|
| 87 | |
|---|
| 88 | function __autoload($classname) { |
|---|
| 89 | include str_replace('_', '/', $classname).'.php'; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | $__shell_retval = eval($__shell->getCode()); |
|---|
| 94 | if (isset($__shell_retval)) { |
|---|
| 95 | print $__shell->getColour("value"); |
|---|
| 96 | |
|---|
| 97 | if (function_exists("__shell_print_var")) { |
|---|
| 98 | __shell_print_var($__shell_retval, $__shell->getVerbose()); |
|---|
| 99 | } else { |
|---|
| 100 | if(is_object($__shell_retval) && method_exists($__shell_retval, '__toString')) { |
|---|
| 101 | echo "Class:".get_class($__shell_retval)."\n".$__shell_retval->__toString(); |
|---|
| 102 | } else { |
|---|
| 103 | var_export($__shell_retval); |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | ## cleanup the variable namespace |
|---|
| 108 | unset($__shell_retval); |
|---|
| 109 | $__shell->resetCode(); |
|---|
| 110 | } |
|---|
| 111 | } catch(Exception $__shell_exception) { |
|---|
| 112 | print $__shell->getColour("exception"); |
|---|
| 113 | print $__shell_exception->getMessage(); |
|---|
| 114 | |
|---|
| 115 | $__shell->resetCode(); |
|---|
| 116 | |
|---|
| 117 | ## cleanup the variable namespace |
|---|
| 118 | unset($__shell_exception); |
|---|
| 119 | } |
|---|
| 120 | print $__shell->getColour("default"); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | print $__shell->getColour("reset"); |
|---|
| 124 | |
|---|
| 125 | ?> |
|---|