Skip to content

Instantly share code, notes, and snippets.

@matthias-chlechowitz
Created February 6, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthias-chlechowitz/f5c49f531da4c9670e6d to your computer and use it in GitHub Desktop.
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
<?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