I'm developing a ZF2 system and it was working very well, but after I clone the repository in other computer this deprecated error has appeared:
You are retrieving the service locator from within the class Module\Controller\Controller. Please be aware that ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along with the ServiceLocatorAwareInitializer. You will need to update your class to accept all dependencies at creation, either via constructor arguments or setters, and use a factory to perform the injections. in /home/path/project/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php on line 258
The composer.json:
"require": {
"php": ">=5.5",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"zendframework/zendframework": "~2.5",
"doctrine/doctrine-orm-module": "0.*",
"hounddog/doctrine-data-fixture-module": "0.0.*",
"imagine/Imagine": "~0.5.0"
The error appears when I retrieve the service in my controllers (extending Zend\Mvc\Controller\AbstractActionController):
$this->getServiceLocator()->get("Module\Service\Service");
In the Zend core at Zend\Mvc\Controller\AbstractController is like this:
public function getServiceLocator()
{
trigger_error(sprintf(
'You are retrieving the service locator from within the class %s. Please be aware that '
. 'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
. 'with the ServiceLocatorAwareInitializer. You will need to update your class to accept '
. 'all dependencies at creation, either via constructor arguments or setters, and use '
. 'a factory to perform the injections.',
get_class($this)
), E_USER_DEPRECATED);
return $this->serviceLocator;
}
Before was only this:
public function getServiceLocator()
{
return $this->serviceLocator;
}
I've tried everything, someone know what I've to do?
You will need to update your class to accept all dependencies at creation, either via constructor arguments or setters, and use a factory to perform the injections.
– Saintebeuve