How andrejrs/php-mvc-example works
Identifying the Main Components
• Front Controller/Entry Point: Located under public/index.php. This is where all incoming HTTP requests are directed.
• Core Classes (in the src directory): These include key abstractions like Controller, Model, Request, Router, Validator, View, and others. They encapsulate the core functionality of the MVC framework.
• Application Layer (in the App directory):
– Controllers (e.g., App/Controllers/Home.php): Handle incoming requests.
– Models (e.g., Customer, Order, OrderItem, Statistic in App/Models): Represent the business data and interaction with the database.
– Views (e.g., the page templates in App/Views/Page and App/Views/Template.php): Manage how information is presented.
– Routing / Namespacing (App/Routes.php and App/Namespaces.php): Define the routes and namespace mapping used by the framework.
• Configuration (in the Config directory): Contains files like Application.php and Database.php that set up configuration parameters for the application and database.
• Database & Seeder: The database directory holds SQL dumps and seed classes (e.g., OrderSeeder.php) to initialize test data.
• Public Assets: Located in the public directory, including assets like CSS, JavaScript (dashboard.js), and .htaccess for server configurations.
Relationships and Interactions
• The Request (src/Request.php) then processes input data, which is passed to the Router (src/Router.php) to determine the appropriate controller from App/Controllers.
• Controllers leverage Models (from App/Models) to interact with the database, guided by configuration parameters from the Config directory.
• After processing, controllers hand off data to Views (in App/Views) to generate user output.
• The Seeder (from seeder or database/seed files) provides a one-off use case to populate the database.
• The configuration and core components ensure that the MVC layers remain loosely coupled.
Architectural Patterns and Design Principles
• MVC Pattern: The separation of concerns is explicit—Controllers process requests, Models handle database logic, and Views take care of presentation.
• Front Controller: All traffic passes through a single entry point (public/index.php) before being directed to the proper route.
• Autoloading and Namespacing: The src/Psr4AutoloaderClass.php, together with App/Namespaces.php, demonstrates adherence to PSR-4 standards.
• Dependency Centralization: Configuration and database connection settings are centrally maintained in the Config directory.
Including Technologies and Frameworks
• PHP (tested on PHP 7.1.14).
• MySQL for database operations.
• Web servers: Apache or Nginx.