コード例 #1
0
ファイル: php-shell-cmd.php プロジェクト: julpi/FreshCMS
/**
* the wrapper around the PHP_Shell class
*
* PHP Version 5
*
* - load extensions
* - set default error-handler
* - add exec-hooks for the extensions
*
* To keep the namespace clashing between shell and your program 
* as small as possible all public variables and functions from
* the shell are prefixed with __shell:
* 
* - $__shell is the object of the shell
*   can be read, this is the shell object itself, don't touch it
* - $__shell_retval is the return value of the eval() before 
*   it is printed
*   can't be read, but overwrites existing vars with this name
* - $__shell_exception is the catched Exception on Warnings, Notices, ..
*   can't be read, but overwrites existing vars with this name
*
* @category  Script
* @package   PHP_Shell
* @author    Jan Kneschke <*****@*****.**>
* @copyright 2006 Jan Kneschke
* @license   MIT <http://www.opensource.org/licenses/mit-license.php>
* @version   SVN: $id$
* @link      http://pear.php.net/package/PHP_Shell
*/
function __shell_print_var($variable, $verbose = false, $indent = 0)
{
    $output = "";
    // case 1: null
    if (is_null($variable)) {
        $output = "null";
        // case 2: boolean
    } elseif (is_bool($variable)) {
        $output = true === $variable ? "true" : "false";
        // case 3: object
    } elseif (is_object($variable)) {
        // class breadcrumbs
        $parent = $variable;
        $output .= get_class($variable);
        while ($parent = get_parent_class($parent)) {
            $output .= " < " . $parent;
        }
        $output .= ' ';
        // print properties if can be converted to array (ad hoc or through get_object_vars)
        if (method_exists($variable, 'toArray')) {
            $output .= __shell_print_var($variable->toArray(), true, $indent);
        } elseif (method_exists($variable, '__toArray')) {
            $output .= __shell_print_var($variable->__toArray(), true, $indent);
        } else {
            $output .= __shell_print_var(get_object_vars($variable), true, $indent);
        }
        // case 4: array
    } elseif (is_array($variable)) {
        if (empty($variable)) {
            $output .= "{";
            $output .= "}";
        } else {
            $output .= "{\n";
            foreach ($variable as $k => $v) {
                $output .= str_repeat(" ", $indent + 2) . $k . ' => ' . __shell_print_var($v, true, $indent + 2) . "\n";
            }
            $output .= str_repeat(" ", $indent) . "}";
        }
        // fallback: print_r php function (better than var_dump due to native support for string output and than var_export that fails on recursive dependencies)
    } else {
        $output .= print_r($variable, true);
    }
    if ($indent == 0 && $verbose == false) {
        echo "=> " . $output;
    } else {
        return $output;
    }
}
コード例 #2
0
         include_once str_replace('_', '/', $classname) . '.php';
         if ($__shell_exts->autoload_debug->isAutoloadDebug()) {
             print str_repeat(".", $__shell_exts->autoload_debug->decAutoloadDepth()) . " <- autoloading {$classname}" . PHP_EOL;
         }
     }
 }
 try {
     $__shell_exts->exectime->startParseTime();
     if ($__shell->parse() == 0) {
         ## we have a full command, execute it
         $__shell_exts->exectime->startExecTime();
         $__shell_retval = eval($__shell->getCode());
         if (isset($__shell_retval)) {
             print $__shell_exts->colour->getColour("value");
             if (function_exists("__shell_print_var")) {
                 __shell_print_var($__shell_retval, $__shell_exts->verboseprint->isVerbose());
             } else {
                 var_export($__shell_retval);
             }
         }
         ## cleanup the variable namespace
         unset($__shell_retval);
         $__shell->resetCode();
     }
 } catch (Exception $__shell_exception) {
     print $__shell_exts->colour->getColour("exception");
     printf('%s (code: %d) got thrown' . PHP_EOL, get_class($__shell_exception), $__shell_exception->getCode());
     print $__shell_exception;
     $__shell->resetCode();
     ## cleanup the variable namespace
     unset($__shell_exception);
コード例 #3
0
ファイル: php_shell.php プロジェクト: phpontrax/trax
              *
              * you can set your own autoloader by defining __autoload() before including
              * this file
              * 
              * @param string $classname name of the class
              */
             function __autoload($classname)
             {
                 include str_replace('_', '/', $classname) . '.php';
             }
         }
         $__shell_retval = eval($__shell->getCode());
         if (isset($__shell_retval)) {
             print $__shell->getColour("value");
             if (function_exists("__shell_print_var")) {
                 __shell_print_var($__shell_retval, $__shell->getVerbose());
             } else {
                 if (is_object($__shell_retval) && method_exists($__shell_retval, '__toString')) {
                     echo "Class:" . get_class($__shell_retval) . "\n" . $__shell_retval->__toString();
                 } else {
                     var_export($__shell_retval);
                 }
             }
         }
         ## cleanup the variable namespace
         unset($__shell_retval);
         $__shell->resetCode();
     }
 } catch (Exception $__shell_exception) {
     print $__shell->getColour("exception");
     print $__shell_exception->getMessage();