# HG changeset patch # User luka # Date 1714002755 14400 # Node ID 4bb4daa9e3f1af2804690c95490a7eabfb4e73fc # Parent a20439b1c9d3b7596974de6c7993f479f919ab73 Working with the new FileModifier diff -r a20439b1c9d3 -r 4bb4daa9e3f1 .php-cs-fixer.cache --- a/.php-cs-fixer.cache Tue Jun 27 20:16:55 2023 -0400 +++ b/.php-cs-fixer.cache Wed Apr 24 19:52:35 2024 -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.3.6","version":"3.50.0","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":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,"unary_operator_spaces":{"only_dec_inc":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":{"attribute_placement":"ignore","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_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,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"src\/Generator\/Controller\/ControllerGenerator.php":"075e65a43e5ecc55fbc4dcd7636dfcc1","src\/Generator\/Model\/ModelGenerator.php":"e78c07fc13bd9c379991e8b01b13c672","src\/Generator\/Replacer.php":"5a7f98d22504edb6aba92b061ddd9803","src\/Generator\/Generator.php":"794271f48bed8f156878fc36a25ff60f","src\/Generator\/BaseGenerator.php":"409aadd181fbd4f216fe31f4f42ca3e2","src\/Replacer.php":"c6b5f421259f41016014c00270ca001c","src\/MagicForgerServiceProvider.php":"302d8a09dd351d150ee6cc7988dc447f","src\/Helpers\/FileModifier.php":"13d8f773a55604641ce1e89b28de2922","src\/Test.php":"bac04f2095478ff481ad176918e42db2"}} \ No newline at end of file diff -r a20439b1c9d3 -r 4bb4daa9e3f1 .vimrc --- a/.vimrc Tue Jun 27 20:16:55 2023 -0400 +++ b/.vimrc Wed Apr 24 19:52:35 2024 -0400 @@ -8,6 +8,7 @@ "set number nnoremap cc :set colorcolumn=80 nnoremap ncc :set colorcolumn-=80 +nnoremap :ALECodeAction set mouse=a function! FixPhpFiles() @@ -47,3 +48,26 @@ " " execute "set =\033d" " map :call GitDiffCached() +" +" +" +" + + +function! SendBufferToProgram() + " Create a temporary file + let temp_file = tempname() + + " Write current buffer to the temporary file + exe "write! " . temp_file + + " Send the content of the temporary file to your program + " Replace with the actual command to run your program + let command = "cat " . temp_file . " | " + + " Execute the command + call system(command) + + " Optionally, delete the temporary file if not needed + call delete(temp_file) +endfunction diff -r a20439b1c9d3 -r 4bb4daa9e3f1 src/Generator/Generator.php --- a/src/Generator/Generator.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Generator.php Wed Apr 24 19:52:35 2024 -0400 @@ -49,7 +49,7 @@ /* $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); } /* if ($this->option('factory')) { */ @@ -68,9 +68,9 @@ $this->createController(); } - /* if ($this->option('model')) { */ - /* $this->createModel(); */ - /* } */ + if ($this->option('model')) { + $this->createModel(); + } } @@ -84,6 +84,7 @@ return [ ['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 controller class for the table.'], ]; } diff -r a20439b1c9d3 -r 4bb4daa9e3f1 src/Generator/Replacer.php --- a/src/Generator/Replacer.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Generator/Replacer.php Wed Apr 24 19:52:35 2024 -0400 @@ -53,7 +53,9 @@ return $target; } - + /** + * @return array + */ public function get_available_replacements() { $table_name = $this->getTableInput(); @@ -138,7 +140,9 @@ { return $this->getRootNamespace() . 'Http\\Requests\\' . $this->model_name($name); } - + /** + * @return string + */ public function getRequestUses(string $name) { return implode("\n", [ @@ -172,3 +176,17 @@ return Str::lower($this->human_readable($name)); } } + +class Replacer +{ + /** + * @return void + */ + public function get_available_replacements(): array + { + } + + public function getRequestUses(): string + { + } +} diff -r a20439b1c9d3 -r 4bb4daa9e3f1 src/Helpers/FileModifier.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Helpers/FileModifier.php Wed Apr 24 19:52:35 2024 -0400 @@ -0,0 +1,98 @@ +get_file_contents($file_path); + $this->file_path = $file_path; + } + + + /** + * @param mixed $file_path + * @return void + */ + public function get_file_contents($file_path): void + { + //TODO: there needs to be more/any error checking + $f = fopen($file_path, "r"); + $this->contents = fread($f, filesize($file_path)); + fclose($f); + } + + + /** + * @param mixed $file_path + */ + public function write_to_path($file_path = null): void + { + $file_path = $file_path ?? $this->file_path; + + $f = fopen($file_path, "w"); + fwrite($f, $this->contents); + fclose($f); + } + + + /** + * Replaces the replacement point with the value in the current contents + * + * @param mixed $value + * @param mixed $replacement_point + */ + public function replace($value, $replacement_point): void + { + $this->contents = str_replace($replacement_point, $value, $this->contents); + } + + + /** + * Inserts the value above the insert point in the current contents + * + * @param mixed $value + * @param mixed $insert_point + * @return void + */ + public function insert($value, $insert_point): void + { + //seperate on new lines into an array + $file_arr = explode("\n", $this->contents); + $temp_arr = []; + + foreach($file_arr as $line) { + if(str_contains($line, $insert_point)) { + $temp_arr[] = $value; + } + $temp_arr[] = $line; + } + + $this->contents = implode("\n",$temp_arr); + } +} diff -r a20439b1c9d3 -r 4bb4daa9e3f1 src/Helpers/Replacer.php --- a/src/Helpers/Replacer.php Tue Jun 27 20:16:55 2023 -0400 +++ b/src/Helpers/Replacer.php Wed Apr 24 19:52:35 2024 -0400 @@ -1,5 +1,6 @@