gpt4 book ai didi

namespaces - Composer 包未出现在 autoload_namespaces 中

转载 作者:行者123 更新时间:2023-12-04 16:56:23 24 4
gpt4 key购买 nike

这应该是一件容易的事。我开发了一个名为 MyVendor\MyPackage 的包

MyVendor\MyPackage是:

  • MyVendor\MyPackage\composer.json
  • MyVendor\MyPackage\MyClass.php
  • MyVendor\MyPackage\composer.json文件包含:
    {
    "name":"MyVendor/MyPackage",
    "description":"MyClass!!!",
    "keywords": ["MyKeyword"],
    "homepage": "http://MyPackage.com",
    "type":"library",
    "license": "MIT",
    "authors": [
    {
    "name": "ME",
    "email": "ME@ME.com",
    "homepage":"http://ME.com"
    }
    ],
    "require": {

    },
    "autoload":{
    "psr-4" : {
    "MyVendor\\MyPackage\\":""
    }
    }
    }

    现在我有另一个项目叫 MyOtherPackage谁的 composer.json文件看起来像:
    {
    "require": {
    "monolog/monolog": "1.2.*",
    "MyVendor/MyPackage": "1.0.0"
    },
    "autoload": {
    "psr-4": {
    "MyVendor\\MyOtherPackage\\": "MyOtherPackage/",
    "MyVendor\\": "/"
    }
    },
    "repositories": [
    {
    "type": "package",
    "package": {
    "name": "MyVendor/MyPackage",
    "version": "1.0.0",
    "source": {
    "url": "https://ME.com/svn/MyVendor/MyPackage/",
    "type": "svn",
    "reference": "trunk"
    }
    }
    }
    ]
    }

    所以 MyOtherPackage 依赖于 MyPackage。一切都下载得很好,但如果我打开 autload_namespaces.php,它只包含 monolog。它看起来像这样:
    return array(
    'Monolog' => array($vendorDir . '/monolog/monolog/src'),
    );

    为什么不是 MyVendor/MyPackage出现在 namespaces.phpautoload_psr4.php文件?是 composer.json文件错误?

    编辑 我添加到 MyPackage composer.json 文件中。

    最佳答案

    我已经想通了。似乎将存储库定义为一个包,我告诉 Composer 它不是一个与 Composer 兼容的类,这意味着 Composer 不会寻找 composer.json 文件。

    为了修复它,我删除了包定义并使依赖类的 composer.json 文件看起来像:

    {
    "require": {
    "monolog/monolog": "1.2.*",
    "MyVendor/MyPackage": "1.0.0"
    },
    "autoload": {
    "psr-4": {
    "MyVendor\\MyOtherPackage\\": "MyOtherPackage/",
    "MyVendor\\": "/"
    }
    },
    "repositories": [
    {
    "type": "svn",
    "url": "https://ME.com/svn/MyVendor/MyPackage/",
    "reference": "tags"
    }
    ]
    }

    这告诉 Composer 从这个存储库下载包并查找 composer.json 文件。

    关于namespaces - Composer 包未出现在 autoload_namespaces 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21716281/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com