ServiceManager can't find 'Config' service.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ServiceManager can't find 'Config' service.

Philip Gabbert
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.

My code:

 ---
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
/// ....
        $this->sm = new ServiceManager(new
Config(require('../config/app.php')));
 ---

app.php has:
 --
    'db' => [
        'adapters' => [
            'trackingDb' => [
                'driver' => 'pdo',
                'dsn' =>
'cassandra:host=127.0.0.1,host=192.168.10.214;version=3.0.0',
                'username' => null,
                'password' => null,
                'dbname' => 'overload',
                'options' => array(1012 /* PDO::CASSANDRA_ATTR_THRIFT_DEBUG
*/ => true),
            ],
            // ... More DBs
        ],
    ],
    'abstract_factories' => array(
        'Zend\Db\Adapter\AdapterAbstractServiceFactory',
    ),
 --

$this->sm->get('trackingDb'); fails because $services->has('Config'); fails.

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.

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.



---
Philip
[hidden email]
http://www.gpcentre.net/
Reply | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Marco Pivetta
On 27 February 2014 20:37, Philip G <[hidden email]> 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

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 ;-)



> 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,



Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/
Reply | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Philip Gabbert
On Thu, Feb 27, 2014 at 11:48 AM, Marco Pivetta <[hidden email]> wrote:

>
> On 27 February 2014 20:37, Philip G <[hidden email]> 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.



>
> 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.



>
>
>
>> 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. ;)

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.

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().

---
Philip
[hidden email]
http://www.gpcentre.net/
Reply | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Stefano Torresi
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Marco Pivetta
In reply to this post by Philip Gabbert
On 27 February 2014 21:01, Philip G <[hidden email]> wrote:

> On Thu, Feb 27, 2014 at 11:48 AM, Marco Pivetta <[hidden email]>wrote:
>
>>
>> On 27 February 2014 20:37, Philip G <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Philip Gabbert
In reply to this post by Stefano Torresi
On Thu, Feb 27, 2014 at 12:38 PM, Stefano Torresi
<[hidden email]>wrote:

> If you look at its code, the abstract factory is just looking for a 'db'
> array key from different sources, 'Config' service being one of them.


From what I saw, it only looked from the 'Config' service. The code
immediately returns if $sm->has('Config') fails. If passes, then it starts
checking for 'db' and 'abstracts' sub-services.

---
Philip
[hidden email]
http://www.gpcentre.net/
Reply | Threaded
Open this post in threaded view
|

Re: ServiceManager can't find 'Config' service.

Philip Gabbert
In reply to this post by Marco Pivetta
On Thu, Feb 27, 2014 at 12:44 PM, Marco Pivetta <[hidden email]> wrote:

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

Okay, I'm understanding this "Config" service a little more. I was under
the impression ServiceManager\Config would automatically configure all its
sub-components with the config data passed in. I don't really see how this
is an invalid assumption, though.


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...
>

At the point of adding abstract factory classes to the ServiceManager, it's
a reasonable assumption you would be passing in itself or the defined
configuration. However, I have seen the ambiguity on my part:
AdapterAbstractServiceFactory under Zend\Db needs a 'db' key to be defined,
which wouldn't be under the 'service_manager' sub-key. Adding complexities
when having to discover 'db' location from outside of the ServiceManager
package.

I did find a solution now, however:

My config file actually already had a config service defined:
...
    'services' => [
        'app.config' => [
           // .. Add my application configs here.
        ],
    ],
...

Just changing the name to 'Config' actually worked. ;)

It would be nice to add in the documentation, then, for the Db
AbstractServiceFactory, it is dependent on a 'Config' service of some type,
whether it be a factory service, or just a 'services' => 'Config' => [] in
the config file.

---
Philip
[hidden email]
http://www.gpcentre.net/