From: Michael Wallner Date: Fri, 3 Jun 2011 08:38:49 +0000 (+0000) Subject: * do not list inherited constants X-Git-Tag: DEV_2-before-client~110 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7fc758b4ccec7ae1c996b87244373fb3ab4f1376;p=m6w6%2Fext-http * do not list inherited constants * mark optional arguments with "=NULL" instead of wrapping into brackets --- diff --git a/reflection2php.php b/reflection2php.php index 6791aba..4f04c28 100755 --- a/reflection2php.php +++ b/reflection2php.php @@ -12,6 +12,21 @@ function t($p) { if ($c = $p->getClass()) return $c->getName() . " "; if ($p->isArray()) return "array "; } +function c($n, $c) { + $_=$c; + while ($c = $c->getParentClass()) { + if (array_key_exists($n, $c->getConstants())) { + return false; + } + } + $c=$_; + foreach ((array) $c->getInterfaces() as $i) { + if (array_key_exists($n, $i->getConstants()) || !c($n, $i)) { + return false; + } + } + return true; +} if (!strlen($ext = $argv[1])) die(sprintf("Usage: %s \n", $argv[0])); @@ -30,7 +45,7 @@ foreach ($ext->getClasses() as $class) { $_=0; foreach ($class->getConstants() as $n => $v) { - $_+=printf("\tconst %s = %s;\n", $n, var_export($v, true)); + c($n, $class) and $_+=printf("\tconst %s = %s;\n", $n, var_export($v, true)); } $_ and printf("\n"); $_=0; @@ -46,20 +61,12 @@ foreach ($ext->getClasses() as $class) { printf("\t%sfunction %s(", m($m->getModifiers()), $m->getName()); $ps = array(); foreach ($m->getParameters() as $p) { - $p1 = sprintf("%s%s", t($p), $p->isPassedByReference()?"&":""); - if ($p->isOptional()) { - $p1 .= sprintf("[\$%s", $p->getName()); - } else { - $p1 .= sprintf("\$%s", $p->getName()); - } + $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName()); if ($p->isDefaultValueAvailable()) { $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true)); - } elseif ($p->allowsNull()) { + } elseif ($p->allowsNull() || $p->isOptional()) { $p1 .= sprintf(" = NULL"); } - if ($p->isOptional()) { - $p1 .= sprintf("]"); - } $ps[] = $p1; } printf("%s) {\n\t}\n", implode(", ", $ps));