Simplify Command boilerplate for typical use-cases
#218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This is a general shuffling the
Commandclass hierarchy. The basicCommandfromsymfony/consoleis the same, but several of the helpers used bycvcommands have been moved around.Most notably, the
BaseCommand(internal tocv-app) has been replaced by theCvCommand(which is now part ofcv-lib). The contract forCvCommandshould be easier to use, and -- when we get CiviCRM extension integration (#219) -- it should slot-in more easily.Before
The
BaseCommandclass is internal to cv-app. It is fairly heavy with helpers that don't need to be in there (low cohesion).Pretty much all commands require the use of
BootTrait. The boilerplate code involves importing the trait, activating the trait, and then figuring out where to call a few helper functions. This is done in every command-class.After
The
CvCommandclass is part of cv-lib, and it includesBootTrait.Some other helpers have been moved out to standalone utilities.
Common bootstrap options (
--level,--user) are declared inBaseApplication. Bootstrap behavior is automatically included by way ofCvCommand. The default behavior assumes that you want Civi to be booted before running the command. But this can be overridden viagetBootOptions().Comments
plugins.mdreferred to this part of the functionality as experimental. Plugin support was only recently merged. So... I don't think there's much of an install-base needing the old contracts ofBootTrait.--leveland--usershould still work, but they can't work the same. (TheCommandclass hasn't been loaded... so we have to start processing those flags before have theCommand.)