_InitX () functions are called sequentially

In my bootstrap.php, I have many _initX () functions, and some of them may contain code that depends on the code in the previous initX

protected function _initAutoloading() { }
protected function _initViewInitializer() { }
protected function _initVariables() { }

So my question is: are these _init functions guaranteed in the order in which they were declared?

+3
source share
3 answers

EDIT. , , , , , ReflectionObjects:: getmethods() get_class_methods PHP, , PHP Zend , , , .

, / : $bootstrap->bootstrap(array('foo', 'bar')); , Zend Application , .

, , $bootstrap ('foo') "bar" ( _init *())

, , , , _init *().

, Zend Application doc

+4

, :

var $init_us = array(
    "_initAutoloading",
    "_initViewInitializer",
    "_initVariables",
);

function __construct() {
    foreach ($this->init_us as $fn) { 
        $this->{$fn}();
    }
}

ZF, __construct _initOrderedList _initFunctions _myinit... - .

+1

manual. :

If the resource depends on another resource, it must call bootstrap () in its code to ensure that the resource is executed. Subsequent calls will then be ignored.

Here is a sample code:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initRequest()
    {
        // Ensure the front controller is initialized
        $this->bootstrap('FrontController');

        // Retrieve the front controller from the bootstrap registry
        $front = $this->getResource('FrontController');

        $request = new Zend_Controller_Request_Http();
        $request->setBaseUrl('/foo');
        $front->setRequest($request);

        // Ensure the request is stored in the bootstrap registry
        return $request;
    }
}

You do not need to rely on the order.

+1
source

Source: https://habr.com/ru/post/1773864/


All Articles