Skip to content

Refactoring the code to be more MakerBundle-like#15

Merged
mamazu merged 3 commits intomasterfrom
refactor
Mar 10, 2025
Merged

Refactoring the code to be more MakerBundle-like#15
mamazu merged 3 commits intomasterfrom
refactor

Conversation

@mamazu
Copy link
Copy Markdown
Collaborator

@mamazu mamazu commented Jan 2, 2025

What I did

  • Using the interact Method to set up the command
  • Using the DoctrineHelper to select entities interactively
  • Unifying the defaults for all commands (it's --assume-defaults or -d everywhere)

Changing naming conventions

  • Removing the option to configure namespaces for classes. If you don't like where the generator is putting things, just move them afterwards.
  • Using the class name details generator to generate Symfony like class names

What this means

One of the advantages of using Sulu is that you're free to put your classes where ever you want as long as they're correctly wired up. However, this also makes it harder for a tool like the maker bundle to find stuff to update and reference. So I suggest the following structure.

src
|--> Admin
|   +--> EventAdmin.php // The Admin configuration
|--> Controller
|   |--> Admin
|   |   +--> EventController.php // The Admin API controller
|   +--> OtherController.php // This is where Symfony maker controllers live
|--> Entity
|   +--> Event.php // The resource itself
+--> Trash
    +--> EventTrashItemHandler.php

@mamazu mamazu force-pushed the refactor branch 3 times, most recently from cb1088a to 2fd1660 Compare January 2, 2025 11:20
@mamazu
Copy link
Copy Markdown
Collaborator Author

mamazu commented Jan 2, 2025

@alexander-schranz Maybe you also have an opinion on the directory structure I'm proposing here. I don't know what the most common way to structure a Sulu application is.

@alexander-schranz
Copy link
Copy Markdown
Member

I don't think our typical domain-based structure makes sense for a MakerBundle, so I would have a look at the Symfony MakerBundle how they handle it.

PS: would make all maker bundle classes @internal like Symfony Maker bundle is also doing. So you can at anytime refactor the whole code of a maker / generator.

@mamazu
Copy link
Copy Markdown
Collaborator Author

mamazu commented Jan 6, 2025

The file tree I showed in the comment would be the directory structure of the generated project. Because there is currently no convention for where a Sulu admin class would be located. It would generate admin classes with the maker to this location. src/Admin. Of course the user can still move them but I'm asking if this is a sensible default.

And marking all classes as internal makes sense.

@mamazu
Copy link
Copy Markdown
Collaborator Author

mamazu commented Mar 10, 2025

Merging this because I need this for another feature. (Attribute based routing)

@mamazu mamazu merged commit b5cccc1 into master Mar 10, 2025
2 checks passed
@mamazu mamazu deleted the refactor branch March 10, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants