From af404818e50c39ca9cfd6402b576055ca3ad8a3a Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 22 Sep 2016 12:33:38 +0000 Subject: [PATCH] cli : If the provided argument is -?, display the variable with the phpdoc associated git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3070 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- cli.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cli.php b/cli.php index 57facf9..955851f 100644 --- a/cli.php +++ b/cli.php @@ -295,8 +295,8 @@ class cli $paramsConst = array (); try { - $r = new ReflectionMethod ($class, "__construct"); - $paramsConst = $r->getParameters(); + $r1 = new ReflectionMethod ($class, "__construct"); + $paramsConst = $r1->getParameters(); $min = $max = count ($paramsConst); } catch (Exception $e) @@ -304,15 +304,33 @@ class cli // No constructor available in class } - $r = new ReflectionMethod ($class, $method); - $params = $r->getParameters(); + $r2 = new ReflectionMethod ($class, $method); + $params = $r2->getParameters(); foreach ($params as $param) { if (!$param->isOptional()) $min++; $max++; } - unset ($r); + + if (in_array ("-?", $argv)) + { + // Question mark display the PHPDoc of the method + $comment = trim (substr ($r1->getDocComment (), 3, -2)); + if ($comment !== "") $comment .= "\n"; + $comment .= trim (substr ($r2->getDocComment (), 3, -2)); + $comment = preg_replace ("#^\s*\*\s*#m", "", $comment); + $comment = preg_replace ("#@param .+ \\$(\w+) #U", "<\\1> ", $comment); + $params = ""; + foreach ($r1->getParameters() as $param) + $params .= "<".$param->name."> "; + foreach ($r2->getParameters() as $param) + $params .= "<".$param->name."> "; + echo "Parameters : $params\n$comment\n"; + exit; + } + unset ($r1); + unset ($r2); if (count ($argv) < $min) die ("Not enough parameters provided to method\n");