首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在解析工厂时未找到Laminas (ex Zend Framework 3)类

在解析工厂时未找到Laminas (ex Zend Framework 3)类
EN

Stack Overflow用户
提问于 2020-03-17 19:05:31
回答 1查看 1.1K关注 0票数 1

我被这个问题搞糊涂了.

我有一个带有工厂的模块表,用于我的最后一个类"Entreprise“

所以在module/Tables/config/module.config.php

代码语言:javascript
复制
<?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;
             }
}

module/Tables/Modules.php

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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中(composer转储-自动加载完成)

代码语言:javascript
复制
...
      "autoload": {
            "psr-4": {
                "Application\\": "module/Application/src/",
                "Tfirst\\": "module/Tfirst/src/",
                "Tables\\": "module/Tables/src/"
            }
        },
...

和在SERVER/config/modules.config.php的根配置中

代码语言:javascript
复制
...
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',
......

和错误转储

代码语言:javascript
复制
  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()

..。有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2020-03-18 21:50:57

好的..。我发现我错了..。

实际上,我将旧的Zend2目录结构与新的Zend3教程(以及现在的Laminas)混合在一起,所以命名空间是错误的。

更正前:我的结构目录是:

(即型号:) modules/Tables/src/Tables/Model

新的结构是

(例如,对于模型:)工厂的modules/Tables/src/Model idem,等等...

总会有错误,但这是另一个问题...

我结束这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60721094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档