Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

rahuldroy
Copy link

Fixes deprecated warnings when using newer versions of Zend Framework

$userMapper,
$adminUserService,
$zfcUserOptions
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant u put this in a separate factory class?
This makes that this line is also cachable and can make it faster.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yepp agreed. The only reason i did it this was was to maintain consistency with services.config.php..

Did you still want me to create separate factories?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes cause this makes caching impossible.
Just like ithere scenario you mentioned

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well create factories for services.config.php as well while I am at it.

I'll try to get whatever I can do done today if not then tomorrow.

@stijnhau
Copy link

stijnhau commented Jul 3, 2016

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.

@Danielss89
Copy link
Owner

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

@rahuldroy
Copy link
Author

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
Copy link
Author

@Danielss89 done

@rahuldroy rahuldroy mentioned this pull request Jul 13, 2016
@stijnhau
Copy link

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

@rahuldroy
Copy link
Author

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

@stijnhau
Copy link

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

@Danielss89
Copy link
Owner

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

@stijnhau
Copy link

@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

@rahuldroy
Copy link
Author

So what is the final verdict then?

@Danielss89
Copy link
Owner

Agree with @stijnhau

@stijnhau
Copy link

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.

@rahuldroy
Copy link
Author

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

@stijnhau
Copy link

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();

@Danielss89
Copy link
Owner

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.

@stijnhau
Copy link

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

@@ -15,7 +15,8 @@
"require": {
"php": ">=5.3.3",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::class is used and this is since php 5.5

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you want me to remove the usage of ::class and use FQDN strings instead? or update composer.json to require PHP 5.5 instead?

I prefer the later as Zend\ServiceManager has required PHP 5.5 since 2.6

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im also More a fan of going to 5.6

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since 5.3 end of life has been in mid 2014, I think we should at least use 5.5 as a compromise though it's also reached it end of life already.
see: http://php.net/supported-versions.php

@stijnhau
Copy link

stijnhau commented Aug 3, 2016

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

@XCame
Copy link

XCame commented Nov 15, 2016

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

@stijnhau
Copy link

stijnhau commented Jun 18, 2017

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants