/** * Returns a string containing information about this value * * @param mixed $value The value to return information about * @return String A shoft string describing the input */ function getDump($value) { if (is_bool($value)) { return "bool(" . ($value ? "TRUE" : "FALSE") . ")"; } else { if (is_null($value)) { return "null()"; } else { if (is_int($value)) { return "int(" . $value . ")"; } else { if (is_float($value)) { return "float(" . $value . ")"; } else { if (is_string($value)) { return "string('" . str_replace(array("\n", "\r", "\t"), array('\\n', '\\r', '\\t'), \r8\str\truncate(addslashes($value), 50, "'...'")) . "')"; } else { if (is_array($value)) { if (count($value) == 0) { return "array(0)"; } $output = array(); $i = 0; foreach ($value as $key => $val) { $i++; $output[] = getDump($key) . " => " . (is_array($val) ? "array(" . count($val) . ")" : getDump($val)); if ($i == 2) { break; } } return "array(" . count($value) . ")(" . implode(", ", $output) . (count($value) > 2 ? ",..." : "") . ")"; } else { if (is_object($value)) { return "object(" . get_class($value) . ")"; } else { if (is_resource($value)) { return "resource(" . get_resource_type($value) . ")"; } else { return "unknown(" . gettype($value) . ")"; } } } } } } } } // @codeCoverageIgnoreEnd }
public function testFunctionGetDump() { $this->string(getDump(42))->isEqualTo("integer([33m42[0m)" . PHP_EOL . PHP_EOL)->string(getDump(42, 'foobar', new \stdClass()))->isEqualTo("integer([33m42[0m)" . PHP_EOL . PHP_EOL . "string(6) [33m\"foobar\"[0m" . PHP_EOL . PHP_EOL . "[42;37;1mobject stdClass[0m" . PHP_EOL . PHP_EOL); }
function dumpFile(&$var, $info = FALSE, $mode = 'a') { if (isLive()) { // do not create dumps for LIVE application return; } $out = getDump($var, $info); $fp = fopen('dump.htm', $mode); if ($mode == 'w') { $str = "<html><head><title>DUMP</title></head><body>"; fwrite($fp, $str); } fwrite($fp, $out); fclose($fp); }
} // init credentials array and connect to MySql DB $startTime = init($credentials = array(), $link); echo "Opening iTunes... (You can minimize iTunes when it opens) "; // grab the total track count from iTunes $tracks = str_replace("\n", "", @`/usr/bin/osascript /Applications/.SqlTunes/Interfaces/iTunes.Interface.app count 2> /dev/null`); if (!is_numeric($tracks)) { wlog("Invalid number of tracks returned.", true, true); } echo "done.\n"; // go through all the tracks in the iTunes library for ($i = 1; $i <= $tracks; $i++) { // dump data for that track @`/usr/bin/osascript /Applications/.SqlTunes/Interfaces/iTunes.Interface.app {$i} 2>&1 /dev/null`; // Load the iTunes dump, dump the load read if we are logging it $iTunesTrack->setData(getDump($credentials["Log"])); switch ($credentials["Log"]) { case "Debug": wlog($iTunesTrack->debug(), false, false); case "Verbose": printf("\n%06.2f%% %6d %6d | %s - %s", $i / $tracks * 100, $i, $iTunesTrack->getDatabaseID(), $iTunesTrack->getArtist(), $iTunesTrack->getTrackName()); wlog($i . " " . $iTunesTrack->getDatabaseID() . " " . $iTunesTrack->getArtist() . " - " . $iTunesTrack->getTrackName(), false, false); break; case "Normal": printf("\n%06.2f%% %s - %s", $i / $tracks * 100, $iTunesTrack->getArtist(), $iTunesTrack->getTrackName()); break; } // perform non-fatal query on MySql DB query($iTunesTrack->getQuery(), false); } // log the summary stats