How mh-shuvo/php-mvc works
Main Components
• Front Controller / Entry Points:
• The public folder represents the document root for web requests. Include files like “public/index.php” which serves as the entry point.
• “app/bootstrap.php” in the app folder that likely initializes the framework.
• Controllers:
• Represented by “app/controllers”, these components process incoming requests. For example, “Pages.php” in this directory serves as a sample controller.
• Views:
• The “app/views” directory includes the UI components (with header and footer within “app/views/inc”) that render data.
• Core Libraries:
• “app/libraries” contains essential framework classes such as “Core.php”, “Controller.php”, “Database.php”, and “Handler.php”. These classes implement routing, base controller functionality, DB interactions, and error handling.
• Configuration:
• “app/config/config.php” holds configuration settings that drive the application behavior.
• Static Assets:
• The “public/css”, “public/js”, and other files such as “public/test.php” represent public-facing assets that support the application interface.
• Infrastructure/Support Files:
• Files like “.htaccess” in both the project root and certain directories suggest rewrite rules and URL routing mechanisms.
Relationships and Interactions
• Data Flow starts at the public/index.php (or test endpoints) that funnels web requests into the application.
• The Bootstrap process (in app/bootstrap.php) configures the environment, loads configuration from app/config, and instantiates Core classes.
• The Core routing (likely inside app/libraries/Core.php) directs the request to the appropriate Controller (as seen in app/controllers) based on the URL.
• The Controller then interacts with Model components (not present in a dedicated “models” folder, so model functionality might be integrated within controllers or via external libraries) and loads the appropriate Views (from app/views).
• The Views render the final output, integrating common components from “app/views/inc”, and delivering the final HTML/CSS/JS to the client.
• The Database and Handler libraries provide supporting functionality for data persistence and error management, respectively.
Architectural Patterns and Design Principles
• MVC Pattern: Separates concerns between Controllers handling requests, Views managing the presentation, and underlying business logic (potentially in models or libraries).
• Front Controller: The public/index.php and bootstrap.php serve as centralized entry points.
• Configuration Management: Centralized configuration stored in app/config.
• Modularity: Segregated directories for controllers, views, libraries, and configuration enhances the maintainability and scalability of the framework.