我正在尝试为我的控制器实现工厂:
class NumberControllerFactory implements FactoryInterface{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new NumberController($container->get(Bar::class));
}
public function createService(ServiceLocatorInterface $services)
{
return $this($services, NumberController::class);
}
}
我收到错误:
Fatal error: Declaration of Number\Factory\NumberControllerFactory::__invoke() must be compatible with Zend\ServiceManager\Factory\FactoryInterface::__invoke(Interop\Container\ContainerInterface $container, $requestedName, array $options = NULL) in C:\xampp\htdocs\MyProject\module\Number\src\Number\Factory\NumberControllerFactory.php on line 10
我需要这个,因为我想将模型注入控制器,因为服务管理器已从 Zend 3 中的控制器中删除。
我使用了https://framework.zend.com/manual/2.4/en/ref/installation.html中描述的骨架
在 composer.json 中是:
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-component-installer": "^1.0 || ^0.3 || ^1.0.0-dev@dev",
"zendframework/zend-mvc": "^3.0.1",
"zfcampus/zf-development-mode": "^3.0"
},
我不明白这个问题,我阅读了很多教程,例如:
https://zendframework.github.io/zend-servicemanager/migration/
请你帮帮我好吗?
我猜目前这种方法与 Zend\ServiceManager\Factory\FactoryInterface::__invoke 兼容