Last active
August 26, 2023 00:50
-
-
Save mcsee/4eb63e5acfcdda39b24e3f6a73eb0bdb to your computer and use it in GitHub Desktop.
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
<? | |
final class TextReplacer { | |
function replace( | |
string $patternToFind, | |
string $textToReplace, | |
string $subject, | |
string $replaceFunctionName, | |
$postProcessClosure) { | |
return $postProcessClosure( | |
$replaceFunctionName($patternToFind, $textToReplace, $subject)); | |
} | |
} | |
// Lots of tests on text replacer so you can gain confidence. | |
final class WordProcessor { | |
function replaceText(string $patternToFind, string $textToReplace) { | |
$this->text = (new TextReplacer())->replace( | |
$patternToFind, | |
$textToReplace, | |
$this->text, | |
'str_replace', fn($text) => '<<<' . $text . '>>>'); | |
} | |
} | |
final class Obfuscator { | |
function obfuscate(string $patternToFind, string $textToReplace) { | |
$this->text = (new TextReplacer())->replace( | |
$patternToFind, | |
$textToReplace, | |
$this->text, | |
'str_ireplace', fn($text) => strlower($text)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment