[horde] Horde_Rdo - getAdapter() method more flexible
Chuck Hagenbuch
chuck at horde.org
Mon Jan 25 01:44:19 UTC 2010
Quoting Elier Delgado <elier.delgado at 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
More information about the horde
mailing list