作曲家-私有软件包未进入自动装带器 [英] Composer - Private package not getting into autoloader

查看:60
本文介绍了作曲家-私有软件包未进入自动装带器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个自定义包,它位于我们的GitLab存储库中,这是它的composer.json:

I've created a custom package and it's sitting on our GitLab repository, here's the composer.json for it:

{
    "name": "TeamScanblox/InternalAPI_Ref",
    "description": "",
    "keywords": [
        "swagger",
        "php",
        "sdk",
        "api"
    ],
    "homepage": "http://swagger.io",
    "license": "proprietary",
    "authors": [
        {
            "name": "Swagger and contributors",
            "homepage": "https://github.com/swagger-api/swagger-codegen"
        }
    ],
    "require": {
        "php": ">=5.5",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-mbstring": "*",
        "guzzlehttp/guzzle": "^6.2"
    },
    "require-dev": {
        "phpunit/phpunit": "^4.8",
        "squizlabs/php_codesniffer": "~2.6",
        "friendsofphp/php-cs-fixer": "~2.12"
    },
    "autoload": {
        "psr-4": { "InternalAPI\\Ref\\" : "lib/" }
    },
    "autoload-dev": {
        "psr-4": { "InternalAPI\\Ref\\" : "test/" }
    }
}

这是它的文件夹顶层结构:

This is the folder top level structure for it:

我将其包含为 TeamScanblox / InternalAPI_Ref:我需要的顶级项目的composer .json中的 *,问题是它不会通过PSR-4自动解析并包含在该项目中。包含它并起作用的唯一方法是在项目的 psr-4中添加 InternalAPI\Ref\: vendor / TeamScanblox / InternalAPI_Ref / lib /。这是为什么?我做错了/不正确地进行了自动加载?

I'm including it as "TeamScanblox/InternalAPI_Ref": "*" in composer .json of the top project I need it in, and the problem is that it doesn't get automatically parsed and included via PSR-4 in that project. The only way to have it included and working is adding "InternalAPI\Ref\": "vendor/TeamScanblox/InternalAPI_Ref/lib/" in the "psr-4" in the project. Why is that? What have I done wrong/not doing right to have it autoloaded?

我将其包含在项目的composer.json中,如下所示:

I have it included in project' composer.json as follows:

{
  "type": "package",
  "package": {
    "name": "TeamScanblox/InternalAPI_Ref",
    "version": "1.0.0",
    "type": "package",
    "source": {
      "url": "git@gitlab.com:TeamScanblox/InternalAPI_Ref.git",
      "type": "git",
      "reference": "master"
    }
  }
}


推荐答案

如果使用<$ c将库包含在应用程序中$ c> package 类型,那么在该 package 描述中必须提及Composer关于该库的所有信息,包括自动加载和任何其他要求。

If you include your library in an application by using the package type, then everything Composer knows about that library has to be mentioned in that package description, including the autoloading and any other requirements.

通常,仅当您不能更改代码来源时,才应使用此软件包。幸运的是,您可以完全控制库的存储库,只需将Composer指向它即可。

Usually this package should only be used if you cannot change the source where the code is coming from. Luckily, you have full control over the repository of your library, you should simply point Composer to it.

"repositories": [{
    "type": "vcs",
    "url": "ssh://git@somewhere/path/repo.git"
}]

使用此示例代替 type: package ,Composer将联系存储库并读取它的 composer.json ,检测所有依赖项和自动加载,然后像安装任何外部软件包一样安装它。

Use this example instead of "type": "package", and Composer will contact the repository and read it's composer.json, detect all dependencies and the autoloading, and install it just like any external package.

请注意,您必须添加您使用的每个内部存储库。 Composer不遵循库的存储库指针,它们都必须在应用程序的根 composer.json 中复制

Note that you have to add every internal repository that you use. Composer does not follow the library's repository pointers, they all have to be duplicated in the root composer.json of your application.

这篇关于作曲家-私有软件包未进入自动装带器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆