|
Hi all,
After a long day of reviewing, debugging and fixing with Matthew, the ServiceManager MVC integration has been merged into master. Most modules will probably be broken after this update. Aside from a few small changes, you can largely continue utilizing DI as you have been if you'd like, or you can refactor your module to utilize the patterns provided by the new Zend\ServiceManager. You can even use a little bit of both if you'd like. I'm not going to spend time explaining how to actually use the new ServiceManager stuff, but rather just outline the main BC-breaks so that you can get your code functioning again. There will be docs and other info coming soon In your module config/module.config.php you'll need to change how you have your routes defined: Before: 'di' => array( 'instance' => array( 'Zend\Mvc\Router\RouteStackInterface' => array( 'parameters' => array( 'routes' => array( /* routes here */ ) ) ) ) ) After: 'router' => array( 'routes' => array( /* routes here */ ) ) You will also need to change how you add your module's view script path to the path stack and how you register view helpers: Before: 'di' => array( 'instance' => array( 'Zend\View\Resolver\TemplatePathStack' => array( 'parameters' => array( 'paths' => array( 'zfcuser' => __DIR__ . '/../view', ) ) ), 'Zend\View\HelperLoader' => array( 'parameters' => array( 'map' => array( 'zfcUserIdentity' => 'ZfcUser\View\Helper\ZfcUserIdentity', 'zfcUserLoginWidget' => 'ZfcUser\View\Helper\ZfcUserLoginWidget', ) ) ) ) ) After: 'view_manager' => array( 'template_path_stack' => array( __DIR__ . '/../view' ), 'helper_map' => array( 'zfcUserIdentity' => 'ZfcUser\View\Helper\ZfcUserIdentity', 'zfcUserLoginWidget' => 'ZfcUser\View\Helper\ZfcUserLoginWidget' ) ) If you were registering any controller plugins with DI, you'll need to change how you're doing that as well: Before: 'di' => array( 'instance' => array( 'Zend\Mvc\Controller\PluginLoader' => array( 'parameters' => array( 'map' => array( 'zfcUserAuthentication' => 'ZfcUser\Controller\Plugin\ZfcUserAuthentication' ) ) ) ) ) After: 'controller' => array( 'map' => array( 'zfcuserauthentication' => 'ZfcUser\Controller\Plugin\ZfcUserAuthentication', ) ) Additionally, if you are using any of the interfaces in Zend\Module for your Module classes, know that Zend\Module is now Zend\ModuleManager and that the interfaces are now under Zend\ModuleManager\Feature (they've also been renamed per the new interface naming conventions). Finally, we are now also checking is_callable on the methods, so implementing the Feature interfaces is now optional. Also remember that the new Zend\Form has been merged so if you had a module using the old forms, it's probably broken now. If I think of anything else, I'll add it in a response to this thread. Be sure to thank Matthew and Ralph for all of their hard work getting this together for us! --- Evan Coury, ZCE http://blog.evan.pro/ |
|
Another thing: if you have a bootstrap event listener in your Module
class, you'll need to change the identifier from 'bootstrap' to 'application': Before: $moduleManager->events()->getSharedManager()->attach('bootstrap', 'bootstrap', array($this, 'initSomething')); After: $moduleManager->events()->getSharedManager()->attach('application', 'bootstrap', array($this, 'initSomething')); However, there's actually another feature now: if you have a public method named onBootstrap in your Module class, the module manager will automatically attach it as a listener to the bootstrap event for you, so you no longer have to do this yourself in init(). -- Evan Coury |
|
This post has NOT been accepted by the mailing list yet.
Hi , so how can we modify such a function :
public function initSomething(\Zend\EventManager\Event $e) { $app = $e->getParam('application'); $locator = $app->getLocator(); $aclService = $locator->get('ZfcAcl\Service\Acl'); ... } Fatal error: Call to undefined method Zend\Mvc\Application::getLocator() |
|
In reply to this post by EvanDotPro
David,
On Fri, May 18, 2012 at 3:36 AM, <[hidden email]> wrote: > > Hi , so how can we modify such a function : > > public function initSomething(\Zend\EventManager\Event $e) { > $app = $e->getParam('application'); > $locator = $app->getLocator(); > $aclService = $locator->get('ZfcAcl\Service\Acl'); > ... > } > > Fatal error: Call to undefined method Zend\Mvc\Application::getLocator() If you want to continue to pull it via DI like before: public function initSomething(\Zend\EventManager\Event $e) { $app = $e->getParam('application'); $locator = $app->getServiceLocator(); $di = $locator->get('Di'); $aclService = $di->get('ZfcAcl\Service\Acl'); ... } However, in theory, the service locator should fall back to DI, so you should be able to simply do the following without any trouble: public function initSomething(\Zend\EventManager\Event $e) { $app = $e->getParam('application'); $locator = $app->getServiceLocator(); $aclService = $locator->get('ZfcAcl\Service\Acl'); ... } -- Evan Coury |
|
This post has NOT been accepted by the mailing list yet.
Ok so i think a made something wrong somewhere because into my code
$app is instance of Zend\Mvc\Application so getServiceLocator() is not a method of this class. I'm checking this. |
|
In reply to this post by EvanDotPro
On Fri, May 18, 2012 at 4:34 AM, Evan Coury <[hidden email]> wrote:
> David, > > On Fri, May 18, 2012 at 3:36 AM, <[hidden email]> wrote: >> >> Hi , so how can we modify such a function : >> >> public function initSomething(\Zend\EventManager\Event $e) { >> $app = $e->getParam('application'); >> $locator = $app->getLocator(); >> $aclService = $locator->get('ZfcAcl\Service\Acl'); >> ... >> } >> >> Fatal error: Call to undefined method Zend\Mvc\Application::getLocator() > > If you want to continue to pull it via DI like before: > > public function initSomething(\Zend\EventManager\Event $e) { > $app = $e->getParam('application'); > $locator = $app->getServiceLocator(); > $di = $locator->get('Di'); > $aclService = $di->get('ZfcAcl\Service\Acl'); > ... > } > > However, in theory, the service locator should fall back to DI, so you > should be able to simply do the following without any trouble: > > public function initSomething(\Zend\EventManager\Event $e) { > $app = $e->getParam('application'); > $locator = $app->getServiceLocator(); > $aclService = $locator->get('ZfcAcl\Service\Acl'); > ... > } Correction: $app->getServiceLocator(); should be $app->getServiceManager(); at least in zf2 master as of writing this. -- Evan Coury |
|
This post has NOT been accepted by the mailing list yet.
Thank you Evan,
Now i get the following error: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ZfcAcl\Service\Acl |
|
In reply to this post by EvanDotPro
Hi all,
Another change has been merged into master which will require you to update your modules. The view layer has been updated to be namespace-aware, so the script path it will look for is now "<top-namespace>/<controller-name>/<action>", lowercase, dash-separated. -- Evan Coury |
|
Hi all,
I was just reminded by booradleys in IRC that we have enacted a decision from one of our meetings to drop 'config' from the filename of files in ./config/autoload/*. You'll now need the files in there to match this glob pattern: "config/autoload/{,*.}{global,local}.php" for them to be loaded. -- Evan Coury |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by EvanDotPro
Evan, Is there a way to use aliases? for example: 'alias' => array( 'acl' => 'ZfcAcl\Service\Acl', ), $aclService = $locator->get('acl'); Thanks! |
|
This post has NOT been accepted by the mailing list yet.
I got it sorted out, I just didn't realize that Di config stays intact =) |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by EvanDotPro
> However, in theory, the service locator should fall back to DI, so you
> should be able to simply do the following without any trouble: Hi Evan, how exactly the ServiceManager fallback to Di works? It seems necessary to explicitly get the Di instance from the service manager like $di = $serviceManager->get('dependencyInjector'); (which registers the Di abstract factory in the service manager) and only then the fallback works. Is this the intended behaviour? If so is there a way to configure the service manager to enable the fallback to Di automatically (i.e. so that it is not necessary to get the Di from the SM explicitly)? Thanks, David
David Lukas (dlu-gs)
www.zfdaily.com |
| Powered by Nabble | Edit this page |
