One shared vendor with two projects

r3m4k3

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.

Jens A. Koch

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Delphi shared unit in two projects

Two projects in one repository

How to use one vendor chunk file (webpack) for multiple react projects

Using one Vendor Folder for Multiple Projects in Laravel 5.2

Frontend and backend projects in IntelliJ: One or two projects?

Two Django Projects with One Database

Find one record that exists as two records in another vendor database

Update one APK from two projects

Merge two Java Maven projects into one

Two projects in one repository with GitHub Actions (monorepo)

One domain for two separate Firebase projects

Two Django projects, one Postgresql database, and Docker

Two Laravel projects on one VPS with Apache

How to import two projects in Eclipse, like one

Visual Studio recompiles projects that are shared between two solutions for no reason

Typescript. Template default value for class shared between two projects

Combine two ggplots into one plot with shared legend

hiding "vendor" folder on shared hosting

Sidekiq how can two projects share one sidekiq pid?

Merge two separate projects/Git repos into one master project?

ASP .NET MVC & WebForms - Two projects and one final site

Receive push notifications on one android app from two Firebase projects

Can i add two independant maven projects into one Project in Gitlab

One out of two Team Projects not shown in Source Control Explorer

Interface Event between two projects in one solution and Event Handlers

how can I merge two web projects in one solution

ESP32 - combining two or more SDK example projects into one

Google Cloud Shell is putting files in one instance for two separate projects

How to merge two or more firebase projects in one javascript app?