On 27 February 2014 21:01, Philip G <guice...@gmail.com> wrote:

> On Thu, Feb 27, 2014 at 11:48 AM, Marco Pivetta <ocram...@gmail.com>wrote:
>
>>
>> On 27 February 2014 20:37, Philip G <guice...@gmail.com> wrote:
>>
>>> I'm creating a new ServiceManager instance and a abstract_factory
>>> instance
>>> is failing to load.
>>>
>>> Found out the root of the issue is $services->has('Config')  fails within
>>> Zend\Db\Adapter\AdapterAbstractServiceFactory::getConfig() line number
>>> 71.
>>>
>>
>> That is normal - such a factory was thought to be used in the context of
>> a standard ZF2 Zend\Mvc based application
>>
>
> Ah. Then abstract_factory should be moved into Zend\Mvc, or
> zend-servicemanager needs to become non-dependent on Zend\Mvc auto-sets.
>

Not really. That abstract factory just relies on a "Config" service (that
is an array or ArrayObject) - it does not depend on Mvc components.



>
>
>
>>
>> I would have assumed new ServiceManager(new Config()); would have
>>> automatically set the Config service to the Config I passed in ...
>>> apparently, it does not.
>>>
>>>
>> Automagic is not a good idea here ;-)
>>
>
> I can get that. But, I'm intentionally using Zend\ServiceManager and
> Zend\Db conjointly for this functionality. It shouldn't be assuming I'm
> using it within context of Zend\Mvc, a non-explicit dependency.
>
>
No, the only assumption is that there is a "Config" service. It's a fairly
simple assumption, and easy to fix. Factories are scrap code, they rely on
other services and are in general not nice. Moving this factory to Zend\Mvc
brings no real advantage IMO.


>
>
>>
>>
>>
>>> One solution is to add this line, within
>>> Zend\ServiceManager\Config::configureServiceManager():
>>> --
>>>         $serviceManager->setService('Config', $this->config);
>>> --
>>>
>>> However, I'm unaware of the implications to that. 'Config' is obviously
>>> being set somewhere else for abstract_factory to pass unit tests. But
>>> where? I'm running a very slim-down, component-by-component, based app; I
>>> only import zend-servicemanager, zend-db, and zend-http.
>>>
>>>
>> The "Config" service is usually defined by Zend\Mvc:
>> https://github.com/zendframework/zf2/blob/df6fa23483c990f3ac47400f7191a337d979b5ac/library/Zend/Mvc/Service/ConfigFactory.php
>>
>> The factory is registered in the ServiceListenerFactory:
>> https://github.com/zendframework/zf2/blob/df6fa23483c990f3ac47400f7191a337d979b5ac/library/Zend/Mvc/Service/ServiceListenerFactory.php#L44
>>
>> Cheers,
>>
>>
>>
> So, what happened is Zend\ServiceManager has became dependent on Zend\Mvc.
> Oops! Looks like some work needs to be done within Zend\ServiceManager. ;)
>

No, it's not up to the ServiceManager to define services. The service
manager is an empty box once shipped.


>
> I am 100% properly creating a new ServiceManager instance, without any
> conflicts or issues within any other component of ServiceManager.
> abstract_factory should to be updated so that it, too, isn't dependent on
> Zend\Mvc.
>

As specified above, it depends on a service, not on a component.

>
> I'll look into it, too, but this is a new piece to me I just discovered
> today -- seemed to fit my needs (I have 3 different db adapters I need to
> manage ... owie!). And I don't know all the potential implications or
> thought-process around the design decisions for abstract_factory. At the
> base, abstract_factory needs to become config aware upon
> $sm->addAbstractFactory().
>
>
Not sure what you mean here...




Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Reply via email to