Allow to display the controllers and the methods line by line to be parseable

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1722 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-08-18 09:53:04 +00:00
parent 33e87e33de
commit a886b63eb3

59
cli.php
View File

@@ -63,6 +63,14 @@ class cli
foreach ($files as $file) foreach ($files as $file)
$classes[$file] = substr (strstr ($file, "_"), 1, -4); $classes[$file] = substr (strstr ($file, "_"), 1, -4);
if (isset ($argv[0]) && $argv[0] === "-listonly")
{
// Lists the classes available in controllers and models if expert mode
// Don't do any presentation to be parseable (by bash completion by example)
echo implode ("\n", $classes)."\n";
exit;
}
if (isset ($argv[0]) && $argv[0] === "-list") if (isset ($argv[0]) && $argv[0] === "-list")
{ {
// Lists the classes available in controllers and models if expert mode // Lists the classes available in controllers and models if expert mode
@@ -75,7 +83,8 @@ class cli
} }
if (isset ($argv[0]) && $argv[0] === "-listmethods" || if (isset ($argv[0]) && $argv[0] === "-listmethods" ||
isset ($argv[0]) && $argv[0] === "-listmethodsdetails") isset ($argv[0]) && $argv[0] === "-listmethodsdetails" ||
isset ($argv[0]) && $argv[0] === "-listmethodsonly")
{ {
// Lists the methods of a class // Lists the methods of a class
if (!isset ($argv[1])) if (!isset ($argv[1]))
@@ -109,34 +118,40 @@ class cli
// Look at methods // Look at methods
$methods = $refclass->getMethods(); $methods = $refclass->getMethods();
echo "List of methods available in the class '$class' :\n"; if ($argv[0] !== "-listmethodsonly")
echo "List of methods available in the class '$class' :\n";
foreach ($methods as $key=>$method) foreach ($methods as $key=>$method)
{ {
if ($method->name === "__construct") if ($method->name === "__construct")
continue; continue;
if ($key > 0) if ($key > 0 && $argv[0] !== "-listmethodsonly")
echo "\n"; echo "\n";
echo " ".$method->name.$constParams; if ($argv[0] !== "-listmethodsonly")
$r = new ReflectionMethod ($class, $method->name); echo " ";
$params = $r->getParameters(); echo $method->name.$constParams;
foreach ($params as $param) if ($argv[0] !== "-listmethodsonly")
{ {
echo " "; $r = new ReflectionMethod ($class, $method->name);
if ($param->isOptional()) $params = $r->getParameters();
echo "["; foreach ($params as $param)
else {
echo " <"; echo " ";
echo $param->name; if ($param->isOptional())
if ($param->isOptional()) echo "[";
echo "]"; else
else echo " <";
echo ">"; echo $param->name;
} if ($param->isOptional())
echo "]";
else
echo ">";
}
if ($argv[0] === "-listmethodsdetails") if ($argv[0] === "-listmethodsdetails")
{ {
echo "\n"; echo "\n";
echo trim (substr ($method->getDocComment(), 3, -2)); echo trim (substr ($method->getDocComment(), 3, -2));
}
} }
echo "\n"; echo "\n";
} }