Skip to content

Commit

Permalink
Ensure that a classes base class comes first in the merged source.
Browse files Browse the repository at this point in the history
This fixes mongofill#46
  • Loading branch information
Roy Williams committed Sep 12, 2015
1 parent ca4440f commit ea62063
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tools/merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ private function mergePHPFiles(array $files)
{
$code = '';

$needed_first = array();
$file_names = array();
foreach($files as $file) {
$code .= PHP_EOL . $this->readCodeFromFile($file);
$file_names[basename($file)] = $file;
$code = $this->readCodeFromFile($file);
if (preg_match('/extends\s+(\w+)\s+.*/i', $code, $match)) {
$needed_first[$match[1] . '.php'] = True;
}
}

print var_dump(array_keys($file_names));
foreach(array_keys($needed_first) as $basename) {
if (array_key_exists($basename, $file_names)) {
$code .= PHP_EOL . $this->readCodeFromFile(
$file_names[$basename]
);
}
}
foreach($files as $file) {
if (!array_key_exists(basename($file), $needed_first)) {
$code .= PHP_EOL . $this->readCodeFromFile($file);
}
}

return $code;
Expand Down Expand Up @@ -80,7 +100,7 @@ private function prepareNamespaces($code)
$ns,
substr($ns, 0, strlen($ns)-1) . ' {',
$code
) . PHP_EOL . '}';
) . PHP_EOL . '}';
}

private function findPHPFiles(array $paths)
Expand Down Expand Up @@ -113,7 +133,7 @@ private function saveCodeToFile($filename, $code)
}

(new Merger(
['src', 'vendor/mongofill/mongofill/src'],
['src', 'vendor/mongofill/mongofill/src'],
['vendor/mongofill/mongofill/src/functions.php'],
'src/ext_mongo.php'
));

0 comments on commit ea62063

Please sign in to comment.