Beispiel #1
0
 /**
  * Register a command
  * 
  * @return void
  */
 public function register()
 {
     $cmd = PHP_Shell_Commands::getInstance();
     $cmd->registerCommand('#^p #', $this, 'cmdPrint', 'p <var>', 'print the variable verbosly');
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption('verboseprint', $this, 'optSetVerbose');
 }
Beispiel #2
0
 public function register()
 {
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption("background", $this, "optSetBackground");
     $opt->registerOptionAlias("bg", "background");
     $this->registerColourScheme("plain", array("default" => "", "value" => "", "exception" => "", "reset" => ""));
     $this->registerColourScheme("dark", array("default" => self::C_YELLOW, "value" => self::C_WHITE, "exception" => self::C_PURPLE));
     $this->registerColourScheme("light", array("default" => self::C_BLACK, "value" => self::C_BLUE, "exception" => self::C_RED));
 }
Beispiel #3
0
 static function getInstance()
 {
     if (is_null(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
Beispiel #4
0
 public function register()
 {
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption("autoload", $this, "optSetAutoload");
     $opt->registerOptionAlias("al", "autoload");
 }
* @param string $errfile Filename where the error was raised
* @param interger $errline Line-Number in the File
* @param mixed $errctx ...
*/
function __shell_default_error_handler($errno, $errstr, $errfile, $errline, $errctx)
{
    ## ... what is this errno again ?
    if ($errno == 2048) {
        return;
    }
    throw new Exception(sprintf("%s:%d\r\n%s", $errfile, $errline, $errstr));
}
set_error_handler("__shell_default_error_handler");
$__shell = new PHP_Shell();
$__shell_exts = PHP_Shell_Extensions::getInstance();
$__shell_exts->registerExtensions(array("options" => PHP_Shell_Options::getInstance(), "autoload" => new PHP_Shell_Extensions_Autoload(), "autoload_debug" => new PHP_Shell_Extensions_AutoloadDebug(), "colour" => new PHP_Shell_Extensions_Colour(), "exectime" => new PHP_Shell_Extensions_ExecutionTime(), "inlinehelp" => new PHP_Shell_Extensions_InlineHelp(), "verboseprint" => new PHP_Shell_Extensions_VerbosePrint(), "loadscript" => new PHP_Shell_Extensions_LoadScript()));
$f = <<<EOF
PHP-Shell - Version %s%s
(c) 2006, Jan Kneschke <*****@*****.**>

>> use '?' to open the inline help 

EOF;
printf($f, $__shell->getVersion(), $__shell->hasReadline() ? ', with readline() support' : '');
unset($f);
print $__shell_exts->colour->getColour("default");
while ($__shell->input()) {
    if ($__shell_exts->autoload->isAutoloadEnabled() && !function_exists('__autoload')) {
        /**
         * default autoloader
         *
Beispiel #6
0
 public function register()
 {
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption("exectime", $this, "optSetExecTime");
 }
Beispiel #7
0
/**
 * a readline completion callback
 *
 * @param string  $str linebuffer
 * @param integer $pos position in linebuffer
 *
 * @return array list of possible matches
 */
function PHP_Shell_readlineComplete($str, $pos)
{
    $in = readline_info('line_buffer');
    /**
     * parse the line-buffer backwards to see if we have a
     * - constant
     * - function
     * - variable
     */
    $m = array();
    if (preg_match('#\\$([A-Za-z0-9_]+)->#', $in, $a)) {
        /* check for $o->... */
        $name = $a[1];
        if (isset($GLOBALS[$name]) && is_object($GLOBALS[$name])) {
            $c = get_class_methods($GLOBALS[$name]);
            foreach ($c as $v) {
                $m[] = $v . '(';
            }
            $c = get_class_vars(get_class($GLOBALS[$name]));
            foreach ($c as $k => $v) {
                $m[] = $k;
            }
            return $m;
        }
    } else {
        if (preg_match('#\\$([A-Za-z0-9_]+)\\[([^\\]]+)\\]->#', $in, $a)) {
            /* check for $o[...]->... */
            $name = $a[1];
            if (isset($GLOBALS[$name]) && is_array($GLOBALS[$name]) && isset($GLOBALS[$name][$a[2]])) {
                $c = get_class_methods($GLOBALS[$name][$a[2]]);
                foreach ($c as $v) {
                    $m[] = $v . '(';
                }
                $c = get_class_vars(get_class($GLOBALS[$name][$a[2]]));
                foreach ($c as $k => $v) {
                    $m[] = $k;
                }
                return $m;
            }
        } else {
            if (preg_match('#([A-Za-z0-9_]+)::#', $in, $a)) {
                /* check for Class:: */
                $name = $a[1];
                if (class_exists($name, false)) {
                    $c = get_class_methods($name);
                    foreach ($c as $v) {
                        $m[] = sprintf('%s::%s(', $name, $v);
                    }
                    $cl = new ReflectionClass($name);
                    $c = $cl->getConstants();
                    foreach ($c as $k => $v) {
                        $m[] = sprintf('%s::%s', $name, $k);
                    }
                    return $m;
                }
            } else {
                if (preg_match('#\\$([a-zA-Z]?[a-zA-Z0-9_]*)$#', $in)) {
                    $m = array_keys($GLOBALS);
                    return $m;
                } else {
                    if (preg_match('#new #', $in)) {
                        $c = get_declared_classes();
                        foreach ($c as $v) {
                            $m[] = $v . '(';
                        }
                        return $m;
                    } else {
                        if (preg_match('#^:set #', $in)) {
                            foreach (PHP_Shell_Options::getInstance()->getOptions() as $v) {
                                $m[] = $v;
                            }
                            return $m;
                        }
                    }
                }
            }
        }
    }
    $f = get_defined_functions();
    foreach ($f['internal'] as $v) {
        $m[] = $v . '(';
    }
    foreach ($f['user'] as $v) {
        $m[] = $v . '(';
    }
    $c = get_declared_classes();
    foreach ($c as $v) {
        $m[] = $v . '::';
    }
    $c = get_defined_constants();
    foreach ($c as $k => $v) {
        $m[] = $k;
    }
    /* taken from http://de3.php.net/manual/en/reserved.php */
    $m[] = 'abstract';
    $m[] = 'and';
    $m[] = 'array(';
    $m[] = 'as';
    $m[] = 'break';
    $m[] = 'case';
    $m[] = 'catch';
    $m[] = 'class';
    $m[] = 'const';
    $m[] = 'continue';
    $m[] = 'default';
    $m[] = 'die(';
    $m[] = 'do';
    $m[] = 'echo(';
    $m[] = 'else';
    $m[] = 'elseif';
    $m[] = 'empty(';
    $m[] = 'eval(';
    $m[] = 'exception';
    $m[] = 'extends';
    $m[] = 'exit(';
    $m[] = 'extends';
    $m[] = 'final';
    $m[] = 'for (';
    $m[] = 'foreach (';
    $m[] = 'function';
    $m[] = 'global';
    $m[] = 'if';
    $m[] = 'implements';
    $m[] = 'include "';
    $m[] = 'include_once "';
    $m[] = 'interface';
    $m[] = 'isset(';
    $m[] = 'list(';
    $m[] = 'new';
    $m[] = 'or';
    $m[] = 'print(';
    $m[] = 'private';
    $m[] = 'protected';
    $m[] = 'public';
    $m[] = 'require "';
    $m[] = 'require_once "';
    $m[] = 'return';
    $m[] = 'static';
    $m[] = 'switch (';
    $m[] = 'throw';
    $m[] = 'try';
    $m[] = 'unset(';
    $m[] = 'var';
    $m[] = 'while';
    $m[] = 'xor';
    $m[] = '__FILE__';
    $m[] = '__FUNCTION__';
    $m[] = '__CLASS__';
    $m[] = '__LINE__';
    $m[] = '__METHOD__';
    return $m;
}
Beispiel #8
0
 public function register()
 {
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption('autoloaddebug', $this, 'optSetAutoloadDebug');
 }
Beispiel #9
0
 /**
  * Register a command
  * 
  * @return void
  */
 public function register()
 {
     $opt = PHP_Shell_Options::getInstance();
     $opt->registerOption('echo', $this, 'optSetEcho');
 }