How rosengate/exedra works
Project Overview
• Type: PHP microframework.
• Purpose: To provide a minimal, flexible and container-based routing system with support for PSR-7/PSR-15 HTTP messages, explicit dependency injection, and middleware.
• Key features include nestable routes, annotated controller actions, middleware-enforced routing groups and minimal, highly modular design.
Identifying Main Components
• Application Core
• The Application class (Exedra/Application.php) is the entry point that bootstraps the framework.
• Configuration
• Config.php (Exedra/Config.php) holds configuration settings.
• Routing System
• Routing: Files under Exedra/Routing (e.g., Route.php, Group.php, CallStack.php, etc.) showcase how routes and groups are defined and linked.
• Routeller: A set of tools and attributes address route annotations and metadata (e.g., Exedra/Routeller/Attributes, RoutellerProvider.php).
• HTTP Layer
• HTTP messages: Exedra/Http includes Request, Response, ServerRequest, Stream, Uri and UploadedFile.
• This layer ensures conformity with PSR-7 and supports middlewares.
• Dependency Injection (Container)
• Container and Registry classes (Exedra/Container) manage services and dependencies.
• Middleware & Runtime
• Runtime: Module (Exedra/Runtime) that includes CallHandler, Context, Redirect.
• Middleware is supported both directly and via the Routes (see the sample code in the README where middleware is applied to route groups).
• Development & Console Utilities
• Console commands (e.g., ServeCommand.php, RouteListCommand.php in Exedra/Console/Commands) for CLI operations.
• Utility & Support Modules
• Supporting classes like Autoloader (Exedra/Support/Autoloader.php), file handling, and wireman for dependency resolution.
• Additional Components:
• Form handling (Exedra/Form), Session management (Exedra/Session), View rendering (Exedra/View) and URL generation (Exedra/Url).
Relationships and Data Flow
• The Application core initializes configuration, loads the dependency injection container, and registers all providers (including routing, session, view, etc.).
• HTTP Requests enter through the HTTP layer where the Request and Response objects are managed.
• The Routing System intercepts the request – matching it to the correct route (or nested group) and then resolving the controller or action. Middleware may wrap the execution flow.
• The container supplies dependencies to controllers, middleware, and other components, ensuring explicit dependency injection.
• Console utilities provide command-based interactions, e.g., serving the application or listing all available routes.
Architectural Patterns and Design Principles
• Modular Architecture: Core responsibilities (routing, HTTP handoff, dependency injection, etc.) are encapsulated in separate directories.
• Nested/Group Routing: Emphasis on nestable route definitions and middleware grouping.
• Interface Contracts: The use of “Contracts” (e.g., Routing, Runtime) promotes a clear separation of interfaces and implementations.
• Explicit Dependency Injection: Dependencies are injected via container-based resolution (no autowiring).
• PSR Compliance: Supports PSR-7/PSR-15 standards for HTTP message handling and middleware.
• Application Core: Starting point for the framework.
• Configuration & Container: Indicate how configuration is linked to dependency injection.
• HTTP Layer: Show a Request entering the system, interacting with the Router.
• Routing & Routing Annotation (Routeller): Show layered routing handling – starting from a Route List, then middleware attachment, and lastly, execution handling.
• Console Tools: Illustrate the alternative command-line interactions (e.g., serving the application, route listing).
• Utility Modules: Optionally showcase support for forms, sessions, URL generation, and views to round out the helper functionalities.