I ended up using the idea that @Abdou Rayes suggested, even though I had to adapt it.
In my specific case, I had some columns in the database that were camelCase and others were snake_case. I had to maintain the column names of the entities exactly as they were in the database.
So, after generating all the entities with this script I decided to loop over all the files generated and look for all the info I needed to replace. Right above every "private $nameOfTheVariable;" there was a comment with the actual column name in the database. With a regex I got all the actual column names, as well as the variables declared and then replace the variables with the actual column names.
The code looks like this:
// Changes the variables in the Entity
$regex = '/ORM\\\\Column\(name="([^"]*)"|private \$([^;]*);/';
$dir = new DirectoryIterator(__DIR__. '/entities');
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$str = file_get_contents($fileinfo->getRealPath());
preg_match_all($regex, $str, $matches, PREG_SET_ORDER, 0);
$variables = array();
$databaseColumns = array();
$both = array(&$databaseColumns, &$variables);
array_walk($matches, function($v, $k) use ($both) { $both[$k % 2][] = $v; }); // to split the column names and the variable names (since the regex returns them in order)
if( count($databaseColumns) != count($variables) ){ // just in case there are more items in one of the arrays than the other, something must have gone wrong
echo "Error in file " . $fileinfo->getFilename();
die;
}
$len = count($databaseColumns);
for($i = 0; $i < $len; $i++){
$actualColumnName = end($databaseColumns[$i]);
$nameOfVariableInTheEntity = end($variables[$i]);
$nameOfVariableInTheEntity = explode(" ", $nameOfVariableInTheEntity); // to remove possible extra stuff after the name of the variable, such as variables with default values in the database
$nameOfVariableInTheEntity = $nameOfVariableInTheEntity[0];
$str = str_replace('private $'.$nameOfVariableInTheEntity, 'private $'.$actualColumnName,$str); // replace the declaration of variable
$str = str_replace('$this->'.$nameOfVariableInTheEntity, '$this->'.$actualColumnName,$str); // replace the usage of the old variables
}
file_put_contents(__DIR__.'/entities/'.$fileinfo->getFilename(),$str);
}
}