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

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

问题描述

我目前正在处理2个应用程式。第一个是CMS,第二个是商店。



所以我的结构将是这样:

  project1 / 
project2 /
shared_vendor /

我读了这个。
我改变了 app / autoload.php 加载器变量:

  $ loader = require __DIR __。'/ .. / vendor / autoload.php'; 

到:

 code> $ loader = require __DIR __。'/ .. / .. / vendor / autoload.php'; 

我也更改了 vendor-dir 在我的 composer.json 中:

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

到:

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

$ b b

然后,我得到这个错误:

  AppKernel.php中的ClassNotFoundException第20行:尝试从命名空间Cms \UserBundle加载
类CmsUserBundle。
你忘记了另一个命名空间的use语句吗?

我做错了什么?我忘了改变东西吗?
提前感谢。

解决方案

Composer在每个项目的基础上工作。



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



我们有了共享供应商文件夹方法与PEAR足够长,它根本没有解决。



无论如何,使用全局供应商文件夹管理不同的项目需求是一件痛苦的事情。



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



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

  | -container-project 
+ -CMS
| -src
+ -tests
+ -Shop
| -src
+ -tests
+ -vendors //包含两个项目的依赖项(CMS + Shop)
| -composer.json //定义两个项目的需求

composer.json 子项目的文件。
您只需将需求从超级项目的 composer.json 文件传输到 composer.json



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


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/

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

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

to:

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

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

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

to:

    "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 "Cms\UserBundle".
Did you forget a "use" statement for another namespace?

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

解决方案

Composer works on a per project basis.

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

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.

Anyway...

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.

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

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天全站免登陆