Quantcast

ZF2 Service Manager problems after RC1 update...

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

ZF2 Service Manager problems after RC1 update...

travis
This post has NOT been accepted by the mailing list yet.
I just updated to the latest version of ZF2 and had a few changes to make to get things to work.  But, there's one problem I can't figure out.

I have a module that exposes several factories via the module's getServiceConfig() method.  (Btw, the latest documents still refer to this method as getServiceConfiguration().)  I know that this is being called.  It looks like this:

    public function getServiceConfig()
    {
        return array(
            'factories' => array(
                    'my_event_service' => function ($sm) {
                        $service = new Service\Event();
                        $service->setEventMapper($sm->get('myEventMapper'));
                        return $service;
                    },

Now, I have an Application module that has a factory method for an "events" controller that will try to get and assign the aforementioned event service to the new controller.  It lives in the Application module's module.config.php file and looks like this:

return array(
    'controllers' => array(
        'factories' => array(
            'index' => function ($sm) {
                $controller = new Application\Controller\IndexController();
                return $controller;
            },
            'events' => function ($sm) {
                $controller = new Application\Controller\EventController();
                $controller->setEventService($sm->get('my_event_service'));
                return $controller;
            },

The problem is that the $sm->get('my_event_service') call blows up.  It does not seem to be able to figure out how to get said service.  Here's the exception message: "Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for my_event_service"

Now, this was working before I updated.  I'm also using zfcUser and having no problem doing similar things with zfcUser services/resources.  I have tried to move the factory for my_event_service into its module's module.config.php file and have had the same results.

I'm guessing I'm missing some small, but obviously important piece somewhere, but I don't know what/where it is.

As I've stated, this was working fine before the update to RC1.  I have shown that the getServiceConfig() call is being made (by simply echoing output just prior to the array being returned).  I have also shown that the closure isn't being called at all (which I've done by echoing some text and exiting immediately...and this is never reached).  I've also used the service manager's canCreate() method to try to validate whether or not my_event_service can be created...it returns false.  (I may not be using this correctly, though, so I'm not sure how important this is.)

So...any ideas?  What might I be missing?  Is there any other code that I can post to help answer some of my questions?

Thanks in advance for any help.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2 Service Manager problems after RC1 update...

macest
This post has NOT been accepted by the mailing list yet.
The controllers are now in their own scoped Service Manager so you need to get the parent Service Manager like this:

  return array(
      'controllers' => array(
          'factories' => array(
              'index' => function ($sm) {
                  $controller = new Application\Controller\IndexController();
                  return $controller;
              },
              'events' => function ($sm) {
                  $controller = new Application\Controller\EventController();
-                 $controller->setEventService($sm->get('my_event_service'));
+                 $controller->setEventService($sm->getServiceLocator()->get('my_event_service'));
                  return $controller;
              },
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2 Service Manager problems after RC1 update...

travis
Wow...!  Such a small, yet significant change....and it worked...!

Thanks.

So...within the context of the controllers, we "need to get the parent service manager"...?  Is this documented anywhere?

Thanks again.  I have been banging my head trying to make sure all my ducks were in a row, which they were, it seems.  So, this was a bit of a surprise.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2 Service Manager problems after RC1 update...

weierophinney
Administrator
-- travis <[hidden email]> wrote
(on Monday, 30 July 2012, 11:24 AM -0700):
> Wow...!  Such a small, yet significant change....and it worked...!
>
> Thanks.
>
> So...within the context of the controllers, we "need to get the parent
> service manager"...?  Is this documented anywhere?

Not yet. It will be soon. :)

That said, it was in the changelog, though nobody really reads those. :)

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ZF2 Service Manager problems after RC1 update...

travis
This post has NOT been accepted by the mailing list yet.
Hi Matthew,

You know...I did read the last one.  It is because I read it that I immediately knew why all of my calls to XxxConfiguration were failing...because they were changed to XxxConfig.  I either didn't catch the piece that was important or I didn't connect the dots.  Who knows...?

Either way...great work.  I love working with ZF2 since it really promotes best practices.  Not only do I get to work with a framework that does things in ways I like...but I am also learning as I go.  Great stuff...!

Thanks.
Loading...