- How do I add the --module option to an existing Laravel Artisan command?
- Use the `Modularize` trait in your command class. This automatically adds the `--module` flag and injects a `module()` method that returns the resolved `ModuleConfig` instance. No additional configuration is needed beyond including the trait.
- Can I use internachi/modularize with Laravel versions older than 13?
- No, this package is designed for Laravel 13+ due to its reliance on Symfony 7.x components. If you’re using an older Laravel version, you’ll need to find an alternative or manually implement modular support.
- What happens if I don’t specify a module when running a command with Modularize?
- The `--module` flag is optional. If omitted, the `module()` method returns `null`, allowing you to handle non-module-specific logic in your command. This makes the package flexible for both module-aware and global commands.
- How does ModularizeGeneratorCommand handle file generation paths and namespaces?
- The `ModularizeGeneratorCommand` trait automatically places generated files in the correct module directory and applies the module’s namespace. It overrides the default `getPath()` and `getDefaultNamespace()` methods to ensure consistency with the module structure.
- Is internachi/modularize compatible with custom module configurations or non-PSR-4 paths?
- The package relies on `internachi/modular`'s `ModuleConfig` for path and namespace resolution. If your modules use non-standard configurations, you may need to extend or override the `ModuleConfig` class to ensure compatibility with the traits.
- Can I use this package without internachi/modular installed?
- No, `internachi/modularize` depends on `internachi/modular` for module resolution. If you’re not already using `internachi/modular`, this package won’t work without significant refactoring to adapt to its expected `ModuleConfig` structure.
- How do I test commands that use Modularize or ModularizeGeneratorCommand?
- Mock the `ModuleConfig` instance returned by the `module()` method in your tests. For generators, verify that the generated files are placed in the correct module directory and use the expected namespace. Use Laravel’s `Artisan::call()` for integration testing.
- Are there any performance concerns with using Modularize in production?
- The package adds minimal overhead, primarily during command initialization when resolving the module. Since it leverages Laravel’s service container and traits, there’s no significant impact on runtime performance in production environments.
- What are the alternatives to internachi/modularize for Laravel modular commands?
- Alternatives include `spatie/laravel-modules`, which provides a broader modular system with its own command helpers, or manually implementing module-aware logic using Laravel’s service container and traits. However, these may not offer the same seamless integration with `internachi/modular`.
- How do I customize the module resolution logic in Modularize?
- Extend the `Modularize` trait or override the `module()` method in your command class. You can also customize how the module is resolved by modifying the `ModuleConfig` class or injecting your own resolution logic via Laravel’s service container.