# HG changeset patch # User luka # Date 1697154064 14400 # Node ID b0b2e79ad8e68707047d5045fcdd747f2fa6e0c8 # Parent a20439b1c9d3b7596974de6c7993f479f919ab73 Not exatly sure what was changed but commiting to it :) diff -r a20439b1c9d3 -r b0b2e79ad8e6 .php-cs-fixer.cache --- a/.php-cs-fixer.cache Tue Jun 27 20:16:55 2023 -0400 +++ b/.php-cs-fixer.cache Thu Oct 12 19:41:04 2023 -0400 @@ -1,1 +1,1 @@ -{"php":"8.2.7","version":"3.19.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"curly_braces_position":{"allow_single_line_empty_anonymous_classes":true},"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/Generator\/BaseGenerator.php":"409aadd181fbd4f216fe31f4f42ca3e2","src\/Replacer.php":"c6b5f421259f41016014c00270ca001c","src\/MagicForgerServiceProvider.php":"e56f92adc0181e9b7681de8ca8aca6eb","src\/Generator\/Controller\/ControllerGenerator.php":"075e65a43e5ecc55fbc4dcd7636dfcc1","src\/Generator\/Generator.php":"794271f48bed8f156878fc36a25ff60f","src\/Generator\/Replacer.php":"5a7f98d22504edb6aba92b061ddd9803","src\/Generator\/Model\/ModelGenerator.php":"e78c07fc13bd9c379991e8b01b13c672"}} \ No newline at end of file +{"php":"8.2.10","version":"3.19.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"curly_braces_position":{"allow_single_line_empty_anonymous_classes":true},"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/Generator\/Route\/RouteGenerator.php":"4145e6208d253b08e9415339655c43e8","src\/Generator\/Controller\/ControllerGenerator.php":"cda3b688502c4427a50680c41b3a0f9d","src\/Generator\/Model\/ModelGenerator.php":"ded0f28024f6b6cbbfda97fbe14fda5a","src\/Generator\/Generator.php":"32b046d691dd2c24388e0741f875b184","src\/Generator\/Requests\/UpdateRequestGenerator.php":"ed745b244a7151bf0c12439af236f99b","src\/Generator\/Requests\/RequestGenerator.php":"29917ee19288caa73d92b46645c54905","src\/Generator\/Requests\/StoreRequestGenerator.php":"04b9c38f3339e02be4dc2d1c7545a370","src\/Generator\/BaseGenerator.php":"e59b94348fbc89dabdfea4098d4dfacb","src\/MagicForgerServiceProvider.php":"38024b0e807b2bc4cdd756ab456965a0","src\/Replacer\/Replacer.php":"830af5da740df6688a6def60966d38d7","src\/Replacer\/TableReplacer.php":"52736f1760b4c556cb3390e3d51a8812"}} \ No newline at end of file diff -r a20439b1c9d3 -r b0b2e79ad8e6 examples/ExampleGenerator.php.stub --- a/examples/ExampleGenerator.php.stub Tue Jun 27 20:16:55 2023 -0400 +++ b/examples/ExampleGenerator.php.stub Thu Oct 12 19:41:04 2023 -0400 @@ -1,6 +1,6 @@ files->get($this->getStub()); } + /** * Get the desired class table from the input. * @@ -209,4 +217,23 @@ return $this->schema; } + + protected function getTable(string $table_name) + { + return $this->getSchema()->introspectTable($table_name); + } + + protected function getCurrentTable() + { + return $this->currentTable; + } + + protected function setCurrentTable(string $table_name) + { + $table = null; + if(!is_null($table_name) && trim($table_name) !== '') { + $table = $this->getTable($table_name); + } + $this->currentTable = $table; + } } diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Controller/ControllerGenerator.php --- a/src/Generator/Controller/ControllerGenerator.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Controller/ControllerGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -4,7 +4,6 @@ use Symfony\Component\Console\Attribute\AsCommand; use Wizzard\MagicForger\Generator\BaseGenerator; -use Wizzard\MagicForger\Replacer; use Illuminate\Support\Str; #[AsCommand(name: 'mf:controller')] @@ -36,6 +35,7 @@ */ public function handle() { + $table = $this->getTable($this->getTableInput()); parent::handle(); } diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Controller/stubs/controller.stub --- a/src/Generator/Controller/stubs/controller.stub Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Controller/stubs/controller.stub Thu Oct 12 19:41:04 2023 -0400 @@ -35,10 +35,13 @@ */ public function store({{ storeRequest }} $request) { + $validated = $request->validated(); + // ${{ modelVariable }} = new {{ model }}(); //insert the values into the model + //{{ valuesForCreation }} ${{ modelVariable }}->save(); @@ -74,7 +77,11 @@ */ public function update({{ updateRequest }} $request, {{ model }} ${{ modelVariable }}) { + $validated = $request->validated(); + // Set the variables + //{{ valuesForCreation }} + ${{ modelVariable }}->save(); return redirect()->route('{{ tableName }}.index'); diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Generator.php --- a/src/Generator/Generator.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Generator.php Thu Oct 12 19:41:04 2023 -0400 @@ -11,7 +11,6 @@ use Illuminate\Support\Str; use Wizzard\MagicForger\Generator\BaseGenerator; -use Wizzard\MagicForger\Replacer; #[AsCommand(name: 'mf')] class Generator extends BaseGenerator @@ -44,12 +43,17 @@ return false; } + $this->setCurrentTable($this->getTableInput()); + dd($this->getCurrentTable()->getForeignKeys()); + if ($this->option('all')) { /* $this->input->setOption('factory', true); */ /* $this->input->setOption('seed', true); */ /* $this->input->setOption('migration', true); */ $this->input->setOption('controller', true); - /* $this->input->setOption('model', true); */ + $this->input->setOption('model', true); + $this->input->setOption('request', true); + $this->input->setOption('route', true); } /* if ($this->option('factory')) { */ @@ -68,9 +72,17 @@ $this->createController(); } - /* if ($this->option('model')) { */ - /* $this->createModel(); */ - /* } */ + if ($this->option('model')) { + $this->createModel(); + } + + if ($this->option('request')) { + $this->createRequest(); + } + + if ($this->option('route')) { + $this->createRoute(); + } } @@ -81,10 +93,13 @@ */ protected function getOptions() { - return [ + return array_merge(parent::getOptions(), [ ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], - ]; + ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], + ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], + ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], + ]); } /** @@ -102,6 +117,21 @@ protected function createController() { - $this->call('mf:controller', ['table' => $this->getTableInput()]); + $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); + } + + protected function createModel() + { + $this->call('mf:model', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); + } + + protected function createRequest() + { + $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); + } + + protected function createRoute() + { + $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); } } diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Model/ModelGenerator.php --- a/src/Generator/Model/ModelGenerator.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Model/ModelGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -1,6 +1,6 @@ created_by = \Auth::user()->id; + $item->updated_by = \Auth::user()->id; + }); + + self::saving(function ($item) { + $item->updated_by = \Auth::user()->id; + }); + } } diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Replacer.php --- a/src/Generator/Replacer.php Tue Jun 27 20:16:55 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -get_all_inserts($target); - $available_replacements = $this->get_available_replacements(); - - $target = str_replace( - array_keys($available_replacements), - $available_replacements, - $target - ); - - return $target; - } - - public function get_available_replacements() - { - $table_name = $this->getTableInput(); - $replacements = [ - "{{ class }}" => $this->getClassName($table_name), - "{{ model }}" => $this->model_name($table_name), - "{{ modelVariable }}" => $this->model_variable($table_name), - "{{ namespace }}" => $this->{'get' . $this->type . 'Namespace'}(), - "{{ namespacedModel }}" => $this->getModelNamespace(), - "{{ requestUses }}" => $this->getRequestUses($table_name), - "{{ rootNamespace }}" => $this->getRootNamespace(), - "{{ storeRequest }}" => $this->store_request_name($table_name), - "{{ tableName }}" => $table_name, - "{{ updateRequest }}" => $this->update_request_name($table_name), - ]; - - return $replacements; - } - - //////////////////////////////////////////// - // Internals and Classes // - //////////////////////////////////////////// - - /** - * Model names are generated in uppercase first Camel case - */ - public function model_name(string $name): string - { - return Str::singular(Str::studly($name)); - } - - /** - * Model variable is standardly just a singular version of the table name - */ - public function model_variable(string $name): string - { - return Str::singular($name); - } - - /** - * Controller names are generated in uppercase first Camel case - * and wrapped in the prefix and suffix - */ - public function controller_name(string $name): string - { - return $this->controller_prefix . - $this->model_name($name) . - $this->controller_suffix; - } - - public function store_request_name(string $name): string - { - return 'Store' . $this->model_name($name); - } - - public function update_request_name(string $name): string - { - return 'Update' . $this->model_name($name); - } - - - //////////////////////////////////////////// - // Namespaces // - //////////////////////////////////////////// - - public function getRootNamespace() - { - return $this->laravel->getNamespace(); - } - - public function getModelNamespace() - { - return $this->getRootNamespace() . 'Models'; - } - - public function getControllerNamespace() - { - return $this->getRootNamespace() . 'Http\\Controllers'; - } - - public function getRequestNamespace(string $name) - { - return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name); - } - - public function getRequestUses(string $name) - { - return implode("\n", [ - "use " . $this->getRequestNamespace($name) . '\\' . $this->store_request_name($name), - "use " . $this->getRequestNamespace($name) . '\\' . $this->update_request_name($name), - ]); - } - - - //////////////////////////////////////////// - // Language and Presentables // - //////////////////////////////////////////// - - /** - * Breaks up a string and makes it human readable - * - * This function assumes that the inputted name is camel case - */ - public function human_readable(string $name): string - { - return Str::title(Str::replace('_', ' ', $name)); - } - - /** - * Breaks up a string and makes it human readable and lowecase - * - * This function assumes that the inputted name is camel case - */ - public function human_readable_lc(string $name): string - { - return Str::lower($this->human_readable($name)); - } -} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Requests/RequestGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Requests/RequestGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,103 @@ +tableExists($this->getTableInput())) { + $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); + + return false; + } + + if ($this->option('all')) { + $this->input->setOption('store_request', true); + $this->input->setOption('update_request', true); + } + + if ($this->option('store_request')) { + $this->createStoreRequest(); + } + + if ($this->option('update_request')) { + $this->createUpdateRequest(); + } + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return array_merge(parent::getOptions(), [ + ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'], + ['store_request', 's', InputOption::VALUE_NONE, 'Generate store request class for the table.'], + ['update_request', 'u', InputOption::VALUE_NONE, 'Generate update request class for the table.'], + ]); + } + + /** + * Interact further with the user if they were prompted for missing arguments. + * + * @return void + */ + protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) + { + } + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + } + + protected function createStoreRequest() + { + $this->call('mf:store_request', ['table' => $this->getTableInput()]); + } + + protected function createUpdateRequest() + { + $this->call('mf:update_request', ['table' => $this->getTableInput()]); + } + +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Requests/StoreRequestGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Requests/StoreRequestGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,79 @@ +resolveStubPath('/stubs/request.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->store_request_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['App\\', '\\'], ['app/', '/'], $this->getRequestNamespace($this->getTableInput()) . '/' . $this->store_request_name($this->getTableInput()) . '.php'); + } +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Requests/UpdateRequestGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Requests/UpdateRequestGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,79 @@ +resolveStubPath('/stubs/request.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->update_request_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['App\\', '\\'], ['app/', '/'], $this->getRequestNamespace($this->getTableInput()) . '/' . $this->update_request_name($this->getTableInput()) . '.php'); + } +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Requests/stubs/request.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Requests/stubs/request.stub Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,28 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Route/RouteGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Route/RouteGenerator.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,79 @@ +resolveStubPath('/stubs/routes.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getClassName($name) + { + return $this->routes_name($name); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getPath($name = null) + { + return str_replace(['App\\', '\\'], ['app/', '/'], $this->getRouteNamespace() . '/' . $this->routes_name($this->getTableInput()) . '.php'); + } +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Generator/Route/stubs/route.stub --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Generator/Route/stubs/route.stub Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,13 @@ +prefix('{{ tableName }}') + ->alias('{{ tableName }}.') + ->group( function () { + Route::get('/', 'index')->name('index'); + Route::get('/create', 'create')->name('create'); + Route::get('/edit', 'edit')->name('edit'); + + Route::post('/store', 'store')->name('store'); + Route::put('/udpate/{id}', 'update')->name('update'); + Route::delete('/delete/{id}', 'delete')->name('delete'); + }); diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Helpers/Replacer.php --- a/src/Helpers/Replacer.php Tue Jun 27 20:16:55 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ - [ - * 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; -} - - - - -} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/MagicForgerServiceProvider.php --- a/src/MagicForgerServiceProvider.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/MagicForgerServiceProvider.php Thu Oct 12 19:41:04 2023 -0400 @@ -6,6 +6,10 @@ use Wizzard\MagicForger\Generator\Generator; use Wizzard\MagicForger\Generator\Controller\ControllerGenerator; use Wizzard\MagicForger\Generator\Model\ModelGenerator; +use Wizzard\MagicForger\Generator\Requests\RequestGenerator; +use Wizzard\MagicForger\Generator\Requests\StoreRequestGenerator; +use Wizzard\MagicForger\Generator\Requests\UpdateRequestGenerator; +use Wizzard\MagicForger\Generator\Route\RouteGenerator; class MagicForgerServiceProvider extends ServiceProvider { @@ -19,6 +23,10 @@ Generator::class, ControllerGenerator::class, ModelGenerator::class, + RequestGenerator::class, + StoreRequestGenerator::class, + UpdateRequestGenerator::class, + RouteGenerator::class, ]); } } diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Replacer.php --- a/src/Replacer.php Tue Jun 27 20:16:55 2023 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -log_level <= $log_level) { - print($str . "\n"); - } - - } -} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Replacer/Replacer.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Replacer/Replacer.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,196 @@ +get_all_inserts($target); + $available_replacements = $this->get_available_replacements(); + + $target = str_replace( + array_keys($available_replacements), + $available_replacements, + $target + ); + + return $target; + } + + public function get_available_replacements() + { + $table_name = $this->getTableInput(); + $replacements = [ + "{{ class }}" => $this->getClassName($table_name), + "{{ controllerName }}" => $this->controller_name($table_name), + "{{ model }}" => $this->model_name($table_name), + "{{ modelVariable }}" => $this->model_variable($table_name), + "{{ namespace }}" => $this->{'get' . $this->type . 'Namespace'}($table_name), + "{{ namespacedModel }}" => $this->getNamespacedModel($table_name), + "{{ requestUses }}" => $this->getRequestUses($table_name), + "{{ rootNamespace }}" => $this->getRootNamespace(), + "{{ storeRequest }}" => $this->store_request_name($table_name), + "{{ tableName }}" => $table_name, + "{{ updateRequest }}" => $this->update_request_name($table_name), + ]; + + return $replacements; + } + + //////////////////////////////////////////// + // Internals and Classes // + //////////////////////////////////////////// + + /** + * Model names are generated in uppercase first Camel case + */ + public function model_name(string $name): string + { + return Str::singular(Str::studly($name)); + } + + /** + * Model variable is standardly just a singular version of the table name + */ + public function model_variable(string $name): string + { + return Str::singular($name); + } + + /** + * Controller names are generated in uppercase first Camel case + * and wrapped in the prefix and suffix + */ + public function controller_name(string $name): string + { + return $this->controller_prefix . + $this->model_name($name) . + $this->controller_suffix; + } + + public function store_request_name(string $name): string + { + return 'Store' . $this->model_name($name) . 'Request'; + } + + public function update_request_name(string $name): string + { + return 'Update' . $this->model_name($name) . 'Request'; + } + + + //////////////////////////////////////////// + // Namespaces // + //////////////////////////////////////////// + + public function getRootNamespace() + { + return $this->laravel->getNamespace(); + } + + public function getModelNamespace(string $name = '') + { + return $this->getRootNamespace() . 'Models'; + } + + public function getNamespacedModel(string $name = '') + { + return $this->getModelNamespace() . '\\' . $this->model_name($name); + } + + public function getControllerNamespace(string $name = '') + { + return $this->getRootNamespace() . 'Http\\Controllers'; + } + + public function getRequestNamespace(string $name) + { + return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name); + } + + public function getStoreRequestNamespace(string $name) + { + return $this->getRequestNamespace($name); + } + + public function getUpdateRequestNamespace(string $name) + { + return $this->getRequestNamespace($name); + } + + public function getRequestUses(string $name) + { + return implode("\n", [ + "use " . $this->getRequestNamespace($name) . '\\' . $this->store_request_name($name) . ';', + "use " . $this->getRequestNamespace($name) . '\\' . $this->update_request_name($name) . ';', + ]); + } + + + public function getRouteNamespace(string $name = '') + { + return $this->getRootNamespace() . 'Http\\Controllers'; + } + + + //////////////////////////////////////////// + // Language and Presentables // + //////////////////////////////////////////// + + /** + * Breaks up a string and makes it human readable + * + * This function assumes that the inputted name is camel case + */ + public function human_readable(string $name): string + { + return Str::title(Str::replace('_', ' ', $name)); + } + + /** + * Breaks up a string and makes it human readable and lowecase + * + * This function assumes that the inputted name is camel case + */ + public function human_readable_lc(string $name): string + { + return Str::lower($this->human_readable($name)); + } +} diff -r a20439b1c9d3 -r b0b2e79ad8e6 src/Replacer/TableReplacer.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Replacer/TableReplacer.php Thu Oct 12 19:41:04 2023 -0400 @@ -0,0 +1,17 @@ +getTables()->getColumns(); + } + + protected function get_attributes() + { + } +}