Add configurable namespaces for generated classes#1794
Open
Amoifr wants to merge 1 commit intosymfony:1.xfrom
Open
Add configurable namespaces for generated classes#1794Amoifr wants to merge 1 commit intosymfony:1.xfrom
Amoifr wants to merge 1 commit intosymfony:1.xfrom
Conversation
Allow overriding the default namespace for controllers, commands,
entities, forms and repositories via the maker configuration:
maker:
namespaces:
entity: Domain\Entity
controller: Application\Controller
Defaults are centralized in a NamespaceType enum, and the directory
is derived automatically from PSR-4 autoloading rules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 is a proof of concept to support the discussion in #1344 — it is not intended to be merged as-is, but to serve as a concrete base for the ongoing reflection.
What it does
Adds an optional
namespacesconfiguration to override the default namespace for generated classes:The directory is derived automatically from PSR-4 autoloading rules (no
diroption needed, as @GromNaN suggested).Design choices
NamespaceTypeenum — replaces magic strings with a typed enum for all 5 configurable types (controller, command, entity, form, repository). Provides IDE autocompletion and prevents typos.defaultNamespace(). TheGeneratormerges user config on top of these defaults.scalarPrototype— the config accepts any key, not a fixed list. Users can override only what they need.Validator::validateClassName().$generator->getNamespace(NamespaceType::Entity)instead of hardcoded'Entity\\'.Generatoris already available ingenerate(). TheMakeControllerlogic was moved frominteract()togenerate()to avoid adding a constructor dependency.What's NOT in scope (possible follow-ups)
--namespace) for one-off overrides (mentioned by @GromNaN)