How nativephp/laravel works
Main Components
• Laravel Integration Layer:
• HTTP Interface: Controllers, routes (see the routes/api.php and the controllers in src/Http/Controllers) to accept web requests and dispatch events.
• Middleware: The “src/Http/Middleware/PreventRegularBrowserAccess.php” indicates a layer that restricts or manages access, typical to web routes.
• Service Provider: The “NativeServiceProvider.php” in both the src and resources (as a stub) registers the NativePHP services with Laravel’s container.
• Artisan Commands: Located in “src/Commands”, these provide CLI interactions to manage the application lifecycle (e.g., booting, debugging, migrating, seeding, etc.).
• NativePHP Desktop Services:
• Core Desktop Classes: Classes like “src/App.php”, “src/System.php”, “src/WindowManager.php”, “src/Windows/Window.php”, “src/Dock.php”, and “src/Notification.php” represent the underlying native desktop functionalities.
• Event Handling: The “src/Events” directory is organized by context (App, ChildProcess, Menu, MenuBar, PowerMonitor, Windows, etc.), implementing an event-driven or observer pattern.
• Facades: Wrappers in “src/Facades” (e.g., Alert, ChildProcess, Window, etc.) provide a static interface to the underlying services, consistent with Laravel’s design.
• Contracts, DTOs, and Data Objects support loose coupling and clear interfaces between components.
• Configuration and Resources:
• The “config” directory contains configuration files (for example, “nativephp.php” and “nativephp-internal.php”) which control the behavior of the integration.
• Resource stubs and views offer scaffolding and canned components which help in bootstrapping or customizing the native services.
• Testing & Quality Assurance:
• The “tests” directory houses PHPUnit tests that cover aspects such as HTTP endpoints, facade behavior, event handling, and more.
• Static analysis (phpstan.neon) and workflow configurations under the “.github” directory reflect CI/CD and style validation.
Relationships and Interactions
• Laravel’s container and service provider mechanism integrates the desktop services into the Laravel ecosystem.
• HTTP requests from routes (invoked via controllers) interact with the desktop services; for example, a controller may trigger an event that the NativePHP layer listens for to open a new window or display a notification.
• The facade pattern simplifies access to the native functionalities from various parts of the Laravel application.
• Commands in the “src/Commands” directory allow for performing application-wide actions (like configuration loading or database migrations) with direct access to the native desktop interface.
Architectural Patterns and Principles
• Separation of Concerns: The project is clearly divided between the Laravel web/application side (HTTP controllers, middleware, routes) and the native desktop functions (windows, menus, notifications, system events).
• Facade Pattern: Use of facades in “src/Facades” abstracts and simplifies complicated underlying logic.
• Event-Driven Architecture: The “src/Events” structure outlines how various desktop or application state events are triggered and handled.
• Dependency Injection & Contracts: The “src/Contracts” and “src/Support” directories underline the commitment to loose coupling and adherence to well-defined interfaces.