X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=reflection2php.php;h=7768eeb9a65a027979a497bf152408beae469f2d;hp=4f04c28d381670bf21b233abdebcfa0ffb7ac9e4;hb=4407379af8d886b627c88572e9da69c38cdbda58;hpb=7fc758b4ccec7ae1c996b87244373fb3ab4f1376 diff --git a/reflection2php.php b/reflection2php.php index 4f04c28..7768eeb 100755 --- a/reflection2php.php +++ b/reflection2php.php @@ -32,6 +32,31 @@ if (!strlen($ext = $argv[1])) die(sprintf("Usage: %s \n", $argv[0])); $ext = new ReflectionExtension($ext); +foreach ($ext->getConstants() as $constant => $value) { + printf("const %s = %s;\n", $constant, $value); +} +printf("\n"); + +foreach ($ext->getFunctions() as $f) { + printf("function %s(", $f->getName()); + $ps = array(); + foreach ($f->getParameters() as $p) { + $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName()); + if ($p->isOptional()) { + if ($p->isDefaultValueAvailable()) { + $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true)); + } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) { + $p1 .= " = NULL"; + } elseif ($p->isArray()) { + $p1 .= " = array()"; + } + } + $ps[] = $p1; + } + printf("%s) {\n}\n", implode(", ", $ps)); +} +printf("\n"); + foreach ($ext->getClasses() as $class) { printf("%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getName()); @@ -62,11 +87,15 @@ foreach ($ext->getClasses() as $class) { $ps = array(); foreach ($m->getParameters() as $p) { $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() || $p->isOptional()) { - $p1 .= sprintf(" = NULL"); - } + if ($p->isOptional()) { + if ($p->isDefaultValueAvailable()) { + $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true)); + } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) { + $p1 .= sprintf(" = NULL"); + } elseif ($p->isArray()) { + $p1 .= " = array()"; + } + } $ps[] = $p1; } printf("%s) {\n\t}\n", implode(", ", $ps));