X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=reflection2php.php;h=37747be51c48702b537dce5e153ed74b953804e2;hp=7768eeb9a65a027979a497bf152408beae469f2d;hb=cc74cdc4ff1334afa39ff12001ba94309346df54;hpb=29a54250b58e444974ae19840194e214cab80bd5 diff --git a/reflection2php.php b/reflection2php.php index 7768eeb..37747be 100755 --- a/reflection2php.php +++ b/reflection2php.php @@ -9,7 +9,7 @@ function m($m) { return $n; } function t($p) { - if ($c = $p->getClass()) return $c->getName() . " "; + if ($c = $p->getClass()) return "\\" . $c->getName() . " "; if ($p->isArray()) return "array "; } function c($n, $c) { @@ -31,9 +31,11 @@ function c($n, $c) { if (!strlen($ext = $argv[1])) die(sprintf("Usage: %s \n", $argv[0])); +printf("getConstants() as $constant => $value) { - printf("const %s = %s;\n", $constant, $value); + printf("define('%s', '%s');\n", $constant, $value); } printf("\n"); @@ -57,33 +59,46 @@ foreach ($ext->getFunctions() as $f) { } printf("\n"); -foreach ($ext->getClasses() as $class) { +$classes = $ext->getClasses(); +usort($classes, function($a,$b) { + $cmp = strcmp($a->getNamespaceName(), $b->getNamespaceName()); + if (!$cmp) { + $cmp = strcmp($a->getShortName(), $b->getShortName()); + } + return $cmp; + } +); + +foreach ($classes as $class) { - printf("%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getName()); + if ($class->inNamespace()) { + printf("namespace %s\n{\n", $class->getNamespaceName()); + } + printf("\t%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getShortName()); if ($p = $class->getParentClass()) { - printf("extends %s ", $p->getName()); + printf("extends \\%s ", $p->getName()); } if ($i = $class->getInterfaceNames()) { - printf("implements %s ", implode(", ", array_filter($i,function($v){return$v!="Traversable";}))); + printf("implements \\%s ", implode(", \\", array_filter($i,function($v){return$v!="Traversable";}))); } - printf("\n{\n"); + printf("\n\t{\n"); $_=0; foreach ($class->getConstants() as $n => $v) { - c($n, $class) and $_+=printf("\tconst %s = %s;\n", $n, var_export($v, true)); + c($n, $class) and $_+=printf("\t\tconst %s = %s;\n", $n, var_export($v, true)); } $_ and printf("\n"); $_=0; foreach ($class->getProperties() as $p) { if ($p->getDeclaringClass()->getName() == $class->getName()) { - $_+=printf("\t%s\$%s;\n", m($p->getModifiers()), $p->getName()); + $_+=printf("\t\t%s\$%s;\n", m($p->getModifiers()), $p->getName()); } } $_ and printf("\n"); foreach ($class->getMethods() as $m) { if ($m->getDeclaringClass()->getName() == $class->getName()) { - printf("\t%sfunction %s(", m($m->getModifiers()), $m->getName()); + printf("\t\t%sfunction %s(", m($m->getModifiers()), $m->getName()); $ps = array(); foreach ($m->getParameters() as $p) { $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName()); @@ -98,10 +113,19 @@ foreach ($ext->getClasses() as $class) { } $ps[] = $p1; } - printf("%s) {\n\t}\n", implode(", ", $ps)); + printf("%s)", implode(", ", $ps)); + if ($m->isAbstract()) { + printf(";\n\n"); + } else { + printf(" {\n\t\t}\n\n"); + } } } - printf("}\n\n"); + printf("\t}\n"); + if ($class->inNamespace()) { + printf("}\n"); + } + printf("\n"); }