ZfcUserAdmin icon indicating copy to clipboard operation
ZfcUserAdmin copied to clipboard

Fix "Please be aware that ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0"

Open rahuldroy opened this issue 9 years ago • 19 comments

Fixes deprecated warnings when using newer versions of Zend Framework

rahuldroy avatar Jul 03 '16 13:07 rahuldroy

Not a fan actualy of this. You create all teh object and only use them in the required case. I think we need lazy factories over here.

stijnhau avatar Jul 03 '16 13:07 stijnhau

Do you want me to merge this for now? And then you can do another ticket for the factories refactoring.

Danielss89 avatar Jul 12 '16 07:07 Danielss89

oh crap, I completely forgot about this!!

I'll create the factories tonight itself and update this PR. I'll post another comment once I finish

rahuldroy avatar Jul 12 '16 12:07 rahuldroy

@Danielss89 done

rahuldroy avatar Jul 12 '16 15:07 rahuldroy

Those factories are zf2 way. You must use the __invoke method for zf3

stijnhau avatar Jul 13 '16 12:07 stijnhau

Don't think that is a good idea as we want to still keep supporting zf2 apps.

I think you are referring to Zend\ServiceManager\Factory\FactoryInterface which has __invoke but this has only been added in version 3.x.

I guess it comes down to weather we want to drop support for ServiceManager 2.x or not

rahuldroy avatar Jul 13 '16 13:07 rahuldroy

With this change we support SM2 but ot SM3 But you can implement fallback in the create service method and support v2 and v3

stijnhau avatar Jul 13 '16 13:07 stijnhau

@rahuldroy create the __invoke method, and inside, call the other Create method.

Danielss89 avatar Jul 13 '16 14:07 Danielss89

@Danielss89 I think it's better to do the other way around because in that case you just have to drop the createService method when zf2 support is dropped. Also better with the parameters that are passed to those functions

stijnhau avatar Jul 13 '16 14:07 stijnhau

So what is the final verdict then?

rahuldroy avatar Jul 14 '16 12:07 rahuldroy

Agree with @stijnhau

Danielss89 avatar Jul 14 '16 13:07 Danielss89

Not tested or not sure about it but in the createService methiod i think u don't pass the SM but rather an other manager where you first have to call the getService Manageror Locator method on.

stijnhau avatar Jul 14 '16 15:07 stijnhau

@stijnhau, Can you please elaborate on it. I did a very quick test before pushing my changes and it seems to be working fine

rahuldroy avatar Jul 14 '16 15:07 rahuldroy

Can't reley elaborate on it dont know the exact details of it. and cant find it on the web(and no time now to luk deeper) But it has something to do with it not always the service manager that is passed. Sometimes, its a plginmanager or a controllermanager or something like that. maybe @Danielss89 knows more about it.

/* @var ServiceLocatorInterface $serviceLocator */ $serviceLocator = $serviceLocator->getServiceLocator();

stijnhau avatar Jul 15 '16 07:07 stijnhau

Yes, when you are inside a factory for a controller, viewhelper, pluginhelper or formhelper, it is not a service manager being passed, but a pluginmanager. And on that you would have to do $pluginManager->getServiceLocator(); and pass that to the __invoke method. For example in the UserControllerFactory this is true.

Danielss89 avatar Jul 15 '16 07:07 Danielss89

@Danielss89 Thats the reason. I'm just doing it everwhere so i'm sure i always get one ;)

stijnhau avatar Jul 15 '16 10:07 stijnhau

Havn't had any time to test it but most of it seems good.

stijnhau avatar Aug 03 '16 12:08 stijnhau

Any chance, that this gets merged? I think that the composer update and the ::class changes could then be done in another PR. But at least we would get rid of the deprecated warnings

XCame avatar Nov 15 '16 10:11 XCame

@rahuldroy Trying to use your versions but getting fatal ;(

Fatal error: Declaration of ZfcUserAdmin\Factory\Service\UserMapperFactory::__invoke($container, $requestedName, ?array $options = NULL) must be compatible with Zend\ServiceManager\Factory\FactoryInterface::__invoke(Interop\Container\ContainerInterface $container, $requestedName, ?array $options = NULL) in C:\Program Files (x86)\Zend\ZendServer\data\apps\http\__default__\0\True-Life\1.0.0_32\vendor\danielss89\zfc-user-admin\src\ZfcUserAdmin\Factory\Service\UserMapperFactory.php on line 9

Seems like you're not setting the typehint for the first paramater. Can you fix asap so i can continue testing?

stijnhau avatar Jun 18 '17 19:06 stijnhau