-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add generators for seeders and migrations + Options to generate #61
Conversation
…ate from the model command
Thanks! Is this an active fork being used in your project, or can I hop in and work on things? |
Yes, I use this in my local dev, but for the moment it is a local path repository in composer so you can commit to this branch and it will not effect me until I pull down the changes. |
@JasperTey Have to worked anything more on this? I might have some time in the weekend to look at this. |
I was also reserving the weekend for this. One recent thought that I'll share, from some experimentation on a local branch: Making return [
['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model'],
['controller', 'c', InputOption::VALUE_NONE, 'Create a new controller for the model'],
['factory', 'f', InputOption::VALUE_NONE, 'Create a new factory for the model'],
['force', null, InputOption::VALUE_NONE, 'Create the class even if the model already exists'],
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model'],
['morph-pivot', null, InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom polymorphic intermediate table model'],
['policy', null, InputOption::VALUE_NONE, 'Create a new policy for the model'],
['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder for the model'],
['pivot', 'p', InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom intermediate table model'],
['resource', 'r', InputOption::VALUE_NONE, 'Indicates if the generated controller should be a resource controller'],
['api', null, InputOption::VALUE_NONE, 'Indicates if the generated controller should be an API resource controller'],
['requests', 'R', InputOption::VALUE_NONE, 'Create new form request classes and use them in the resource controller'],
]; Of course, each option would be generated as the corresponding DDD equivalent where applicable. Would this be a welcomed change? |
Sure, that sounds good. How would we handle controllers, requests etc that maybe shouldn't be in the domain. Should they be generated in the Application layer then? If so, then I would like to be able to control where they are generated based on the information we have. For example I typically have my controllers at this path in my application: |
Yeah, a configurable path for the application layer will be needed. In my recent applications, there is often an equivalent "module" in the application that corresponds to a domain. Example:
And there are also modules that could exist which don't correspond to any domain necessarily. e.g.,
In these apps, I've created local commands that allow me to do the following: php artisan make:controller InvoiceController --module=Invoicing
php artisan make:controller SendInvoiceController --module=Invoicing
php artisan make:request UpdateInvoiceRequest --module=Invoicing
php artisan make:controller PreferenceController --module=Settings
php artisan make:controller AdminDashboardController --module=Dashboard Would new ddd config keys Your example with Let me know your thoughts. |
Yes, I think this could work for a general and not so opinionated use case. And I agree, my convention might be a bit too specific and opinionated to support in an easily configurable way. Maybe something like:
I can play around with this and see if I find something flexible and intuitive. |
For this PR, will keep things simple and just extend |
I started poking around on on this PR; I see a variety of other micro changes which I don't want to disrupt since this is being used in your project. I'm going to leave this PR intact for reference purposes, but will start work in a clean branch to focus on implementing Another idea I see you've implemented, is supporting ddd-specific stubs when present ( |
Ok, that sounds good. |
PR got closed when I deleted and recreated the develop branch... forgot that the branch was being used for this draft PR. |
Hoping to resolve most of the items here in the PR currently in progress: #69 If you have a moment @pelmered, I wanted to understand your specific convention:
What is the root namespace of this application layer under |
Ok great job!
The app folder is a bit of a mess with some code that is left there from the default Laravel structure. We plan to cleanup and refactor this a bit along with the a new API version. The other three are pretty well structured and some of the things in the App folder should probably be moved to support. Regarding |
Thanks for the details @pelmered! Here is the current implementation of the application layer in #69: Application Layer (since 1.2)Some objects interact with the domain layer, but are not part of the domain layer themselves. By default, these include: // In config/ddd.php
'application_layer' => [
'path' => 'app/Modules',
'namespace' => 'App\Modules',
'objects' => [
'controller',
'request',
'middleware',
],
], The default configuration above will result in the following: ddd:model Invoicing:Invoice --controller --resource --requests Output:
...which doesn't quite support your Would ALL controllers via I'm currently working on support for custom resolvers, but the caveat is that the point where namespaces are resolved, only the following information is available: domainName, resourceName, and type (via ddd:{type}). I'll think on this a bit and see if I can have more information made available for custom callbacks, such as the options that were used in the original |
Here is what I was able to implement so far (in #69): // In config/ddd.php
'application_layer' => [
'path' => 'src/App',
'namespace' => 'App',
'objects' => [
'controller',
'request',
'middleware',
],
], In AppServiceProvider boot method: use Lunarstorm\LaravelDDD\ValueObjects\DomainCommandContext;
DDD::resolveNamespaceUsing(function (string $domain, string $type, ?DomainCommandContext $context): ?string {
if ($type == 'controller' && $context->option('api')) {
return "App\\Api\\Controllers\\{$domain}";
}
return null;
}); Result: php artisan ddd:controller Invoicing:PaymentApiController --api
# Controller [src/App/Api/Controllers/Invoicing/PaymentApiController.php] created successfully. Current Limitations:
|
Closing in favour of #77 |
This PR adds commands for generating seeders and migrations inside the domain.
It also adds options on the
ddd:model
command to generate more files at the same time.ddd:model -a
also generates factory, seeder, migration and policy for that model. I thought that you also could configure what you want to have generated with this option in the config fileddd:model -f
also generates a model factoryddd:model -m
also generates a migrationddd:model -p
also generates a policyddd:model -s
also generates a seederI also thought about adding
-t
to generate a test file. An option for generating PHPUnit or Pest class would be nice.The migration command is currently not working properly and it needs some more testing.