Objects that know each other

In the Zend Framework, the Zend_Application object has a bootstrap object to bootstrap or configure a component. In turn, the Boutstrap class has access to the zend_application object to access configuration parameters.
My question is what kind of sample is this or is it the smell of code due to circular dependency.

+7
source share
1 answer

Zend Framework 1 is bloated, that's for sure.

The reason for this $_application , which is a bidirectional relation, is a module that is independent of boot files.

This is strange, I think, because when dealing with modules, instead of having the Zend_Aplication set, you will have the main boot file instead:

 /** * Set application/parent bootstrap * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application * @return Zend_Application_Bootstrap_BootstrapAbstract */ public function setApplication($application) { if (($application instanceof Zend_Application) || ($application instanceof Zend_Application_Bootstrap_Bootstrapper) ) { if ($application === $this) { throw new Zend_Application_Bootstrap_Exception('Cannot set application to same object; creates recursion'); } $this->_application = $application; } else { throw new Zend_Application_Bootstrap_Exception('Invalid application provided to bootstrap constructor (received "' . get_class($application) . '" instance)'); } return $this; } 

There is also a lot of code smell:

 /** * Constructor * * Sets application object, initializes options, and prepares list of * initializer methods. * * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application * @return void * @throws Zend_Application_Bootstrap_Exception When invalid application is provided */ public function __construct($application) { $this->setApplication($application); $options = $application->getOptions(); $this->setOptions($options); } 

The boostrap file needs parameters, so instead of requesting parameters , it expects Zend_Application to receive the following parameters:

 $options = $application->getOptions(); $this->setOptions($options); 

It looks like they just ignore the type of interface expected by the setApplication () method, and it can be one of the following:

  • Zend_application
  • Zend_Application_Bootstrap_Bootstrapper
  • Zend_Application_Bootstrap_ResourceBootstrapper

I would give up trying to understand this mess and switch to ZF 2, though;)

+2
source

All Articles