Last active
August 29, 2015 14:22
-
-
Save aminin/afb5061d8d149f9aeadf to your computer and use it in GitHub Desktop.
Merge orm annotations to existing classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Run after $ php app/console doctrine:mapping:convert annotation | |
$propertyRegExp = '~( \/\*\*[^/]+?\*\/)\s+(?:private)|(?:protected) \$(\w+)\;~'; | |
$classRegExp = '~(\/\*\*[\s\S]+?\*\/)\s+(class \w+)~'; | |
$to = ''; | |
$from = ''; | |
$Regex = new RegexIterator( | |
new RecursiveIteratorIterator(new RecursiveDirectoryIterator($from)), | |
'/^.+\.php$/i', | |
RecursiveRegexIterator::GET_MATCH | |
); | |
$i = 0; | |
foreach ($Regex as $file) { | |
$file = $file[0]; | |
$baseName = basename($file); | |
echo $baseName, "\n"; | |
$toFile = $to . '/' . $baseName; | |
$fileContents = file_get_contents($file); | |
$toFileContents = file_get_contents($toFile); | |
if (preg_match($classRegExp, $fileContents, $m)) { | |
$classComment = $m[0]; | |
echo $classComment, "\n"; | |
$toFileContents = preg_replace($classRegExp, $classComment, $toFileContents); | |
} | |
if (preg_match_all($propertyRegExp, $fileContents, $matches, PREG_SET_ORDER)) { | |
foreach ($matches as $mm) { | |
$re = str_replace('(\w+)', $mm[2], $propertyRegExp); | |
$toFileContents = preg_replace($re, $mm[0], $toFileContents); | |
echo $re, "\n"; | |
} | |
} | |
file_put_contents($toFile, $toFileContents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment