安装时 Composer 包复制目录

Composer package duplicating directories when installing

我有一个托管在私有 Gitlab 存储库上的本地依赖项。然而,我很难通过 Composer 将其引入我的项目。

我的composer.json:

"require": {
    "crmpicco/GolfBundle": "dev-master"
},
"repositories": [
    {
        "type": "package",
        "package": {
        "name": "crmpicco/GolfBundle",
        "version": "dev-master",
        "source": {
            "url": "https://git.crmpicco.com/rfc1872/golfbundle.git",
            "type": "git",
            "reference": "master"
        },
        "autoload": {
            "psr-4": {
                "crmpicco\GolfBundle\": ""
            }
        }
        }
    }
],

当我查看 vendor 目录时,我不希望目录翻倍,例如 /vendor/crmpicco/GolfBundle/crmpicco/GolfBundle

当我 运行 a composer update crmpicco\GolfBundle 时,当 Symfony 尝试执行 cache:clear:

时出现以下错误

脚本 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 处理 post-update-cmd 事件因异常终止

[运行时异常]
执行“'cache:clear --no-warmup'”命令时出错:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted   
  to load class "crmpiccoGolfBundle from namespace "crmpicco\GolfBundle".         
  Did you forget a "use" statement for "crmpicco\GolfBundle\crmpiccoGolfBundle"?   
  in /var/www/crmpicco/symfony/app/AppKernel.php:31   

我的 composer.json 设置有什么问题 missing/doing?

捆绑目录结构:

/crmpicco
   /GolfBundle
      /Component      
      /DependencyInjection
      crmpiccoGolfBundle.php

捆绑包composer.json:

{
  "name": "crmpicco/GolfBundle",
  "type": "library",
  "description": "A Symfony 2 bundle which provides an easy way to handle billing and subscriptions.",
  "license": "MIT", 
  "require": {
    "php": ">=7.0",
    "symfony/config": "~2.8.34",
    "symfony/dependency-injection": "~2.8.34",
    "symfony/http-kernel": "~2.8.34",
  },
  "autoload": {
    "psr-4": {
      "crmpicco\GolfBundle\": ""
    }
  },
  "extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "relative"
  }
}

好的。如我所见,您的捆绑包 composer.json 中的 psr-4 自动加载配置有误 您必须将其更改为以下内容:

"autoload": {
    "psr-4": {
        "crmpicco\GolfBundle\": "crmpicco/GolfBundle"
    }
}

此外,如果您不想复制目录,请将您的包的内容移动到根目录,然后不要更改 composer.json 内容。 Dirs 重复,因为 Composer 根据 name 属性 创建目录结构,在您的情况下也是 crmpicco/GolfBundle

您不应为包含有效 composer.json 的存储库使用 package 类型。这种类型是为没有 composer.json 的包设计的,所以这个文件将被完全忽略,就像你的包中的更新一样。

在您的情况下,最好将其定义为 git:

"repositories": [
    {
        "type": "git",
        "url": "https://git.crmpicco.com/rfc1872/golfbundle.git"
    }
],