Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of "flat" modules #13

Merged
merged 4 commits into from
Jul 27, 2021

Conversation

weierophinney
Copy link
Contributor

This patch implements the ability to create a module with a "flat" structure.

While the recommended structure for modules is still the default, the Mezzio skeleton app also allows creating "flat" modules that contain only source code (no templates, tests, assets, or other items); this is particularly of interest when creating application-specific, API-facing modules where tests may exist at the application level, and no templates are needed.
As such, this patch now adds a "--flat" option to mezzio:module:create which will allow generating this simpler flat structure.

In order to allow this, I needed to migrate away from consuming laminas-composer-autoloading for enabling/disabling autoloader rules for modules.
The reason is because laminas-composer-autoloading assumes a laminas-mvc structured module, which coincides with our recommended structure.
Since the flat structure is not part of the MVC ecosystem, it becomes specific to this Mezzio tooling, and thus requires "in-lining" the functionality.
In reality, it is a completely new approach to handling the tasks, and was written from the ground-up with testing in mind.

As such, this patch:

  • Removes the dependency on laminas-composer-autoloading.
  • Adds a new dependency on symfony/process.
  • Updates the mezzio:module:register and mezzio:module:deregister commands to use the new functionality.

Fixes #12

Adds the option "--flat" to the mezzio:module:create command.
When present, the command will not create the nested "src" directory under the module root directory, nor will it create a "templates" directory, either.

Functionality is incomplete; currently, the command proxies to laminas-composer-autoloading, which expects the nested directory when creating autoloading rules.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
The laminas-composer-autoloading package only allows the Mezzio "recommended" module structure (i.e., the version that has "src" and "templates" subdirectories).
To allow flat module structures, the mezzio:module:register command needs to be able to detect the type of module present based on the directory layout, and then register it correctly with the package.
Since this functionality is specific to Mezzio, I decided to inline the logic from laminas-composer-autoloading for parsing and updating the `composer.json` file, and to switch to symfony/process for executing the actual `composer` binary for running the `dump-autoload` process.

To make the above testable, I created a few interfaces, as well as default implementations.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney linked an issue Jul 27, 2021 that may be closed by this pull request
@weierophinney weierophinney added this to the 2.0.0 milestone Jul 27, 2021
@weierophinney weierophinney added the Enhancement New feature or request label Jul 27, 2021
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney merged commit 820d769 into mezzio:2.0.x Jul 27, 2021
@weierophinney weierophinney deleted the feature/flat-modules branch July 27, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow creation of "flat" modules
1 participant