private function appendSource($fileHandler, $path)
{
if (!file_exists($path)) {
return;
}
$openComment = false;
foreach (file($path) as $line) {
// Skip comments
$trimLine = trim($line);
if ($trimLine == '/*' || $trimLine == '/**') {
$openComment = true;
continue;
}
if ($openComment) {
if ($trimLine == '*/' || $trimLine == '**/') {
$openComment = false;
}
continue;
}
// Skip unneeded lines
if (strncmp($line, '#include "', 10) == 0 || strncmp($line, '#include <', 10) == 0 || strncmp($line, 'ZEPHIR_DOC_METHOD', 18) == 0 || strncmp($line, '#line ', 6) == 0) {
continue;
}
// Clean externs, except for PHP API functions
if (strncmp($line, 'extern ', 7) == 0) {
if (substr($line, 7, 8) == 'ZEND_API' || substr($line, 7, 6) == 'PHPAPI') {
fwrite($fileHandler, $line);
} else {
fwrite($fileHandler, substr($line, 7));
}
continue;
}
// Ordinary line - put it as is
fwrite($fileHandler, $line);
}
fwrite($fileHandler, PHP_EOL . PHP_EOL);
}