![]() |
VOOZH | about |
This page documents how HTTP requests flow through the Maho application, from the initial entry point through routing, controller dispatch, and response generation. This covers the front controller pattern implementation, request initialization, and the modernized routing system utilizing PHP attributes and Symfony components.
The request flow system handles all incoming HTTP requests to the Maho application. It encompasses:
public/index.php.Mage::run() app/Mage.php639-681Mage_Core_Controller_Varien_Front app/code/core/Mage/Core/Controller/Varien/Front.php158-178#[Route] attribute system and RouteCollectionBuilder lib/Maho/Routing/RouteCollectionBuilder.php15-17Mage_Core_Controller_Varien_Action app/code/core/Mage/Core/Controller/Varien/Action.php16Mage_Core_Controller_Response_Http app/code/core/Mage/Core/Controller/Response/Http.php20-21Maho utilizes a Front Controller pattern where all requests are funneled through a single point and dispatched to specific Action Controllers based on routing rules.
| System Concept | Code Entity | File Path |
|---|---|---|
| App Bootstrap | Mage::run() | app/Mage.php639-681 |
| Request Object | Mage_Core_Controller_Request_Http | app/code/core/Mage/Core/Controller/Request/Http.php20-21 |
| Front Controller | Mage_Core_Controller_Varien_Front | app/code/core/Mage/Core/Controller/Varien/Front.php18 |
| Modern Router | Maho\Routing\ControllerDispatcher | lib/Maho/Routing/ControllerDispatcher.php15-17 |
| Route Definition | #[Maho\Config\Route] | app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34 |
| Action Controller | Mage_Core_Controller_Varien_Action | app/code/core/Mage/Core/Controller/Varien/Action.php16 |
| Response Object | Mage_Core_Controller_Response_Http | app/code/core/Mage/Core/Controller/Response/Http.php20-21 |
Sources: app/Mage.php639-681 app/code/core/Mage/Core/Controller/Varien/Front.php158-178 app/code/core/Mage/Core/Controller/Varien/Action.php102-110 lib/Maho/Routing/ControllerDispatcher.php15-17
Maho has modernized the request and response layer by wrapping Symfony HttpFoundation components. This provides a robust, standard-compliant foundation while maintaining backward compatibility with the legacy API.
Mage_Core_Controller_Request_Http encapsulates a Symfony\Component\HttpFoundation\Request instance app/code/core/Mage/Core/Controller/Request/Http.php31 It provides proxy methods like getParam() which checks internal $_params, POST ($this->symfonyRequest->request), GET ($this->symfonyRequest->query), and route attributes in sequence app/code/core/Mage/Core/Controller/Request/Http.php227-255
Mage_Core_Controller_Response_Http encapsulates a Symfony\Component\HttpFoundation\Response instance app/code/core/Mage/Core/Controller/Response/Http.php25 The constructor handles both direct Symfony Response injection and legacy Maho factory arguments app/code/core/Mage/Core/Controller/Response/Http.php77-94 Methods like setHeader() app/code/core/Mage/Core/Controller/Response/Http.php107-129 and setRedirect() app/code/core/Mage/Core/Controller/Response/Http.php137-160 update the internal Symfony object.
Sources: app/code/core/Mage/Core/Controller/Request/Http.php13-31 app/code/core/Mage/Core/Controller/Request/Http.php227-255 app/code/core/Mage/Core/Controller/Response/Http.php13-25 app/code/core/Mage/Core/Controller/Response/Http.php77-94 app/code/core/Mage/Core/Controller/Response/Http.php107-160
Maho introduces a modern routing system based on PHP 8 attributes, integrated with Symfony Routing. This system co-exists with legacy XML routing to provide a migration path and improved developer experience.
Routes are defined using the #[Maho\Config\Route] attribute on controller methods app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34
The Maho\Routing\RouteCollectionBuilder scans the codebase for these attributes and compiles them into optimized PHP artifacts for high performance:
var/cache/maho_url_matcher.php: Compiled Symfony URL matcher.var/cache/maho_url_generator.php: Compiled Symfony URL generator.The Maho\Routing\ControllerDispatcher acts as the bridge between Symfony's router and Maho's action controllers lib/Maho/Routing/ControllerDispatcher.php15-17 It uses the compiled matcher to resolve incoming requests to specific controller classes and methods.
Sources: app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34 lib/Maho/Routing/RouteCollectionBuilder.php15-17 lib/Maho/Routing/ControllerDispatcher.php15-17
The Mage_Core_Controller_Varien_Front::dispatch() method is the heart of the request flow app/code/core/Mage/Core/Controller/Varien/Front.php158-178
Routers are initialized from configuration path web/routers app/code/core/Mage/Core/Controller/Varien/Front.php31 The init() method iterates through these configurations, instantiates router classes, and adds them to the internal collection app/code/core/Mage/Core/Controller/Varien/Front.php125-151 A final default router is always added to handle unmatched requests app/code/core/Mage/Core/Controller/Varien/Front.php148-149 To prevent infinite loops during internal forwarding, Maho enforces a limit of 100 iterations app/code/core/Mage/Core/Controller/Varien/Front.php37
Sources: app/code/core/Mage/Core/Controller/Varien/Front.php125-151 app/code/core/Mage/Core/Controller/Varien/Front.php158-178 app/code/core/Mage/Core/Controller/Varien/Front.php184-206
When a router or the attribute-based dispatcher matches a request, it identifies an Action Controller and an Action Name. The controller is instantiated and its dispatch() method is called.
indexAction or an attributed method) is called.Most controllers use the layout system to generate the response body:
loadLayout(): Initializes layout handles (e.g., default, STORE_code, THEME_area_package_theme, full_action_name) and loads XML updates app/code/core/Mage/Core/Controller/Varien/Action.php213-237addActionLayoutHandles(): Specifically adds handles for store, theme, and the full action name (e.g., catalog_product_view) app/code/core/Mage/Core/Controller/Varien/Action.php243-260Sources: app/code/core/Mage/Core/Controller/Varien/Action.php102-110 app/code/core/Mage/Core/Controller/Varien/Action.php213-237 app/code/core/Mage/Core/Controller/Varien/Action.php243-260
Maho supports two primary routing patterns: Attribute-based and Legacy XML-based.
Defined directly in the controller class. Example from Mage_Adminhtml_Cms_Wysiwyg_ImagesController:
/admin/cms_wysiwyg_images/index app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34Standard URLs follow the FrontName / ControllerName / ActionName pattern.
| Component | Code Implementation | Example (Catalog) |
|---|---|---|
| Front Name | web/routers/{name}/args/frontName | catalog |
| Controller | Mage_{Module}_{Controller}Controller | Mage_Catalog_ProductController |
| Action | {action}Action() | viewAction() |
Sources: app/code/core/Mage/Core/Controller/Varien/Front.php129-143 app/code/core/Mage/Core/Controller/Varien/Action.php188-193 app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34
The final stage of the request flow is sending the response to the client.
setHeader(): Adds or replaces HTTP headers in the Symfony Response object app/code/core/Mage/Core/Controller/Response/Http.php107-129setRedirect(): Sets a 302/301 redirect, dispatches controller_response_redirect, and updates the Symfony status code app/code/core/Mage/Core/Controller/Response/Http.php137-160setBody(): Sets the main content of the response app/code/core/Mage/Core/Controller/Response/Http.php83setBodyJson(): Convenience method to set JSON content and appropriate headers app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php94The sendResponse() method is responsible for sending headers and body via Symfony's internal mechanisms. The Front Controller triggers this at the end of its dispatch() method app/code/core/Mage/Core/Controller/Varien/Front.php174
Sources: app/code/core/Mage/Core/Controller/Response/Http.php107-160 app/code/core/Mage/Core/Controller/Varien/Front.php172-176 app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php94
Refresh this wiki