annotate src/Replacer/Replacer.php @ 21:f0b0d014e448 main-dev

Cleaning up code based on AI overlord review
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 26 Feb 2025 19:45:08 -0500
parents 19b7a8de0019
children 827efbf4d73c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
1 <?php
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
2
19
19b7a8de0019 updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents: 14
diff changeset
3 namespace Wizard\MagicForger\Replacer;
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
4
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
5 use Illuminate\Support\Str;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
6
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
7 trait Replacer
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
8 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
9 /**
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
10 * Prefix and Suffix for controller.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
11 * Usage is up to the user.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
12 *
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
13 * @var string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
14 */
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
15 protected string $controller_prefix = '';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
16
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
17 /**
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
18 * Prefix and Suffix for controller.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
19 * Usage is up to the user.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
20 *
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
21 * @var string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
22 */
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
23 protected string $controller_suffix = 'Controller';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
24
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
25 /**
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
26 * Finds all places in a string that could be replaced.
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
27 * Returns an array of all potential replacements as they appear in the target.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
28 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
29 * @param string $target
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
30 * @return array
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
31 */
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
32 public function get_all_keywords(string $target): array
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
33 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
34 // find all matches to our expected syntax
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
35 $matches = [];
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
36 preg_match_all('/{{[\sa-zA-Z\-_]+}}/', $target, $matches);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
37 // sort the array and return unique values
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
38 sort($matches[0]);
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
39
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
40 return array_values(array_unique($matches[0]));
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
41 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
42
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
43 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
44 * Apply replacements to the target string.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
45 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
46 * @param string $target
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
47 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
48 */
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
49 public function apply_replacements(string $target): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
50 {
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
51 $inserts = $this->get_all_keywords($target);
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
52 $available_replacements = $this->get_available_replacements();
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
53
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
54 return str_replace(
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
55 array_keys($available_replacements),
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
56 $available_replacements,
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
57 $target
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
58 );
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
59 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
60
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
61 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
62 * Get available replacements for string replacements.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
63 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
64 * @return array
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
65 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
66 public function get_available_replacements(): array
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
67 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
68 $table_name = $this->getTableInput();
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
69
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
70 return [
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
71 '{{ class }}' => $this->getClassName($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
72 '{{ controllerName }}' => $this->controller_name($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
73 '{{ model }}' => $this->model_name($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
74 '{{ modelVariable }}' => $this->model_variable($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
75 '{{ namespace }}' => $this->{'get' . $this->type . 'Namespace'}($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
76 '{{ namespacedModel }}' => $this->getNamespacedModel($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
77 '{{ requestUses }}' => $this->getRequestUses($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
78 '{{ rootNamespace }}' => $this->getRootNamespace(),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
79 '{{ storeRequest }}' => $this->store_request_name($table_name),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
80 '{{ tableName }}' => $table_name,
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
81 '{{ updateRequest }}' => $this->update_request_name($table_name),
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
82 ];
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
83 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
84
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
85 // Model and Controller Naming
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
86
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
87 /**
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
88 * Generate model name in Studly case.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
89 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
90 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
91 * @return string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
92 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
93 public function model_name(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
94 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
95 return Str::singular(Str::studly($name));
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
96 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
97
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
98 /**
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
99 * Generate singular model variable name.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
100 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
101 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
102 * @return string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
103 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
104 public function model_variable(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
105 {
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 9
diff changeset
106 return Str::singular($name);
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
107 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
108
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
109 /**
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
110 * Generate controller name using prefix/suffix and studly case.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
111 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
112 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
113 * @return string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
114 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
115 public function controller_name(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
116 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
117 return $this->controller_prefix .
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
118 $this->model_name($name) .
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
119 $this->controller_suffix;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
120 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
121
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
122 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
123 * Generate the store request name.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
124 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
125 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
126 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
127 */
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
128 public function store_request_name(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
129 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
130 return 'Store' . $this->model_name($name) . 'Request';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
131 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
132
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
133 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
134 * Generate the update request name.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
135 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
136 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
137 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
138 */
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
139 public function update_request_name(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
140 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
141 return 'Update' . $this->model_name($name) . 'Request';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
142 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
143
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
144 // Namespace Methods
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
145 // These methods handle the formation of various namespaces used within the replacements.
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
146
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
147 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
148 * Get the root namespace for the application.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
149 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
150 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
151 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
152 public function getRootNamespace(): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
153 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
154 return $this->laravel->getNamespace();
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
155 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
156
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
157 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
158 * Get the model namespace.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
159 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
160 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
161 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
162 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
163 public function getModelNamespace(string $name = ''): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
164 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
165 return $this->getRootNamespace() . 'Models';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
166 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
167
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
168 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
169 * Get the fully-qualified namespaced model class.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
170 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
171 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
172 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
173 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
174 public function getNamespacedModel(string $name = ''): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
175 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
176 return $this->getModelNamespace() . '\\' . $this->model_name($name);
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
177 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
178
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
179 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
180 * Get the controller namespace.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
181 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
182 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
183 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
184 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
185 public function getControllerNamespace(string $name = ''): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
186 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
187 return $this->getRootNamespace() . 'Http\\Controllers';
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
188 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
189
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
190 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
191 * Get the request namespace.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
192 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
193 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
194 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
195 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
196 public function getRequestNamespace(string $name): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
197 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
198 return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name);
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
199 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
200
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
201 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
202 * Get the store request namespace.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
203 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
204 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
205 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
206 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
207 public function getStoreRequestNamespace(string $name): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
208 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
209 return $this->getRequestNamespace($name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
210 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
211
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
212 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
213 * Get the update request namespace.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
214 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
215 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
216 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
217 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
218 public function getUpdateRequestNamespace(string $name): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
219 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
220 return $this->getRequestNamespace($name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
221 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
222
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
223 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
224 * Get the request uses string for replacement.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
225 *
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
226 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
227 * @return string
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
228 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
229 public function getRequestUses(string $name): string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
230 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
231 return implode("\n", [
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
232 'use ' . $this->getRequestNamespace($name) . '\\' . $this->store_request_name($name) . ';',
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
233 'use ' . $this->getRequestNamespace($name) . '\\' . $this->update_request_name($name) . ';',
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
234 ]);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
235 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
236
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
237 // Text Manipulation
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
238
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
239 /**
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
240 * Convert a string to a human-readable format.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
241 * Assumes camel case input.
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
242 *
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
243 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
244 * @return string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
245 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
246 public function human_readable(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
247 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
248 return Str::title(Str::replace('_', ' ', $name));
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
249 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
250
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
251 /**
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
252 * Convert a string to a lowercase human-readable format.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
253 * Assumes camel case input.
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
254 *
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
255 * @param string $name
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
256 * @return string
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
257 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
258 public function human_readable_lc(string $name): string
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
259 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
260 return Str::lower($this->human_readable($name));
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
261 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
262 }