How imo-tikuwa/laravel-make-with-format works
Main Components
• Package Core (src folder):
• LaravelMakeWithFormatServiceProvider: Registers the package into the Laravel application.
• Facade (src/Facades): Provides an accessible interface to the package’s functionality.
• Listeners (src/Listeners/PostCommandCodeFormatter.php): Listens to Laravel’s make:●● command events.
• Services (src/Services) and additional runners (CommandRunner subfolder): Encapsulate the logic to run external processes (Pint and IDE Helper generators).
• Dependencies Checker: Ensures optional tools like Pint and IDE Helper are present.
• Demo Application (demo_app folder):
• A sample Laravel application showing how the package integrates within a real app.
• Includes typical Laravel folders (app, config, routes, etc.) which are used to test and demonstrate the package in action.
• Tests (tests folder):
• Contains architectural tests and service tests ensuring the package behaves as expected.
• Configuration (config folder and publishable config inside demo_app/config):
• Houses any config used to customize the package behavior (likely published using vendor:publish).
Relationships and Interactions
• When a developer executes a Laravel "make:" command (e.g., php artisan make:model), the package’s Event Listener is triggered.
• The Service Provider (registered in the package) hooks the listener into Laravel’s event system.
• The Listener then calls the service layer to kick off the appropriate commands:
• It invokes the CommandRunner services (like PintRunner and IdeHelperRunner) to run external processes for code formatting and generating helper files.
• The Dependencies Checker verifies if the optional dependencies (Pint and IDE Helper) are installed. If not, it may bypass running them.
• The Facade exposes these functionalities so that other parts of the Laravel app (or even developers) can interact with the code formatter commands if needed.
Architectural Patterns and Design Principles
• Inversion of Control (IoC) via Service Providers, which is standard in Laravel.
• Separation of concerns (listeners, service classes, and runners are distinct, making each component focused on its individual responsibility).
• The use of event-driven architecture (reacting to Laravel artisan commands) to trigger subsequent actions.
• Extensibility: Optional dependencies let the package provide enhanced functionality without forcing them on projects that don’t require it.
Technologies, Frameworks, and Libraries
• Laravel Framework (with its artisan command and service container).
• Laravel Pint (for automatic code formatting).
• barryvdh/laravel-ide-helper (for generating IDE helper files).
• Composer for dependency management.
• Docker is also present, indicating containerization support for development or testing.
• Testing frameworks (PHPUnit/Pest) as indicated by the tests folder and phpunit.xml.dist.
• Use clear labels for each component (e.g., “Service Provider,” “Event Listener (PostCommandCodeFormatter),” “CommandRunner – PintRunner,” “Laravel Pint,” “IDE Helper Runner,” “Demo App”).
• From “Artisan Command” → “Service Provider” → “Event Listener.”
• From “Event Listener” → “Service Layer” (CommandProcessService, CommandRunner).
• From “Service Layer” → “External Tools” (Laravel Pint, IDE Helper).
• The demo application environment which illustrates the integration.
• References to configuration and testing components separately.
• Follow it with service provider registration then branch into the “PostCommandCodeFormatter” listener.
• Listener to the services (CommandProcessService and different CommandRunner implementations such as PintRunner and IdeHelperRunner).
• Also incorporate testing components and Docker based on the file tree if necessary.