找不到Composer自定义私有软件包

时间:2020-08-04 21:25:00

标签: php composer-php

我有一个私有的软件包回购,我正试图在我作为作曲家软件包的公司内发布该软件。

我已使用以下composer.json文件创建了软件包:

{
    "name": "my_team/package_name",
    "description": "Package Description",
    "homepage": "https://git.company.com/MyTeam/package_name",
    "type": "library",
    "license": "Proprietary",
    "minimum-stability": "stable",
    "version": "1.4",
    "require": {
        "php": ">=7.1.0",
        "ext-curl": "*",
        "ext-json": "*"
    },
    "autoload": {
        "psr-4": {
            "PackageNamespace\\": "src/"
        }
    }
}

该软件包中的所有路径都是正确的,并且我已经在Enterprise Github Repo上创建了一个Tag and Release,其中包含该软件包的zip文件位于v1.4。

我想测试该程序包是否正常工作,所以我创建了一个测试脚本来运行它,它具有以下composer.json文件:

{
    "name": "benjam/test",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "my_team/package_name",
                "version": "1.4",
                "dist": {
                    "type": "zip",
                    "url": "https://git.company.com/MyTeam/package_name/archive/v1.4.zip"
                }
            }
        }
    ],
    "require": {
        "my_team/package_name": "1.4"
    }
}

和一个包含以下内容的main.php文件:

<?php

require __DIR__ . '/vendor/autoload.php';

$obj = new PackageNamespace\ClassName();

当我尝试运行该文件时,出现以下错误:

PHP Fatal error:  Uncaught Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php:5
Stack trace:
#0 {main}
  thrown in C:\Development\test\main.php on line 5

Fatal error: Uncaught Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php on line 5

Error: Class 'PackageNamespace\ClassName' not found in C:\Development\test\main.php on line 5

Call Stack:
    0.2130     353200   1. {main}() C:\Development\test\main.php:0

因此,作曲家自动加载器似乎看不到已安装的软件包。

我做错了什么?

我尝试过的其他测试脚本composer.json设置是:

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "my_team/package_name",
                "version": "1.4",
                "source": {
                    "type": "git",
                    "url": "https://git.company.com/MyTeam/package_name",
                    "reference": "origin/master"
                }
            }
        }
    ],

1 个答案:

答案 0 :(得分:0)

我遇到的问题是,在标记发行版时,Github自动生成的zip文件在存档的顶层中没有composer.json文件。

由于作曲者使用该文件中的信息来创建自动加载设置,因此它已成功导入和安装了程序包,但未设置自动加载设置。

我将测试脚本composer.json文件更改为以下文件,并且可以正常工作:

(请注意,回购中有一个名为v1.4的标签)

{
    "name": "benjam/test",
    "repositories": [
        {
            "type": "vcs",
            "url": "git@git.company.MyTeam/package_name.git"
        }
    ],
    "require": {
        "my_team/package_name": "v1.4"
    }
}