diff options
author | Brion Vibber <brion@pobox.com> | 2010-10-07 15:48:38 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-10-07 15:48:38 -0700 |
commit | fcef2aaab752db9441c1976b5ce98d55d240e489 (patch) | |
tree | 908a4f8cb505cad4f4239e1360f5c6c6d68c9404 | |
parent | 63c4cb3f36c5136a92f0f60ae10dad716b5f425b (diff) |
Pretty up the table dumper :D
-rw-r--r-- | scripts/dumpschema.php | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/scripts/dumpschema.php b/scripts/dumpschema.php index 567eadfb2..5a0fd0bdb 100644 --- a/scripts/dumpschema.php +++ b/scripts/dumpschema.php @@ -27,12 +27,56 @@ END_OF_CHECKSCHEMA_HELP; require_once INSTALLDIR.'/scripts/commandline.inc'; +function indentOptions($indent) +{ + $cutoff = 3; + if ($indent < $cutoff) { + $space = str_repeat(' ', $indent * 4); + $sep = ","; + $lf = "\n"; + $endspace = "$lf" . str_repeat(' ', ($indent - 1) * 4); + } else { + $space = ''; + $sep = ", "; + $lf = ''; + $endspace = ''; + } + if ($indent - 1 < $cutoff) { + } + return array($space, $sep, $lf, $endspace); +} + +function prettyDumpArray($arr, $key=null, $indent=0) +{ + list($space, $sep, $lf, $endspace) = indentOptions($indent); + list($inspace, $insep, $inlf, $inendspace) = indentOptions($indent + 1); + + print "{$space}"; + if (!is_numeric($key)) { + print "'$key' => "; + } + if (is_array($arr)) { + print "array({$inlf}"; + $n = 0; + foreach ($arr as $key => $row) { + $n++; + prettyDumpArray($row, $key, $indent + 1); + if ($n < count($arr)) { + print "$insep$inlf"; + } + } + // hack! + print "{$inendspace})"; + } else { + print var_export($arr, true); + } +} + function dumpTable($tableName) { - echo "$tableName\n"; $schema = Schema::get(); $def = $schema->getTableDef($tableName); - var_export($def); + prettyDumpArray($def, $tableName); echo "\n"; } |