VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/3.2-request-flow-and-front-controller

⇱ Request Flow and Front Controller | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Request Flow and Front Controller

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.


Purpose and Scope

The request flow system handles all incoming HTTP requests to the Maho application. It encompasses:


Architecture Overview

Maho utilizes a Front Controller pattern where all requests are funneled through a single point and dispatched to specific Action Controllers based on routing rules.

Natural Language to Code Entity Mapping: Request Lifecycle

System ConceptCode EntityFile Path
App BootstrapMage::run()app/Mage.php639-681
Request ObjectMage_Core_Controller_Request_Httpapp/code/core/Mage/Core/Controller/Request/Http.php20-21
Front ControllerMage_Core_Controller_Varien_Frontapp/code/core/Mage/Core/Controller/Varien/Front.php18
Modern RouterMaho\Routing\ControllerDispatcherlib/Maho/Routing/ControllerDispatcher.php15-17
Route Definition#[Maho\Config\Route]app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php34
Action ControllerMage_Core_Controller_Varien_Actionapp/code/core/Mage/Core/Controller/Varien/Action.php16
Response ObjectMage_Core_Controller_Response_Httpapp/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


Request and Response Modernization

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.

Request Wrapping

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

Response Wrapping

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


Modern Routing: The #[Route] System

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.

Route Collection and Compilation

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.

Controller Dispatcher

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 Front Controller Dispatch Loop

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

Dispatch Sequence Diagram


Router Initialization

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


Action Controller Execution

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.

Controller Lifecycle

  1. Constructor: Sets the request and response objects and registers itself with the Front Controller app/code/core/Mage/Core/Controller/Varien/Action.php102-110
  2. preDispatch(): A hook for logic that must run before the action (e.g., authentication, SSL checks).
  3. Action Method: The specific method (e.g., indexAction or an attributed method) is called.
  4. postDispatch(): A hook for cleanup or response modification.

Layout Integration

Most controllers use the layout system to generate the response body:

Sources: 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


Routing and URL Structure

Maho supports two primary routing patterns: Attribute-based and Legacy XML-based.

Attribute Routing (Modern)

Defined directly in the controller class. Example from Mage_Adminhtml_Cms_Wysiwyg_ImagesController:

Legacy XML Routing

Standard URLs follow the FrontName / ControllerName / ActionName pattern.



























ComponentCode ImplementationExample (Catalog)
Front Nameweb/routers/{name}/args/frontNamecatalog
ControllerMage_{Module}_{Controller}ControllerMage_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


Response Generation and Output

The final stage of the request flow is sending the response to the client.

Response Methods

Sending the Response

The 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