Generic factory method pattern for Zend Framework 2 serviceLocator

Hello all,

I noticed that new versions of PhpStorm include this nice feature:

That page explains how to deal with static method. However, in ZF2, I continually type things like:

$object = $this->getServiceLocator()->get('someFactoryName');

Is there a way to map someFactoryName to a class so autocomplete can work on $object in the metadata file?


Comment actions Permalink

Hi there,

Automatically (like it's done for static methods, e.g. Mage::getModel('admin/user'); ) -- No (since ATM it's implemented for static methods only).

I guess when will be implemented, this would work for ZF as well.

In meantime -- only manual code hinting, e.g.

/** @var someFactoryClass $object */

$object = $this->getServiceLocator()->get('someFactoryName');

Comment actions Permalink

Thanks for the quick reply! Ok, I'll wait patiently for this feature :)


Please sign in to leave a comment.