Created
February 6, 2015 16:40
-
-
Save matthias-chlechowitz/f5c49f531da4c9670e6d to your computer and use it in GitHub Desktop.
Remove all parameter definitions from container definitions (read: *.xml) and replace the parameters with the actual class names
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 | |
use Symfony\Component\Finder\Finder; | |
require_once('../app/autoload.php'); | |
$finder = new Finder(); | |
$finder->files()->in(__DIR__)->name('*.xml'); | |
// run through all found files | |
foreach ($finder as $file) { | |
// get the file content as a string | |
$filecontent = file_get_contents($file); | |
// match all parameter entries | |
preg_match_all('/<parameter key="(.*)">(.*)<\/parameter>/i', file_get_contents($file), $matches); | |
// Print the relative path to the file | |
print $file->getRelativePathname() . "\n"; | |
// var_dump($matches); | |
// run through paramter matches and replace the %class% with the real class name | |
foreach ($matches[1] as $index => $paramKey) { | |
$filecontent = preg_replace('/%' . $paramKey . '%/i', $matches[2][$index], $filecontent); | |
} | |
// remove the parameter block | |
$filecontent = preg_replace('/<parameters>(.*)<\/parameters>\\n/is', '', $filecontent); | |
// save the fresh content | |
file_put_contents($file, $filecontent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment