etag test & fixes; set default etag mode for temp streams to crc32(b)
[m6w6/ext-http] / reflection2php.php
index 6791aba35fb28500227ca108026f89a0f75b8c29..7768eeb9a65a027979a497bf152408beae469f2d 100755 (executable)
@@ -12,11 +12,51 @@ 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 <ext>\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());
@@ -30,7 +70,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 +86,16 @@ 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());
-                               }
-                               if ($p->isDefaultValueAvailable()) {
-                                       $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true));
-                               } elseif ($p->allowsNull()) {
-                                       $p1 .= sprintf(" = NULL");
-                               }
-                               if ($p->isOptional()) {
-                                       $p1 .= sprintf("]");
-                               }
+                               $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 .= sprintf(" = NULL");
+                    } elseif ($p->isArray()) {
+                        $p1 .= " = array()";
+                    }
+                }
                                $ps[] = $p1;
                        }
                        printf("%s) {\n\t}\n", implode(", ", $ps));