+ $ps[] = $p1;
+ }
+ fprintf($out, "%s) {\n\t}\n", implode(", ", $ps));
+ }
+ }
+ //
+ if (isset($structures[$ns])) {
+ uasort($structures[$ns], function ($a, $b) {
+ /* @var $a ReflectionClass */
+ /* @var $b ReflectionClass */
+ $score = array_sum([
+ -!$a->isInterface()+
+ -!$a->isAbstract()+
+ -!$a->isTrait()+
+ -!substr_compare($a->getShortName(), "Exception", -strlen("Exception")),
+ +!$b->isInterface()+
+ +!$b->isAbstract()+
+ +!$b->isTrait()+
+ -!substr_compare($b->getShortName(), "Exception", -strlen("Exception")),
+ ]);
+
+ if ($score) {
+ return -$score;
+ }
+ return strnatcmp($a->getShortName(), $b->getShortName());
+ });
+ foreach ($structures[$ns] as $cn => $c) {
+ fprintf($out, "\n\t%s%s %s ", m($c->getModifiers()),
+ $c->isInterface() ? "interface":"class", $c->getShortName());
+ if ($p = $c->getParentClass()) {
+ fprintf($out, "extends \\%s ", $p->getName());
+ }
+ if ($i = $c->getInterfaceNames()) {
+ fprintf($out, "implements \\%s ",
+ implode(", \\", array_filter($i, function($v) {
+ return $v != "Traversable";
+
+ }))
+ );
+ }
+ fprintf($out, "\n\t{\n");
+
+ $_=0;
+ foreach ($c->getConstants() as $n => $v) {
+ c($n, $c) and $_+=fprintf($out, "\t\tconst %s = %s;\n", $n,
+ var_export($v, true));
+ }
+ $_ and fprintf($out, "\n");
+ $_=0;
+ foreach ($c->getProperties() as $p) {
+ if ($p->getDeclaringClass()->getName() == $c->getName()) {
+ $_+=fprintf($out, "\t\t%s\$%s;\n", m($p->getModifiers()),
+ $p->getName());
+ }
+ }
+ $_ and fprintf($out, "\n");