-
-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create module:make-class command #1802
Create module:make-class command #1802
Conversation
This looks good the signature should be This needs to be compatible with the already released config file please remove config changes that are dependant on your other PR. Also, tests are required for the new command. |
yes this command should look like module:make-class and module:make-enum
class command should create file in the module app directory like |
I'm not sure about having a classes command, I think it is better to have specific make commands ie: php artisan module:make-enum Thoughts? |
a244d0f
to
d65d640
Compare
Yes, you are correct. This PR will enable the generation of various types of classes, including enums, services, repositories, and many other custom types. I intend to establish this class as a foundation for easily generating dedicated class commands such as After this PR is merged, I'll proceed with the remaining commands immediately. |
I think it may be better to generate classes into the folder root or the php module:make-class Concerns/HasDomain
php module:make-class Services/UserService
php module:make-class Actions/UserStoreAction
php module:make-class Helpers/DateFormat These would be stored in app/src depends on the value of Also the make-class command needs tests in order to be accepted. |
This is already the default behaviour. Regarding the
I can't run the test with my current Windows system. I'll appreciate it if you or anyone else can create the test. |
To handle cases there the config doesn't have the class path you can modify your code from: $config = GenerateConfigReader::read('class');
$path .= $this->type_path($config->getPath()) . '/' . $this->getFileName() . '.php'; To $filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app_folder') . 'Classes';
$path .= $this->type_path($filePath) . '/' . $this->getFileName() . '.php'; Can you change your method names to be camelCased rather then snake_case, also there's a few methods that don't have a return type. Let me know when you feel this is ready and I can look at added the tests |
07947b0
to
4eb7af8
Compare
I've fixed this already. public function getDestinationFilePath(): string
{
$app_path = GenerateConfigReader::read('class')->getPath() ?? $this->app_path('Classes');
return $this->path($this->type_path($app_path) . '/' . $this->getFileName() . '.php');
} I've added a method to get the /**
* Get the app path basename.
*/
public function app_path(?string $path = null): string
{
$config_path = config('modules.paths.app_folder');
$app_path = strlen($config_path) ? trim($config_path, '/') : 'app';
$app_path .= strlen($path) ? '/' . $path : '';
return $this->clean_path($app_path);
}
The snake_case is easier for me to identify and read. I didn't change any existing identifiers to my preference case, as every developer has their preferences. However, the PHP convention supports the snake_case - https://www.php.net/manual/en/userlandnaming.rules.php.
I've fixed them too.
Okay, sir. I'm currently experiencing a minor difficulty with the namespace. I'll update you, once I rounded it up. Thank you. |
Hi, @dcblogdev. |
896c3c0
to
7f6be9b
Compare
Description: Create a new class Usage: module:make:class [options] [--] <name> <module> Arguments: name The name of the class module The targeted module Options: -t, --type[=TYPE] The type of class, e.g. class, service, repository, contract, etc. [default: "service"] -p, --plain Create the class without suffix (type) -i, --invokable Generate a single method, invokable class -f, --force Create the class even if the class already exists -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question --env[=ENV] The environment the command should run under -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Examples: ``` php artisan module:make:class Example Example ``` ``` php artisan module:make:class Example Example -t class ``` ``` php artisan module:make:class Example Example -t repository ``` ``` php artisan module:make:class Example Example -p -t repository ```
Get the module root path + extra $path
7f6be9b
to
2db7125
Compare
Issue: #1800 - Need to add two command "make:enum" and "make:class" for the modules
Examples:
Create a service class:
Create a standard class
Create a repository class
Create a repository class without a suffix