Zend Expressive:激活服务时出现内部服务器错误 500

Zend Expressive: Internal Server Error 500 when activating the Service in Action

请大家帮忙理解
在标准应用程序 CRUD 中,在连接 Service:
/src/App/Panel/Service/CategoriesService.php
in Action:
/src/App/Panel/Action/PanelCategoriesAction.php 时发生 500 error
link 到存储库:https://github.com/drakulitka/expressive.loc.git
Zend Expressive + Doctrine

对不起我的英语

你在这里混淆了一些东西。这应该是您的实体:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="categories")
 * @ORM\Entity(repositoryClass="App\Entity\Repository\CategoriesRepository")
 */
class Categories
{
}

在文档注释中,它告诉 Doctrine 在哪里可以找到自定义存储库 class。 Doctrine 会为您加载它。 存储库不需要构造函数。 Doctrine 会为您解决这个问题。

<?php

namespace App\Entity\Repository;

use App\Entity\Categories;
use Doctrine\ORM\EntityRepository;

class CategoriesRepository extends EntityRepository implements CategoriesRepositoryInterface
{
    // No constructor here

    public function fetchAll()
    {
        // ...
    }
}

然后你的工厂看起来像这样:

<?php

namespace App\Panel\Factory;

use Doctrine\ORM\EntityManager;
use Interop\Container\ContainerInterface;
use App\Entity\Categories;

class CategoriesRepositoryFactory
{
    /**
     * @param ContainerInterface $container
     * @return CategoriesRepository
     */
    public function __invoke(ContainerInterface $container)
    {
        // Get the entitymanager and load the repository for the categories entity
        return $container->get(EntityManager::class)->getRepository(Categories::class);
    }
}

在您使用的配置中:

<?php

return [
    'dependencies' => [
        'invokables' => [
        ],
        'abstract_factories' => [
        ],
        'factories' => [
            App\Entity\Repository\CategoriesRepositoryInterface::class => App\Panel\Factory\CategoriesRepositoryFactory::class,
        ],
    ],
];