Mercurial > packages > magicforger
annotate src/Replacer.php @ 2:cf9993c5c7df
Updated .vimrc for some helper commands.
updated the Base Generator
Brought the controller generator into the package
created an example generator, but it needs some work.
| author | luka |
|---|---|
| date | Sun, 25 Jun 2023 14:45:15 -0400 |
| parents | ca36acd2bef2 |
| children | 6468684362c2 |
| rev | line source |
|---|---|
|
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
luka
parents:
diff
changeset
|
1 <?php |
|
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
luka
parents:
diff
changeset
|
2 |
|
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
luka
parents:
diff
changeset
|
3 namespace Wizzard\MagicForger; |
|
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
luka
parents:
diff
changeset
|
4 |
|
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
luka
parents:
diff
changeset
|
5 use Illuminate\Support\Str; |
|
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
luka
parents:
diff
changeset
|
6 |
| 2 | 7 class Replacer |
| 8 { | |
|
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
luka
parents:
diff
changeset
|
9 /** |
|
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
luka
parents:
diff
changeset
|
10 * Cached replacements for re-use. |
|
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
luka
parents:
diff
changeset
|
11 * |
|
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
luka
parents:
diff
changeset
|
12 * @var array |
|
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
luka
parents:
diff
changeset
|
13 */ |
| 2 | 14 protected $replacement_cache = []; |
| 15 | |
|
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
luka
parents:
diff
changeset
|
16 |
|
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
luka
parents:
diff
changeset
|
17 /** |
| 2 | 18 * Prefix and Suffix for controller. |
| 19 * Usage is up to the user. | |
|
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
luka
parents:
diff
changeset
|
20 * |
|
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
luka
parents:
diff
changeset
|
21 * @var string |
|
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
luka
parents:
diff
changeset
|
22 */ |
| 2 | 23 protected $controller_prefix = ""; |
|
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
luka
parents:
diff
changeset
|
24 |
|
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
luka
parents:
diff
changeset
|
25 |
|
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
luka
parents:
diff
changeset
|
26 /** |
| 2 | 27 * Prefix and Suffix for controller. |
| 28 * Usage is up to the user. | |
|
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
luka
parents:
diff
changeset
|
29 * |
|
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
luka
parents:
diff
changeset
|
30 * @var string |
|
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
luka
parents:
diff
changeset
|
31 */ |
| 2 | 32 protected $controller_suffix = "Controller"; |
|
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
luka
parents:
diff
changeset
|
33 |
|
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
luka
parents:
diff
changeset
|
34 |
|
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
luka
parents:
diff
changeset
|
35 /** |
| 2 | 36 * The lowest level to show log outputs. |
|
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
luka
parents:
diff
changeset
|
37 * |
|
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
luka
parents:
diff
changeset
|
38 * @var int |
|
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
luka
parents:
diff
changeset
|
39 */ |
| 2 | 40 private $log_level = 1; |
|
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
luka
parents:
diff
changeset
|
41 |
|
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
luka
parents:
diff
changeset
|
42 |
| 2 | 43 public function __construct() |
| 44 { | |
| 45 /* parent::__construct(); */ | |
| 46 } | |
|
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
luka
parents:
diff
changeset
|
47 |
| 2 | 48 /** |
| 49 * Model names are generated in uppercase first Camel case | |
| 50 */ | |
| 51 public function model_name(string $name): string | |
| 52 { | |
| 53 return Str::singular(Str::studly($name)); | |
| 54 } | |
|
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
luka
parents:
diff
changeset
|
55 |
| 2 | 56 /** |
| 57 * Controller names are generated in uppercase first Camel case | |
| 58 * and wrapped in the prefix and suffix | |
| 59 */ | |
| 60 public function controller_name(string $name): string | |
| 61 { | |
| 62 return $this->controller_prefix . | |
| 63 $this->model_name($name) . | |
| 64 $this->controller_suffix; | |
| 65 } | |
|
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
luka
parents:
diff
changeset
|
66 |
| 2 | 67 /** |
| 68 * Breaks up a string and makes it human readable | |
| 69 * | |
| 70 * This function assumes that the inputted name is camel case | |
| 71 */ | |
| 72 public function human_readable(string $name): string | |
| 73 { | |
| 74 return Str::title(Str::replace('_', ' ', $name)); | |
| 75 } | |
|
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
luka
parents:
diff
changeset
|
76 |
| 2 | 77 /** |
| 78 * Breaks up a string and makes it human readable and lowecase | |
| 79 * | |
| 80 * This function assumes that the inputted name is camel case | |
| 81 */ | |
| 82 public function human_readable_lc(string $name): string | |
| 83 { | |
| 84 return Str::lower($this->human_readable($name)); | |
| 85 } | |
|
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
luka
parents:
diff
changeset
|
86 |
| 2 | 87 /** |
| 88 * Outputs a log for the replacements based on log level. | |
| 89 */ | |
| 90 public function log(string $str, int $log_level = 1): void | |
| 91 { | |
|
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
luka
parents:
diff
changeset
|
92 |
| 2 | 93 if($this->log_level <= $log_level) { |
| 94 print($str . "\n"); | |
| 95 } | |
|
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
luka
parents:
diff
changeset
|
96 |
| 2 | 97 } |
|
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
luka
parents:
diff
changeset
|
98 } |
