将库添加到symfony项目

gj3fmq9x  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(126)

我通过composer create-project symfony/skeleton:“6.3.*”my_project创建symfony项目,然后创建一个名为shared adding composer.json的库。其想法是让我的库为my_project提供公共代码
composer.json my_project

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,  
  "require": {
        "shared/library": "dev-main" <- my library
    },
    "repositories": [
        {
          "type": "path",
          "url": "../../Shared/"
        }
      ],
}

字符串
composer.json共享库

{
    "name": "shared/library",
    "description": "Shared code between microservices",
    "autoload": {
      "psr-4": {
        "Shared\\": "/"
      }
    }
  }


现在使用公共库注册类从库到服务。yaml在本例中注册类用于消息总线
services.yaml

Shared\:
    resource: "../../../Shared/"
  _instanceof:
        Shared\Application\Command\CommandHandlerInterface:
          public: true
          tags:
            - { name: messenger.message_handler, bus: messenger.bus.command }

        Shared\Application\Query\QueryHandlerInterface:
          public: true
          tags:
            - { name: messenger.message_handler, bus: messenger.bus.query }


现在我得到了错误:

**#message: "Compile Error: Cannot declare class Composer\Autoload\ClassLoader, because the name is already in use"**

8iwquhpp

8iwquhpp1#

你不需要资源加载器。

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    _instanceof:
        # services whose classes are instances of CustomInterface will be tagged automatically
        Cwd\TablerBundle\Menu\HasMenuInterface:
            tags: ['tabler.menu_item']
        Cwd\SearchBundle\SearchableInterface:
            tags: ['cwd.searchable']

字符串
InstanceOf就足够了。我一直用这个。

相关问题