Mercurial > packages > magicforger
diff src/Helpers/Replacer.php @ 1:ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
| author | luka |
|---|---|
| date | Sat, 24 Jun 2023 01:08:01 -0400 |
| parents | |
| children | 4bb4daa9e3f1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Helpers/Replacer.php Sat Jun 24 01:08:01 2023 -0400 @@ -0,0 +1,71 @@ +<?php +namespace Magicforger/Helpers; + + +/* + * Replacer + * + * A class that handles all replacements necessary + * + * General flow: + * Read a line looking for a replacement string + * + * A replacement string will consist of 2 values + * Reference Object, and Replacement Function + * + * After the replacement is made, the Object, function + * are stored in an array to be cached for future replacements + * + * Basically lazy loading the replacements. + * */ +class Replacer { + + +/* + * The array of cached replacements + * + * Object name => [ + * function => replacement text, + * ] + * + * */ +protected $replacement_cache []; + + +/* + * Static instance of inflector for + * string manipulation. + * + * */ +private static $inflector = null; + +public function __construct() { + if(is_null(self::$inflector)) { + self::$inflector = InflectorFactory::create()->build(); + } +} + + + + +protected function extract_replacement_values(string $replacement_string): string { + $matches = []; + preg_match('/o:([^\s]+)\s+f:([^\s]+)/', $replacement_string, $matches); + $name = $matches[1]; + $function = $matches[2]; + + return ['name' => $name, 'function' => $function]; +} + +protected function get_replacement(string $replacement_string): string { + + + + + return $replacement; +} + + + + +}
