【发布时间】:2020-03-17 11:05:31
【问题描述】:
我迷失了这个问题......
我有一个带有工厂的模块表,用于我的最后一课“企业”
所以在module/Tables/config/module.config.php
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED ... :-( ');
$entreprise = new Entreprise();
return $enteprise;
}
}
模块/表/Modules.php
<?php
namespace Tables;
class Module
{
public function getServiceConfig()
{
return [
'factories' => [
'EntrepriseTableGateway' => function ($sm)
{
...
...
$e=$sm->get(\Service\Entreprise::class);
// Here is the problem
// \Service\Entreprise is resolved
// as Tables\Service\Factory\EntrepriseFactory as expected
// but Tables\Service\Factory\EntrepriseFactory is not found...
这是工厂流程----module/Tables/src/Tables/Service
包含Entreprise.php(但此时问题不在这里)
----/module/Tables/config/module.config.php
<?php
return array(
'service_manager' => [
// the resolution works...
// but the final class is not found...
'invokables' => [
Service\Entreprise::class => \Tables\Service\Factory\EntrepriseFactory::class,
]
]
);
module/Tables/src/Tables/Service/Factory.php
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED !!!');
$entreprise = new Entreprise();
return $entreprise;
}
}
在composer.json(作曲家转储-自动加载完成)
...
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"Tfirst\\": "module/Tfirst/src/",
"Tables\\": "module/Tables/src/"
}
},
...
在SERVER/config/modules.config.php的根配置中
...
return [
'Laminas\Db',
'Laminas\Di',
'Laminas\Mvc\Plugin\FilePrg',
'Laminas\Mvc\Plugin\FlashMessenger',
'Laminas\Mvc\Plugin\Identity',
'Laminas\Mvc\Plugin\Prg',
'Laminas\Session',
'Laminas\Mvc\I18n',
'Laminas\Mvc\Console',
'Laminas\Form',
'Laminas\Hydrator',
'Laminas\InputFilter',
'Laminas\Filter',
'Laminas\I18n',
'Laminas\Cache',
'Laminas\Router',
'Laminas\Validator',
'Application',
'Tables',
'Tfirst',
......
还有错误转储
Error
File:
/home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:31
Message:
Class 'Tables\Service\Factory\EntrepriseFactory' not found
Stack trace:
#0 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(765): Laminas\ServiceManager\Factory\InvokableFactory->__invoke()
#1 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(201): Laminas\ServiceManager\ServiceManager->doCreate()
#2 /home/vagrant/Code/yeting/SERVER/module/Tables/src/Module.php(246): Laminas\ServiceManager\ServiceManager->get()
...有什么建议吗?
【问题讨论】:
标签: service factory zend-framework3