From 1e5f13b21b33b0d7ce86fe97ca145a3561433a7a Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 18 Sep 2006 22:57:16 +0000 Subject: Add an interactive php shell that loads Prado classes. --- .../PhpShell/PHP/Shell/Extensions/InlineHelp.php | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 framework/3rdParty/PhpShell/PHP/Shell/Extensions/InlineHelp.php (limited to 'framework/3rdParty/PhpShell/PHP/Shell/Extensions/InlineHelp.php') diff --git a/framework/3rdParty/PhpShell/PHP/Shell/Extensions/InlineHelp.php b/framework/3rdParty/PhpShell/PHP/Shell/Extensions/InlineHelp.php new file mode 100644 index 00000000..4449d1f4 --- /dev/null +++ b/framework/3rdParty/PhpShell/PHP/Shell/Extensions/InlineHelp.php @@ -0,0 +1,140 @@ +registerCommand('#^\? #', $this, 'cmdHelp', '? ', + 'show the DocComment a Class, Method or Function'.PHP_EOL. + ' e.g.: ? fopen(), ? PHP_Shell, ? $__shell'); + } + + /** + * handle the '?' commands + * + * With the help of the Reflection Class we extract the DocComments and display them + * For internal Functions we extract the prototype from the php source. + * + * ? Class::method() + * ? $obj->method() + * ? Class::property + * ? $obj::property + * ? Class + * ? $obj + * ? function() + * + * The license of the PHP_Shell class + * ? license + * + * @return string the help text + */ + public function cmdHelp($l) { + if ("? " == substr($l, 0, strlen("? "))) { + $str = substr($l, 2); + + $cmd = ''; + + if (preg_match('#^([A-Za-z0-9_]+)::([a-zA-Z0-9_]+)\(\s*\)\s*#', $str, $a)) { + /* ? Class::method() */ + + $class = $a[1]; + $method = $a[2]; + + if (false !== ($proto = PHP_ShellPrototypes::getInstance()->get($class.'::'.$method))) { + + $cmd = sprintf("/**\n* %s\n\n* @params %s\n* @return %s\n*/\n", + $proto['description'], + $proto['params'], + $proto['return'] + ); + } else if (class_exists($class, false)) { + $c = new ReflectionClass($class); + + if ($c->hasMethod($method)) { + $cmd = $c->getMethod($method)->getDocComment(); + } + } + } else if (preg_match('#^\$([A-Za-z0-9_]+)->([a-zA-Z0-9_]+)\(\s*\)\s*#', $str, $a)) { + /* ? $obj->method() */ + if (isset($GLOBALS[$a[1]]) && is_object($GLOBALS[$a[1]])) { + $class = get_class($GLOBALS[$a[1]]); + $method = $a[2]; + + $c = new ReflectionClass($class); + + if ($c->hasMethod($method)) { + $cmd = $c->getMethod($method)->getDocComment(); + } + } + } else if (preg_match('#^([A-Za-z0-9_]+)::([a-zA-Z0-9_]+)\s*$#', $str, $a)) { + /* ? Class::property */ + $class = $a[1]; + $property = $a[2]; + if (class_exists($class, false)) { + $c = new ReflectionClass($class); + + if ($c->hasProperty($property)) { + $cmd = $c->getProperty($property)->getDocComment(); + } + } + } else if (preg_match('#^\$([A-Za-z0-9_]+)->([a-zA-Z0-9_]+)\s*$#', $str, $a)) { + /* ? $obj->property */ + if (isset($GLOBALS[$a[1]]) && is_object($GLOBALS[$a[1]])) { + $class = get_class($GLOBALS[$a[1]]); + $method = $a[2]; + + $c = new ReflectionClass($class); + + if ($c->hasProperty($property)) { + $cmd = $c->getProperty($property)->getDocComment(); + } + + } + } else if (preg_match('#^([A-Za-z0-9_]+)$#', $str, $a)) { + /* ? Class */ + if (class_exists($a[1], false)) { + $c = new ReflectionClass($a[1]); + $cmd = $c->getDocComment(); + } + } else if (preg_match('#^\$([A-Za-z0-9_]+)$#', $str, $a)) { + /* ? $object */ + $obj = $a[1]; + if (isset($GLOBALS[$obj]) && is_object($GLOBALS[$obj])) { + $class = get_class($GLOBALS[$obj]); + + $c = new ReflectionClass($class); + $cmd = $c->getDocComment(); + } + + } else if (preg_match('#^([A-Za-z0-9_]+)\(\s*\)$#', $str, $a)) { + /* ? function() */ + $func = $a[1]; + + if (false !== ($proto = PHP_ShellPrototypes::getInstance()->get($func))) { + $cmd = sprintf("/**\n* %s\n*\n* @params %s\n* @return %s\n*/\n", + $proto['description'], + $proto['params'], + $proto['return'] + ); + } else if (function_exists($func)) { + $c = new ReflectionFunction($func); + $cmd = $c->getDocComment(); + } + } + + if ($cmd == '') { + $cmd = var_export(sprintf('no help found for \'%s\'', $str), 1); + } else { + $cmd = var_export($cmd, 1); + } + } else if ("?" == $l) { + $cmd = $this->getHelp(); + $cmd = var_export($cmd, 1); + } + + return $cmd; + } +} -- cgit v1.2.3