Roave / zf2-for-1

Enables using Zend Framework 2 features in a Zend Framework 1 application.
BSD 2-Clause "Simplified" License
34 stars 17 forks source link

Make ZF1 bootstrap lazy? #8

Open croensch opened 9 years ago

croensch commented 9 years ago

The basic features mention

What if my ZF2 modules don't need this? I thought about bootstrapping zf2 first and all remaining resources only in the case that it makes a fallback to ZF1. To do that i had to make some modifications.

index.php

$application->bootstrap('Zf2')->run();

\Zf2for1_Resource_Zf2 called a blank bootstrap() before the fallback, based on a triggered zf2 event.

    public function onBootstrap()
    {
        return;
    }

\Zf2for1\Application\Zf2Bootstrap so i put it into the other event (and also moved the part with the frontcontroller).

    public function run()
    {
        $application = $this->getResource('zf2');
        $config = $application->getServiceManager()->get('Config');

        if ($config['zf2_for_1']['silent_zf1_fallback'] === true) {
            $application->getEventManager()->attach('zf1', array($this, 'parentRun'));
        }

        return $application->run();
    }

    public function parentRun($event)
    {
        $this->bootstrap();
        $front = $this->getResource('frontcontroller');
        $front->setParam('bootstrap', $this);
        return Zend_Application_Bootstrap_Bootstrap::run();
    }

I guess now even if a ZF2 module would need ZF1 resources it could just chain the call bootstrap('X')->getResource('X') while ZF1 modules can work as they were.

Any good reasons against this?

Xerkus commented 9 years ago

Due to heavy use of singletons and statics in ZF1 the only way to achieve consistent state is to bootstrap everything before running application. Same holds true if Zf2for1 is used.

Idea of this package is to provide refactoring path to zf2 instead of complete rewrite. That means that zf1 model and various resources must be made available to zf2 application and that means zf1 must be bootstrapped.