How does bootstrap work in general, and in particular in the Zend Framework?

Im reading the Zend Framework manual and cannot understand how the boot process works especially in ZF and in general. They write:

The Bootstrap class defines which resources and components of initialization.

Ok This means that you must first create an instance of the Bootstrap class. But then they write about the ini configuration file. And there are directives about the Bootstrap class itself in it:

 1. bootstrap.path = APPLICATION_PATH "/Bootstrap.php" 2. bootstrap.class = "Bootstrap" 

So, as I understand it, this means that the Bootstarp class is not the first to be created. First of all, something should read the configuration file, get information about the Bootstrap class, and get this information to instantiate. Otherwise, there is no need to have Bootstrap class information in the configuration file. Because I can just do this:

 require_once(/application/bootstrap.php) $b = new Bootstrap(); 

and an instance of Bootstrap.

But they do not say anything about what they read the configuration file, and then creates an instance of Bootstrap .

  • How does bootstrap work?
  • Who creates the instance and at what stage?
  • They say that APPLICATION_PATH is a constant. A constant must be defined somewhere before it can be used. Where can it be defined if used in the Bootstrap class?

Thanks.

+4
source share
2 answers

If you look at the index.php file that comes with ZF, this should answer most of these questions.

The APPLICATION_PATH constant is defined in index.php , and this also creates a Zend_Application object that simply loads the application and launches it.

There are two ways to tell your Zend_Application where your boot block is located in ZF1.

The first method (explicitly installed):

 $application = new Zend_Application( APPLICATION_ENV, array( 'bootstrap' => array( 'class' => 'Bootstrap', 'path' => APPLICATION_PATH . '/Bootstrap.php', ), 'config' => APPLICATION_PATH . '/configs/application.ini', ) ); 

In the above example, the bootstrap class and bootstrap script are passed as part of the $options constructor directly to Zend_Application along with the application.ini file.

If you put the bootstrap class and the script in your application.ini file, you can initialize Zend_Application as follows:

 $application = new Zend_Application( APPLICATION_ENV, array('config' => APPLICATION_PATH . '/configs/application.ini') ); 

Zend_Application will process the application.ini file and collect Bootstrap information from there.

Then you can call $application->bootstrap()->run(); to run the application.

To answer your questions:

  • The boot application configures your application. After processing your ini file, this is the first thing to do. This installs all the necessary components for your ZF application (e.g. Front Controller, Zend_View, Layouts, DB connection, etc.).
  • index.php copies it at the very beginning at the very beginning.
  • APPLICATION_PATH defined directly in index.php
+6
source

Here is my short explanation:

Bootstrap initializes the resources of the framework, initializes the configuration of the framework, loads the classes and other work on preparing the framework, runs in each request, starting with the index.php file in the default configuration.

  • The first index.php is called where the APPLICATION_PATH constant is defined and passed to the constructor of the Application class.
  • An instance of the application class created in the constructor framework reads the configuration file and saves it for later use.
  • Then the bootstrap of the platform begins:

    I. An instance of the Application / Bootstrap class has been created (the Framework begins to create the necessary plug-ins, resources that were defined in your * .ini file.)

    II. Picks up your custom bootstrap class and initializes methods with the init prefix.

    III. Loads the FrontController resource, and the front controller starts the process of dispatching requests (loads the module, controller, views, calls plugins callbacks).

In general, you can track everything yourself, starting with the index.php file, then to the library and try to understand which classes are loaded, in which order.

+2
source

All Articles