dongping8572 2014-01-17 15:56
浏览 164
已采纳

使用composer进行基于组件的开发

Let's say I want to write a new application.

/workspace/exampleapp/
  .git
  src/
  vendor/
    app/
      component1/
        .git
        src/
        composer.json
      component2/
        .git
        src/
        composer.json
  composer.json

I have three git repositories. They have no remotes. I also have three composer.json files.

/workspace/app/composer.json

{
  "name": "app/app",
  "type": "project",
  "license": "MIT",
  "require": {
    "app/component1": "dev-master",
    "app/component2": "dev-master"
  },
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

/workspace/app/vendor/app/component1/composer.json

{
  "name": "app/component1",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

/workspace/app/vendor/app/component2/composer.json

{
  "name": "app/component2",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {"app\\": "src/"}
  }
}

If I run composer update in the project root I receive the error The requested package app/component1 could not be found in any version, there may be a typo in the package name.

What do I have to change to make it work? Is there a way without moving the components directories out of the vendor directory or creating remote repositories?

Thank you!

  • 写回答

1条回答 默认 最新

  • doulu1968 2014-01-17 20:00
    关注

    I think you are suffering from the XY problem - I'm going to pretend that you actually asked "How can I setup a project with Composer with the following requirements?"

    • Be able to work without a remote Git server i.e. be able to commit and push locally.
    • Be able to commit code for the components separately to the commits to the main project.
    • Be able to edit the code in the vendor directories for your repositories, and commit from those directories.

    In which case the answer is, setup your directories like this:

    /workspace/app/
      composer.json
        src/
    
    /workspace/components/
      component1/
        composer.json
        src/
      component2/
        src/
        composer.json
    

    Setup each of your component's composer file like this:

    /workspace/components/component1/composer.json

    {
      "name": "app/component1",
      "type": "library",
      "license": "MIT",
      "autoload": {
        "psr-4": {"app\\": "src/"}
      }
    }
    

    Tell your the composer.json file for your app to use the components directories as local git repositories.

    /workspace/app/composer.json

    {
      "name": "app/app",
      "type": "project",
      "license": "MIT",
      "require": {
        "app/component1": "dev-master",
        "app/component2": "dev-master"
      },
      "autoload": {
        "psr-4": {"app\\": "src/"}
      },
      "repositories": [
        {
            "type": "vcs",
            "url": "/workspace/components/component1"
        },
        {
            "type": "vcs",
            "url": "/workspace/components/component2"
        }
      ],
    }
    

    When you do the first "composer update" you should run it with the option composer update --prefer-source. That will force composer to do a git clone for the code, rather than downloading just a zip-ball and extracting it.

    (Adding --prefer-source may not be required, it seems composer may do clone by default when fetching from a local directory repository).

    You will now be able to edit the code for the components in the vendor directory, be able to commit it separately to the app code, as well as be able to push it to 'remote' git repository at /workspace/components/component1/.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?