comparison 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
comparison
equal deleted inserted replaced
0:329123c41eaf 1:ca36acd2bef2
1 <?php
2 namespace Magicforger/Helpers;
3
4
5 /*
6 * Replacer
7 *
8 * A class that handles all replacements necessary
9 *
10 * General flow:
11 * Read a line looking for a replacement string
12 *
13 * A replacement string will consist of 2 values
14 * Reference Object, and Replacement Function
15 *
16 * After the replacement is made, the Object, function
17 * are stored in an array to be cached for future replacements
18 *
19 * Basically lazy loading the replacements.
20 * */
21 class Replacer {
22
23
24 /*
25 * The array of cached replacements
26 *
27 * Object name => [
28 * function => replacement text,
29 * ]
30 *
31 * */
32 protected $replacement_cache [];
33
34
35 /*
36 * Static instance of inflector for
37 * string manipulation.
38 *
39 * */
40 private static $inflector = null;
41
42 public function __construct() {
43 if(is_null(self::$inflector)) {
44 self::$inflector = InflectorFactory::create()->build();
45 }
46 }
47
48
49
50
51 protected function extract_replacement_values(string $replacement_string): string {
52 $matches = [];
53 preg_match('/o:([^\s]+)\s+f:([^\s]+)/', $replacement_string, $matches);
54 $name = $matches[1];
55 $function = $matches[2];
56
57 return ['name' => $name, 'function' => $function];
58 }
59
60 protected function get_replacement(string $replacement_string): string {
61
62
63
64
65 return $replacement;
66 }
67
68
69
70
71 }