[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/3rdParty/PhpShell/ -> php-shell-cmd.php (source)

   1  <?php
   2  @ob_end_clean();
   3  error_reporting(E_ALL);
   4  set_time_limit(0);
   5  
   6  /**
   7  * the wrapper around the PHP_Shell class
   8  *
   9  * - load extensions
  10  * - set default error-handler
  11  * - add exec-hooks for the extensions
  12  *
  13  * To keep the namespace clashing between shell and your program
  14  * as small as possible all public variables and functions from
  15  * the shell are prefixed with __shell:
  16  *
  17  * - $__shell is the object of the shell
  18  *   can be read, this is the shell object itself, don't touch it
  19  * - $__shell_retval is the return value of the eval() before
  20  *   it is printed
  21  *   can't be read, but overwrites existing vars with this name
  22  * - $__shell_exception is the catched Exception on Warnings, Notices, ..
  23  *   can't be read, but overwrites existing vars with this name
  24  */
  25  
  26  //try loading it from PEAR
  27  @require_once ('PHP/Shell.php');
  28  if(class_exists('PHP_Shell', false))
  29  {
  30      require_once  "PHP/Shell/Extensions/Autoload.php";
  31      require_once  "PHP/Shell/Extensions/AutoloadDebug.php";
  32      require_once  "PHP/Shell/Extensions/Colour.php";
  33      require_once  "PHP/Shell/Extensions/ExecutionTime.php";
  34      require_once  "PHP/Shell/Extensions/InlineHelp.php";
  35      require_once  "PHP/Shell/Extensions/VerbosePrint.php";
  36      require_once  "PHP/Shell/Extensions/LoadScript.php";
  37  }
  38  else
  39  {
  40      require_once(dirname(__FILE__)."/PHP/Shell.php");
  41      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Autoload.php");
  42      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/AutoloadDebug.php");
  43      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/Colour.php");
  44      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/ExecutionTime.php");
  45      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/InlineHelp.php");
  46      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/VerbosePrint.php");
  47      require_once(dirname(__FILE__)."/PHP/Shell/Extensions/LoadScript.php");
  48  }
  49  
  50  /**
  51  * default error-handler
  52  *
  53  * Instead of printing the NOTICE or WARNING from php we wan't the turn non-FATAL
  54  * messages into exceptions and handle them in our own way.
  55  *
  56  * you can set your own error-handler by createing a function named
  57  * __shell_error_handler
  58  *
  59  * @param integer $errno Error-Number
  60  * @param string $errstr Error-Message
  61  * @param string $errfile Filename where the error was raised
  62  * @param interger $errline Line-Number in the File
  63  * @param mixed $errctx ...
  64  */
  65  function __shell_default_error_handler($errno, $errstr, $errfile, $errline, $errctx) {
  66      ## ... what is this errno again ?
  67      if ($errno == 2048) return;
  68  
  69      throw new Exception(sprintf("%s:%d\r\n%s", $errfile, $errline, $errstr));
  70  }
  71  
  72  set_error_handler("__shell_default_error_handler");
  73  
  74  $__shell = new PHP_Shell();
  75  $__shell_exts = PHP_Shell_Extensions::getInstance();
  76  $__shell_exts->registerExtensions(array(
  77      "options"        => PHP_Shell_Options::getInstance(), /* the :set command */
  78  
  79      "autoload"       => new PHP_Shell_Extensions_Autoload(),
  80      "autoload_debug" => new PHP_Shell_Extensions_AutoloadDebug(),
  81      "colour"         => new PHP_Shell_Extensions_Colour(),
  82      "exectime"       => new PHP_Shell_Extensions_ExecutionTime(),
  83      "inlinehelp"     => new PHP_Shell_Extensions_InlineHelp(),
  84      "verboseprint"   => new PHP_Shell_Extensions_VerbosePrint(),
  85      "loadscript"     => new PHP_Shell_Extensions_LoadScript()
  86  ));
  87  
  88  $f = <<<EOF
  89  PHP-Shell - Version %s%s
  90  (c) 2006, Jan Kneschke <jan@kneschke.de>
  91  
  92  >> use '?' to open the inline help
  93  
  94  EOF;
  95  
  96  printf($f,
  97      $__shell->getVersion(),
  98      $__shell->hasReadline() ? ', with readline() support' : '');
  99  unset($f);
 100  
 101  print $__shell_exts->colour->getColour("default");
 102  while($__shell->input()) {
 103      if ($__shell_exts->autoload->isAutoloadEnabled() && !function_exists('__autoload')) {
 104          /**
 105          * default autoloader
 106          *
 107          * If a class doesn't exist try to load it by guessing the filename
 108          * class PHP_Shell should be located in PHP/Shell.php.
 109          *
 110          * you can set your own autoloader by defining __autoload() before including
 111          * this file
 112          *
 113          * @param string $classname name of the class
 114          */
 115  
 116          function __autoload($classname) {
 117              global $__shell_exts;
 118  
 119              if ($__shell_exts->autoload_debug->isAutoloadDebug()) {
 120                  print str_repeat(".", $__shell_exts->autoload_debug->incAutoloadDepth())." -> autoloading $classname".PHP_EOL;
 121              }
 122              include_once str_replace('_', '/', $classname).'.php';
 123              if ($__shell_exts->autoload_debug->isAutoloadDebug()) {
 124                  print str_repeat(".", $__shell_exts->autoload_debug->decAutoloadDepth())." <- autoloading $classname".PHP_EOL;
 125              }
 126          }
 127      }
 128  
 129      try {
 130          $__shell_exts->exectime->startParseTime();
 131          if ($__shell->parse() == 0) {
 132              ## we have a full command, execute it
 133  
 134              $__shell_exts->exectime->startExecTime();
 135  
 136              $__shell_retval = eval($__shell->getCode());
 137              if (isset($__shell_retval)) {
 138                  print $__shell_exts->colour->getColour("value");
 139  
 140                  if (function_exists("__shell_print_var")) {
 141                      __shell_print_var($__shell,$__shell_retval, $__shell_exts->verboseprint->isVerbose());
 142                  } else {
 143                      var_export($__shell_retval);
 144                  }
 145              }
 146              ## cleanup the variable namespace
 147              unset($__shell_retval);
 148              $__shell->resetCode();
 149          }
 150      } catch(Exception $__shell_exception) {
 151          print $__shell_exts->colour->getColour("exception");
 152          printf('%s (code: %d) got thrown'.PHP_EOL, get_class($__shell_exception), $__shell_exception->getCode());
 153          print $__shell_exception;
 154  
 155          $__shell->resetCode();
 156  
 157          ## cleanup the variable namespace
 158          unset($__shell_exception);
 159      }
 160      print $__shell_exts->colour->getColour("default");
 161      $__shell_exts->exectime->stopTime();
 162      if ($__shell_exts->exectime->isShow()) {
 163          printf(" (parse: %.4fs, exec: %.4fs)",
 164              $__shell_exts->exectime->getParseTime(),
 165              $__shell_exts->exectime->getExecTime()
 166          );
 167      }
 168  }
 169  
 170  print $__shell_exts->colour->getColour("reset");
 171  


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7