Issues

ZF-7951: Add allow bootstrap dependent resources

Issue Type: New Feature Created: 2009-09-24T08:00:58.000+0000 Last Updated: 2012-07-28T21:21:16.000+0000 Status: Closed Fix version(s): Reporter: Kasian Andrii (kandy) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Application

Related issues: Attachments:

Description

Add allow bootstrap dependent resources in config resources.{resourcename}.dependencies[] = Db resources.{resourcename}.dependencies[] = FrontController or

<pre class="highlight">
class System_Application_Resource_Modules extends Zend_Application_Resource_ResourceAbstract
{

    protected $_dependencies = array('FrontController');



<pre class="highlight">
/**
 * Class for bootstrap dependent resources
 *
 * @author Andrii Kasian 
 * @package system.application.resource
 */
abstract class System_Application_Resource_ResourceAbstract extends Zend_Application_Resource_ResourceAbstract
{
     * List of dependent resources
    protected $_dependencies = array();

     * Set list of dependent resources
    public function setDependencies($dependencies)
    {
        $this->_dependencies =$this->mergeOptions($this->_dependencies, (array) $dependencies);
    }

    /**
     * Get list of dependent resources
     * @return array
     */
    public function getDependencies()
    {
        return $this->_dependencies;
    }


    /**
     * Add dependent resource
     * @param string $dependency
     */
    public function addDependency($dependency)
    {
        $this->_dependencies[] = $dependency;
    }

    /**
     * Clear dependent resource
     * @param string $dependency
     */
    public function clearDependencis($dependency)
    {
        $this->_dependencies = array();
    }

     * Bootstrap dependent resources
    public function bootstrapDependencies()
    {
        foreach ($this->getDependencies() as $dependency){
            $this->getBootstrap()->bootstrap($dependency);
        }
    }

    public function init()
    {
        $this->bootstrapDependencies();
    }
}

Comments

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-09-24T17:07:15.000+0000

Could you maybe explain the idea of this? What does it try to accomplish that cannot be done with zend_app already?

Posted by Kasian Andrii (kandy) on 2009-09-25T12:32:15.000+0000

{quote}Zend_Application provides a bootstrapping facility for applications which provides reusable resources, common- and module-based bootstrap classes and dependency checking.{quote} If resource a depend b, and b depend c then I must first write first c, then b and a. It's simple if dependence static ( in code $this->getBootstrap()->bootstrap('Dependet resource')), but if dependencies dynamic it's can lead to errors.

For example: I have load acl rules. In config I write:

<pre class="highlight">
resource.acl.adapter = Config
resource.db.adapter = Pdo_Mysql

Then i have load acl from database I change adapter, set to db "resource.acl.adapter = Db" and get error. I need write "resource.db.adapter = Pdo_Mysql" before "resource.acl.adapter" It is not hard, but program can do better :)
Example: I write

<pre class="highlight">
resource.acl.adapter = Db
resource.acl.dependencis[] = Db
resource.db.adapter = Pdo_Mysql

And all is beautiful :))

PS: SORRY, for my bad English

Posted by Ben Scholzen (dasprid) on 2009-09-25T12:38:03.000+0000

Ressources can already define depencies by themself

Posted by Matthew Weier O'Phinney (matthew) on 2009-09-25T12:49:50.000+0000

There is already a mechanism for this built into ZF. Instead of being configuration driven, however, we require that the dependency is called as part of the resource. For example, if you write an ACL resource that depends on the DB resource, it might look like this:

<pre class="highlight">
class My_Resource_Acl extends Zend_Application_Resource_ResourceAbstract
{
    public function init()
    {
        $this->getBootstrap()->bootstrap('db');
        $db = $this->getBootstrap()->getResource('db');
        ....
    }
}

Basically, calling the bootstrap() method with the name of a resource is how you enforce dependencies. Using configuration seems to me to add some unnecessary and unwanted magic to the situation; the dependencies should be defined at the resource level, not configuration.

Posted by Albulescu Cosmin (albulescu) on 2012-07-28T21:21:16.000+0000

@Ben Scholzen - Yes Ben, resources can already define dependinces, but the Zend_Application_Resource_Session should bootstrap the multidb resource when session database save handler requested. You can make this from the settings ini for eg, but when you should have session first defined and then multidb is not working.

Maybe a Zend_Application_Resource_ResourceBootstrapper sould fix this.

Cosmin

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts