一个有两个项目的共享供应商 [英] One shared vendor with two projects

查看:24
本文介绍了一个有两个项目的共享供应商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在处理 2 个应用程序.第一个是CMS,第二个是商店.我想将我的供应商提升一级并在项目之间共享.

I'm working on 2 applications right now. The first one is a CMS, and the second is a shop. I want to move my vendor one level above and the share it between projects.

所以我的结构将是这样的:

So my structure will be something like this:

project1/
project2/
shared_vendor/

我读到了这个.我已经更改了 app/autoload.php 加载器变量:

I read about this. I have changed the app/autoload.php loader variable from:

$loader = require __DIR__.'/../vendor/autoload.php';

到:

$loader = require __DIR__.'/../../vendor/autoload.php';

而且我也将 composer.json 中的 vendor-dir 从:

And I have also changed vendor-dir in my composer.json from:

    "config": {
      "bin-dir": "bin",
      "vendor-dir": "vendor"
    },

到:

    "config": {
      "bin-dir": "bin",
      "vendor-dir": "/../vendor"
    },

在此之后,我收到此错误:

And after this I'm getting this error:

ClassNotFoundException in AppKernel.php line 20: Attempted to load 
class "CmsUserBundle" from namespace "CmsUserBundle".
Did you forget a "use" statement for another namespace?

我做错了什么?我忘记改变什么了吗?提前致谢.

What am I doing wrong? Did I forget to change something? Thanks in advance.

推荐答案

Composer 以每个项目为基础工作.

Composer works on a per project basis.

一个项目 - 一个供应商文件夹.不是,两个项目和一个共享"供应商文件夹.

One project - one vendor folder. Not, two projects and one "shared" vendor folder.

我们使用 PEAR 的共享"供应商文件夹方法已经足够长了,但它根本不起作用.使用全局供应商文件夹管理不同的项目需求很痛苦,因为每个项目都有不同的需求.

We had the "shared" vendor folder approach with PEAR long enough and it simply didn't work out. Managing different project requirements with a global vendor folder is a pain, because every project has different requirements.

无论如何...

如果您喜欢共享供应商文件夹"设置,我建议创建类似包装器"或超级"项目的内容,作为其他两个项目的容器存储库.包装项目将包含 composer.json 文件,其中包含两个(!)项目的要求.这意味着您正在针对两个子项目中的同一组依赖项工作.

if you like the "shared vendor folder" setup, i would suggest to create something like a "wrapper" or "super" project, which acts as container repository for the two other projects. The wrapper project will contain the composer.json file with the requirements for both(!) projects. That means that you are working against the same set of dependencies in both sub-projects.

这允许定义两个子项目(cms 和 shop)的要求在包装器"回购中.基本上,我建议采用以下结构:

This allows to define requirements for both sub-projects (cms and shop) in the "wrapper" repo. Basically, i'm suggesting the following structure:

|-container-project
  +-CMS
    |-src
    +-tests
  +-Shop
    |-src
    +-tests
  +-vendors      // contains dependencies for both projects (CMS + Shop)
|-composer.json  // define requirements for both projects

此设置也允许为子项目引入 composer.json 文件.您只需要将需求从超级项目的composer.json 文件转移到子项目的composer.json 文件即可.

This setup allows to introduce composer.json files for the subprojects, too. You just have to transfer the requirements from the composer.json file of the super-project to the composer.json file of a subproject.

现在,还可以通过按特定顺序注册自动加载器来调整子项目的自动加载行为.

Now, it's also possible to tweak the autoloading behavior of the sub-projects by registering autoloaders in a specific order.

这篇关于一个有两个项目的共享供应商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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