Composer - Private package not getting into autoloader

二次信任 提交于 2020-02-25 01:35:50

问题


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:

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?

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"
    }
  }
}

回答1:


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.

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"
}]

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.

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.



来源:https://stackoverflow.com/questions/58208991/composer-private-package-not-getting-into-autoloader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!