110 lines
2.3 KiB
PHP
Executable File
110 lines
2.3 KiB
PHP
Executable File
#!/usr/bin/php
|
|
<?php
|
|
|
|
include "utils.php";
|
|
|
|
global $files;
|
|
|
|
foreach ($files as $file) {
|
|
|
|
echo $file . "\n";
|
|
|
|
echo "processing methods for file " . $file . "\n";
|
|
|
|
$fn = fopen($file, "r");
|
|
|
|
$saveLine = true;
|
|
|
|
$methods = [];
|
|
|
|
$saveMethod = false;
|
|
|
|
$lines = [];
|
|
|
|
while (!feof($fn)) {
|
|
|
|
$line = fgets($fn);
|
|
|
|
/**
|
|
* if exiting an options definition block - stop saving that definition
|
|
*/
|
|
if (preg_match('/\bSTATIC_METHODS_END\b/', $line)) {
|
|
$saveMethod = false;
|
|
}
|
|
|
|
/**
|
|
* if exiting an method mplementation block - save the line for later
|
|
*/
|
|
if (preg_match('/\bSTATIC_METHODS_DEFINITION_END\b/', $line)) {
|
|
$saveLine = true;
|
|
}
|
|
|
|
/**
|
|
* Now save the line
|
|
*/
|
|
if ($saveLine) {
|
|
array_push($lines, $line);
|
|
}
|
|
|
|
/**
|
|
* if entering an options implementation block - do not save the line for later
|
|
*/
|
|
if (preg_match('/\bSTATIC_METHODS_DEFINITION_START\b/', $line)) {
|
|
$saveLine = false;
|
|
}
|
|
|
|
if ($saveMethod) {
|
|
|
|
$line = trim($line);
|
|
|
|
array_push($methods, $line);
|
|
}
|
|
|
|
/**
|
|
* If entering an options definition block - start saving that definition
|
|
*/
|
|
if (preg_match('/\bSTATIC_METHODS_START\b/', $line)) {
|
|
$saveMethod = true;
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fn);
|
|
|
|
file_put_contents($file, $lines);
|
|
|
|
/**
|
|
* Process the methods
|
|
*/
|
|
|
|
if (sizeof($methods) > 0) {
|
|
|
|
$template = file_get_contents('src/templates/static_method.template');
|
|
|
|
$newOptions = '';
|
|
|
|
foreach ($methods as $method) {
|
|
$updated = str_replace('METHOD_NAME_UPPERCASE', strtoupper($method), $template);
|
|
$updated = str_replace('METHOD_NAME', $method, $updated);
|
|
$newOptions .= $updated;
|
|
}
|
|
|
|
$contents = file_get_contents($file);
|
|
|
|
$contents = preg_replace(
|
|
'/\/\/\bSTATIC_METHODS_DEFINITION_START\b.*?\/\/\bSTATIC_METHODS_DEFINITION_END\b/s',
|
|
"//STATIC_METHODS_DEFINITION_START\n" . $newOptions . "\t\t//STATIC_METHODS_DEFINITION_END",
|
|
$contents
|
|
);
|
|
|
|
file_put_contents($file, $contents);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
?>
|
|
|