【问题标题】:Laminas (ex Zend Framework 3) class not found resolving factoryLaminas(前 Zend Framework 3)类未找到解析工厂
【发布时间】: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


    【解决方案1】:

    好的...我发现我的错误...

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

    修正前:我的结构目录是:
    (即模型:)modules/Tables/src/Tables/Model

    新结构是
    (即模型:)modules/Tables/src/Model 工厂的同上等......

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

    我关闭问题。

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      相关资源
      最近更新 更多