4

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?

peterh
  • 11,875
  • 18
  • 85
  • 108
DaGhostman Dimitrov
  • 1,608
  • 20
  • 44

2 Answers2

7

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.

Community
  • 1
  • 1
tereško
  • 58,060
  • 25
  • 98
  • 150
3

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

dynamic
  • 46,985
  • 55
  • 154
  • 231
  • so it is more like an autoloader than a big technique, am I getting this correct ? – DaGhostman Dimitrov Nov 09 '12 at 16:29
  • More and less. Autoloader can be called more than once for each requests... bootstrapping will be executed only once before any controllers code – dynamic Nov 09 '12 at 16:30
  • so lets say It like that the Bootstrapper making requests additional files than the defined. lets say it like this: The user writes the autoloader and the boot strap and the bootstrapper requests additional files needed by the application and makes the autoloader request them. Correct ? – DaGhostman Dimitrov Nov 09 '12 at 16:33
  • Bootstrap and autoloader are two different thing. Autoloader is called whenever your request an undefined class like this: $var = new MyCustomClass(); You can of course instanciate new object in the bootstrap – dynamic Nov 09 '12 at 16:36
  • http://www.developer.com/lang/php/article.php/3829776/Build-your-own-MVC-Framework---Step-One-Getting-Started.htm – dynamic Nov 09 '12 at 16:39