Generic factory method pattern for Zend Framework 2 serviceLocator

Hello all,

I noticed that new versions of PhpStorm include this nice feature: http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

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?

Thanks,
Dejan

2 comments

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 http://youtrack.jetbrains.com/issue/WI-10959 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');

0

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

0

Please sign in to leave a comment.