Skip to content
Advertisement

How to implement bootstraping class in a PHP framework?

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?

Advertisement

Answer

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:

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement