代码之家  ›  专栏  ›  技术社区  ›  crmpicco

composer包在安装时复制目录

  •  1
  • crmpicco  · 技术社区  · 6 年前

    我有一个托管在私有gitlab repo上的本地依赖项。然而,我有困难通过作曲家把这个纳入我的项目。

    我的 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/crmpicco/GolfBundle/crmpicco/GolfBundle

    当我运行一个 composer update crmpicco\GolfBundle 当Symfony尝试执行缓存时,出现以下错误:clear:

    script sensio\bundle\distributionbundle\composer\scripthandler::处理更新后命令事件的clearcache因异常而终止

    [运行时异常]
    执行“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   
    

    我有什么遗漏/做错了 作曲家.json 设置?

    捆绑目录结构:

    /crmpicco
       /GolfBundle
          /Component      
          /DependencyInjection
          crmpiccoGolfBundle.php
    

    bundle 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"
      }
    }
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   rob006    6 年前

    你不应该用 package 包含有效 composer.json 是的。这种类型是为没有 作曲家.json ,因此此文件将被完全忽略,与包中的更新相同。

    在你的情况下,最好定义为 git 以下内容:

    "repositories": [
        {
            "type": "git",
            "url": "https://git.crmpicco.com/rfc1872/golfbundle.git"
        }
    ],
    
        2
  •  1
  •   Nikita Leshchev    6 年前

    好 啊。我看你错了 psr-4 包中的自动加载配置 composer.json 您必须将其更改为以下内容:

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

    另外,如果不想复制dir s,请将包的内容移到根目录,然后不要更改 作曲家.json 目录dirs重复,因为composer基于 name 同时也是 crmpicco/GolfBundle 对你来说。