ZF2 : ServiceLocatorAwareInterface is deprecated a

2019-07-23 15:26发布

How can fix it (zend version 2.5) ?

ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along with the ServiceLocatorAwareInitializer. Please update your class Teacher\Controller\TeacherController to remove the implementation, and start injecting your dependencies via factory instead

I tried :

class TeacherControllerFactory implements FactoryInterface
    {
        public function __invoke(ContainerInterface $container, $name, array $options = null)
        {
            return new TeacherController(
                $container->getServiceLocator()->get(TeacherService::class)
            );
        }

        /**
         * Create and return TeacherController instance
         *
         * For use with zend-servicemanager v2; proxies to __invoke().
         *
         * @param ServiceLocatorInterface $container
         * @return TeacherController
         */
        public function createService(ServiceLocatorInterface $container)
        {
            return $this($container, TeacherController::class);
        }
    }

2条回答
甜甜的少女心
2楼-- · 2019-07-23 15:49

Have a look here. The patch is already merged. Here is the link to the patch.

This Link helped me to inject dependencies right.

查看更多
看我几分像从前
3楼-- · 2019-07-23 15:54

You need add ~E_USER_DEPRECATED

You can add in the public/index.php

ini_set ( "error_reporting", E_ALL & ~ E_DEPRECATED & ~E_USER_DEPRECATED  & ~ E_STRICT );

or

error_reporting ( E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED & ~ E_STRICT );

User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().

http://php.net/manual/en/errorfunc.constants.php

查看更多
登录 后发表回答