cms
cms copied to clipboard
Allow starter kits to run console commands
Opening this as a draft as you may want an entirely different approach.
This PR allows starter kits to specify an after_install_hook
key which is a class name and method (\App\Hooks\MyHook::handle
) which receives the console as an argument so further input can be requested.
As requested here: https://github.com/statamic/ideas/issues/863
I don't really like this syntax \App\Hooks\MyHook::handle
. I'd prefer it if it assumed handle
and/or allowed it to be overwritten via property/method. The above syntax isn't really used in Laravel land.
@edalzell what about using @
instead of ::?
@edalzell what about using
@
instead of ::?
Why not make it like middleware and have it assumed?
@edalzell what about using
@
instead of ::?
however, this is better, as at least it's like the old way of doing routing w/ controllers.
Do we need the method? I kinda like assuming handle
, like a middleware.
But yeah the @
would be more inline with other class/method references.
Ok. It seems handle is the consensus so I will change it to that!
The weird thing about this is that you won't really want that file to exist once the starter kit is installed.
So you'd need it to be there for the initial composer require, then delete it? 🤔
Yeah that’s a good point. We could delete it after running, or we could leave that to the starter kit author?
Neat. I had actually been messing with this kind of thing on army own branch, though in the form of post-install PHP closures/callbacks (not commands) that would get run. They run from vendor, so there's be no need to delete anything after-the-fact. Would this work from your use case?
PS. I'll jump in more next week though, as I'm in cottage country right now 👍
Yeah that could work for us. Interested to see how you have approached it.
Just to finish off this approach - I've added a couple of lines to delete the after install hook
file once its been run.
I just tested this and it seems to work perfectly fine. Wonderful!
@ryanmitchell Just gave it a whirl, awesome! 🤘 I dug up my old closure implementation, and wasn't happy with how I was registering closure-based hooks either. Hacked on it a bit more and combined the best of our ideas into https://github.com/statamic/cms/pull/6792. Curious on your thoughts? (Yours too @robdekort!)