Skip to content

Instantly share code, notes, and snippets.

@Geczy
Created November 18, 2015 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geczy/55c86c60b46fcdbfce57 to your computer and use it in GitHub Desktop.
Save Geczy/55c86c60b46fcdbfce57 to your computer and use it in GitHub Desktop.
$urls = Repo::all();
$correctKeys = \DB::connection()->getSchemaBuilder()->getColumnListing("packages");
unset($correctKeys[0], $correctKeys[1]);
foreach ($urls as $repo) {
$text_filename = $repo->id . '.txt';
if (!Storage::exists($text_filename)) {
continue;
}
$fullPath = storage_path() . '/app/' . $text_filename;
start_measure('fopen', 'Package via fgets');
$fp = fopen($fullPath, "r");
$package = [];
while (FALSE !== ($line = fgets($fp))) {
if ($line == "\n") {
foreach ($package as $key => $pack) {
$vals = explode(':', $pack, 2);
if (in_array($vals[0], $correctKeys)) {
$done[$vals[0]] = trim($vals[1]);
}
}
$all[$repo->id][] = $done;
$done = [];
$package = [];
continue;
}
if (0 === strpos($line, " ") || 0 === strpos($line, "\t") || strpos($line, ':') < 0) {
end($package);
$last = key($package);
$package[$last] = $package[$last] . "\n" . trim($line);
continue;
}
$package[] = rtrim($line);
}
fclose($fp);
stop_measure('fopen');
return view('welcome');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment