[prev in list] [next in list] [prev in thread] [next in thread] 

List:       horde
Subject:    Re: [horde] Horde_Rdo - getAdapter() method more flexible
From:       Chuck Hagenbuch <chuck () horde ! org>
Date:       2010-01-25 1:44:19
Message-ID: 20100124204419.Horde.2f3mjtphsksgcswockkgk0s4 () technest ! org
[Download RAW message or body]

Quoting Elier Delgado <elier.delgado@gmail.com>:

> Hi Chuck, thanks for your previous answer.
>
> I'm designing a Driver to manage some related mappers and Rdo_Base
> subclasses (related tables),
> so could share the same adapter, but override the getAdapter() method
> seem not flexible
> If I needed 2 instances of my Driver with 2 different adapters.
>
> By all allowed way, the Adapter for the Mapper will be fixed.
>
> To allow this I must give Adapter or connection data by params, but
> the Mapper constructor
> do not allow params, specially in the Mapper created for relationships.
>
> Well, I put a $_params attribute in my base Mapper and allow the
> access from the Rdo_Base subclasses,
> I pass the connection data to Mappers constructors and the
> getAdapter() create the adapter from $_params:
>
> $this->_params['adapter'] = 'pdo_' . $this->_params['phptype'];
> return Horde_Db_Adapter::factory($this->_params);
>
> And when the Mapper is created for relationships I provide the params:
>
> if (isset($rel['mapper'])) {
>     $m = new $rel['mapper']($this->params);
>     //$m = new $rel['mapper']();
>
> Well, that worked, but which are your opinion ?
> There is another way to do that without modify Horde_Rdo_Base ?

I think how I would approach this now is:

- change the Horde_Rdo_Mapper constructor to take the  
Horde_Db_Adapter_Base object as a parameter.
- create Mappers using Horde_Injector, so that you can use binders or  
factories to create mappers with a specific adapter based on the  
injector's settings
- the setAdapter/getAdapter methods would go away entirely

I'll try and move the codebase in this direction in the near future.

-chuck
-- 
Horde mailing list - Join the hunt: http://horde.org/bounties/#horde
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: horde-unsubscribe@lists.horde.org
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic