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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
7 class Replacer
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
14 protected $replacement_cache = [];
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
18 * Prefix and Suffix for controller.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
27 * Prefix and Suffix for controller.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
43 public function __construct()
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
44 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
45 /* parent::__construct(); */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
48 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
49 * Model names are generated in uppercase first Camel case
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
50 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
51 public function model_name(string $name): string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
52 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
53 return Str::singular(Str::studly($name));
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
56 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
57 * Controller names are generated in uppercase first Camel case
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
58 * and wrapped in the prefix and suffix
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
59 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
60 public function controller_name(string $name): string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
61 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
62 return $this->controller_prefix .
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
63 $this->model_name($name) .
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
64 $this->controller_suffix;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
67 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
68 * Breaks up a string and makes it human readable
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
69 *
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
70 * This function assumes that the inputted name is camel case
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
71 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
72 public function human_readable(string $name): string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
73 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
74 return Str::title(Str::replace('_', ' ', $name));
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
77 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
78 * Breaks up a string and makes it human readable and lowecase
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
79 *
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 * This function assumes that the inputted name is camel case
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
81 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
82 public function human_readable_lc(string $name): string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
83 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
84 return Str::lower($this->human_readable($name));
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
87 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
88 * Outputs a log for the replacements based on log level.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
89 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
90 public function log(string $str, int $log_level = 1): void
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
93 if($this->log_level <= $log_level) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
94 print($str . "\n");
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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 }