[Solar-talk] Proposal: Remove namespace to Solar::loadClass()/factory()
Antti Holvikari
anttih at gmail.com
Tue Nov 7 09:47:56 PST 2006
On 11/7/06, Travis Swicegood <development at domain51.com> wrote:
> Hi Antti,
>
> Antti Holvikari wrote:
> > On 11/7/06, Travis Swicegood <development at domain51.com> wrote:
> >
> >> Howdy all,
> >>
> >> One thing in Solar that's been bugging me is the concrete class
> >> dependencies that it has. Code like this makes me cringe:
> >>
> >> $sql = Solar::factory('Solar_Sql');
> >>
> >> My whole problem with it is that it creates a dependency on Solar_Sql
> >> and keeps me to inserting my own Domain51_Sql code. My solution, as
> >> Paul has heard many (he would add "many, many" I believe) times is some
> >> sort of Dependency Injection model where you don't request the class,
> >> but it's interface.
> >>
> > Sorry if I have completely missed your point but doesn't
> > Solar::dependency() do the job?
> >
>
> Yes and no. dependency() serves a similar purpose, but is different in
> that you must specify what you want to get back. Generally that's done
> via config, so it is configurable, but what I am suggesting is that you
> request "Sql" and get back the first matching object in a vendor's
> namespace called "Sql".
I see your point now :-)
> So, assuming Solar is the only registered namespace:
>
> $sql = Solar::factory('Sql');
> // $sql instance of Solar_Sql
One way of doing this could be to create predefined registry key
mappings like so:
$config['Solar']['registry'] = array(
'request' => 'Vendor_Request',
);
then Solar would need to check what request class to instantiate when
it needs one. Defaults would be the native solar classes and in the
config file you could define your own.
--
Antti Holvikari <http://phphalo.com>
More information about the solar-talk
mailing list