Skip to content

Commit

Permalink
Merge pull request #39 from BrianHenryIE/more-thorough-classmap-repla…
Browse files Browse the repository at this point in the history
…cing

Classmap replacing change str_replace to regex
  • Loading branch information
coenjacobs authored May 23, 2020
2 parents 3d28355 + 586e18c commit 189e141
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function replacePackageByAutoloader(Package $package, $autoloader)
$this->replaceInFile($targetFile, $autoloader);
}
}

}
}

Expand All @@ -113,9 +114,18 @@ public function replaceParentClassesInDirectory($directory)
if ('.php' == substr($targetFile, '-4', 4)) {
$contents = $this->filesystem->read($targetFile);

foreach ($replacedClasses as $key => $value) {
$contents = str_replace($key, $value, $contents);
}
foreach ($replacedClasses as $original => $replacement) {
$contents = preg_replace_callback(
'/(.*)([^a-zA-Z0-9_\x7f-\xff])'. $original . '([^a-zA-Z0-9_\x7f-\xff])/U',
function ($matches) use ($replacement) {
if(preg_match('/(include|require)/', $matches[0], $output_array)) {
return $matches[0];
}
return $matches[1] . $matches[2] . $replacement . $matches[3];
},
$contents
);
}

$this->filesystem->put($targetFile, $contents);
}
Expand Down

0 comments on commit 189e141

Please sign in to comment.