How to implement bootstraping class in a PHP framework?

社会主义新天地 提交于 2019-12-05 01:20:49

问题


Hey guys I am making my own MVC framework (please do not downvote me because everyone wants to make a framework.) and so.. I want to make a bootstrapping class like I have seen in many frameworks. I am making this because I have decided to move to the next level by started learning a framework from the inside. But I am facing few problems getting through them. But I will separate them in different questions. Now to clarify my question: What features should a Bootstrapping class have? And Can you give me articles that could help me?


回答1:


There should not be a "bootstrap class". It is a straightforward process, which can be contain in a simple script, which would serve as entry point for your application. PHP is not Java, therefore you are not require to contain everything within a class.

Usually bootstrap stage of application would have following responsibilities:

  • set up the autoloader
  • initialize routing mechanism
  • configure storage abstractions (db, cache, etc.)
  • handle the user request (using the routing)
  • dispatch to MVC

The bootstrap stage in you application is where all the wiring between objects should be set up. It would also be the place where you set up such things as loggers, access control and error handling structures.

You could say that front controller is a part or bootstrapping.

P.S.: also, you might find this answer of mine relevant, since it also contains an example of bootstrap file.


List of recommended articles:

  • GUI Architectures by Martin Fowler
  • Inversion of Control Containers and the Dependency Injection pattern by Martin Fowler
  • A Description of the Model-View-Controller User Interface Paradigm in the Smalltalk-80 System
  • Understanding JavaServer Pages Model 2 architecture
  • MVP: Model-View-Presenter The Taligent Programming Model for C++ and Java

The last two links cover two of 3 major MVC-inspired patterns (Model2 MVC and MVP), since classical MVC is actually highly impractical (and actually, almost impossible) to be used for web applications.




回答2:


Bootstrapping is just a piece of code that will by executed for each requests.
You can place a function or an object whenever you like more according to your framework dir structure.

It must not have some particular features



来源:https://stackoverflow.com/questions/13311864/how-to-implement-bootstraping-class-in-a-php-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!