Skip to content

Instantly share code, notes, and snippets.

@Geczy
Created Nov 18, 2015
Embed
What would you like to do?
$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