[8.x] Generalized stub path resolution #37412
Closed
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.
This PR solves the issue described in #37389: Several
make:
commands do not use custom stubs in a project but are hard-wired to their default stub files instead.While creating the PR, I discovered several different ways to resolve the stub path in the existing code, which have all been reduced to a single protected method in the
GeneratorCommand
, leading to a net negative of lines and simplified code. This newresolveStubPath
helper uses a reflection class to locate the directory of the current class, which I deemed acceptable for a command intended to be used during development. This makes it possible to let all generator commands (even third-party ones) use the same, uniform way to locate stubs, while preserving backwards-compatibility.Please note that this PR does not change which stubs are published and which aren't, as I think that's out of scope and not my decision to make. It merely gives users the option to override any stubs to fit their own requirements, if that is necessary.
While there are no tests for generator commands as far as I could see, I did run the test suite without issues and monkey-patched the changes in a standard Laravel project to verify path resolution is working as intended.