The Request/Response Cycle

When User A decides he want to pay a visit to http://example.com/ it all begins with a Request. A short moment later he is given a Response. In this cycle Request-Response a lot is going on, in different frameworks it’s decoupled in different components among them Routing, Dispatching, etc.

I’m looking to make a simple experimental MVP Framework for my learning, trying to use as many best practices, heck who knows it might even be worth using when I’m done.

I’m not sure how I should decouple this cycle in to these different components and I’m not even sure of what each component is responsible for (Thinking SOLID, DRY, SRP, etc). That is what I am asking, looking at different frameworks these components seem to have different use-areas from time to time.

What is each of these components responsible for and in what order are the used?

Request, Response, Dispatcher, Router, Front Controller, Bootstrap, Events.

Bootstrap

The bootstrap file is the entry point of your application (index.php). It contains code in the global scope (and this is the only place, where that should be the case). In an outline, it does

  • create a request object from the request
  • create a response object according to the requested resource type
  • ask the router for the responsible controller for the current request
  • create the controller and call its main method, providing it with the request and respond objects (this often is called dispatching)
  • echo the response

Request

The request object is used to abstract from the web environment. In the end, it is just a data container (often a copy of $_REQUEST) that allows you make subsequent calls to other controllers (see HMVC).

Response

The response object is managing the output. You may have different response classes for XHTML, HTML5, PDF, JSON, …, you_name_it with an identical interface. It is responsible for messaging warnings and errors to the user, too.

Router

The router knows, which controller is assigned to which kind of URL. Given the request, it makes a decision about the controller and returns that to the bootstrap.

Dispatcher

A dispatcher is used in different situations. You may think of it like a map and call thingest. For our case, the bootstrap file and the router together make up a dispatcher. A dispatcher is also used to map events to the various event handlers (plugins) and execute them (often using the Observer pattern).

Front Controller

A dispatcher mapping URLs to controllers and executing them dependend on the request is also called a front controller.

Events

the event mechanism is used to decouple systems. You can for example create plugins that take influence on the result of the router. The only thing you have to do for that is to dispatch some events (eg. onBeforeRoute or onAfterRoute) in the routing method. onBeforeRoute would get the request and could change it, before the router even looks at it; onAfterRoute would be able to change the router’s output. This is just a small example of whjat you can do with events.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật