X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=scripts%2Fgen_stubs.php;h=c3343fc8c457e62b8ac0601a976417b0903ef48e;hp=20a1f0fdd853b35d459090e1a43f33a3e4d6cbf2;hb=cbfdc466d8a364445ba3389e876b7c7e7f0189b2;hpb=57e944b102006abfa4005337b0ac5901425f4289 diff --git a/scripts/gen_stubs.php b/scripts/gen_stubs.php index 20a1f0f..c3343fc 100755 --- a/scripts/gen_stubs.php +++ b/scripts/gen_stubs.php @@ -1,16 +1,22 @@ #!/usr/bin/env php isInterface()) { + $m ^= ReflectionMethod::IS_ABSTRACT; + } foreach (Reflection::getModifierNames($m) as $mn) { $n .= $mn . " "; } return $n; } -function t($p) { - if ($c = $p->getClass()) return "\\" . $c->getName() . " "; - if ($p->isArray()) return "array "; +function t(ReflectionParameter $p) { + if ($c = $p->getClass()) return ($p->allowsNull()?"?":"") . "\\" . $c->getName() . " "; + if ($p->isArray()) return ($p->allowsNull() ? "?":"") . "array "; + if ($p->hasType()) { + return ($p->allowsNull() ? "?" : "") . ($p->getType()->isBuiltin() ? "" : "\\") . $p->getType()->getName() . " "; + } } function c($n, $c) { $_=$c; @@ -112,7 +118,11 @@ foreach ($namespaces as $ns) { } $ps[] = $p1; } - fprintf($out, "%s) {\n\t}\n", implode(", ", $ps)); + fprintf($out, "%s)", implode(", ", $ps)); + if ($f->hasReturnType()) { + fprintf($out, " : %s%s", $f->getReturnType()->allowsNull() ? "?":"", $f->getReturnType()->getName()); + } + fprintf($out, " {\n\t}\n"); } } // @@ -143,8 +153,14 @@ foreach ($namespaces as $ns) { fprintf($out, "extends \\%s ", $p->getName()); } if ($i = $c->getInterfaceNames()) { - fprintf($out, "implements \\%s ", - implode(", \\", array_filter($i, function($v) { + fprintf($out, "%s \\%s ", + $c->isInterface() ? "extends" : "implements", + implode(", \\", array_filter($i, function($v) use($c, $i) { + foreach ($i as $ii) { + if ($v != $ii && (new ReflectionClass($ii))->implementsInterface("\\".$v)) { + return false; + } + } return $v != "Traversable"; })) @@ -169,7 +185,7 @@ foreach ($namespaces as $ns) { foreach ($c->getMethods() as $m) { if ($m->getDeclaringClass()->getName() == $c->getName()) { - fprintf($out, "\t\t%sfunction %s(", m($m->getModifiers()), + fprintf($out, "\t\t%sfunction %s(", m($m->getModifiers(), $c), $m->getName()); $ps = array(); foreach ($m->getParameters() as $p) { @@ -188,6 +204,11 @@ foreach ($namespaces as $ns) { $ps[] = $p1; } fprintf($out, "%s)", implode(", ", $ps)); + if ($m->hasReturnType()) { + fprintf($out, " : %s%s%s", $m->getReturnType()->allowsNull() ? "?":"", + $m->getReturnType()->isBuiltin() ? "" : "\\", //0 === strpos($m->getReturnType()->getName(), $c->getNamespaceName()) ? "\\":"", + $m->getReturnType()->getName()); + } if ($m->isAbstract()) { fprintf($out, ";\n\n"); } else {