2

The problem:

I have Entities that are and will be the same for 2 projects written in Symfony. We got an idea to share them between projects. The first idea was to use git sub-module but everyone knows that it's not the most comfortable solution. So we put them in Satis as separate git repository.

In one project I would like to edit them in application directory src/AppBundle/Entity on the other they can be downloaded into vendor directory.

The question is how to setup composer so I can work with them not in vendor directory. How the commits will look like? Is git sub-module required for this?

I've already read about "type" : "path" for repository, I've checked composer installers. Is there any other solution than symlink which comes to my mind right now?

So to sum up.

How to work with shared library in one project from app directory and on the other on vendor directory?

Robert
  • 19,800
  • 5
  • 55
  • 85
  • I think you may try with Composer's `--prefer-source` option. I didn't try it out, so I won't post it as an answer, but this link may help http://dimsav.com/blog/9/git-repository-inside-composer-vendors – Jakub Matczak Aug 17 '16 at 08:52
  • prefer source will download it from github/gitlab etc. instead of packagist/satis so this is not a probelm – Robert Aug 17 '16 at 08:53
  • It will download it according to your composer.json configuration. It doesn't matter where the repository is. – Jakub Matczak Aug 17 '16 at 08:56
  • yep but with prefer source it will try to download it from CVS(or any other source) instead of cached "dist" version this is still not an issue. – Robert Aug 17 '16 at 09:01
  • Isn't that what you want? You want to work on two repositories in one local project. Therefore you need to clone the repository instead of downloading dist version. – Jakub Matczak Aug 17 '16 at 09:05
  • I'm thinking of adding to gitignore one repository on one project and on the other this repostiory will be downloaded by composer – Robert Aug 17 '16 at 09:37

1 Answers1

0

This is the solution that worked for me.

I've cloned internal library into project.

In main project I've added this directory to .gitignore and in composer.json I've added following lines

"repositories": [
        {
            "type": "path",
            "url": "internal-library",
            "options": {
                "symlink": true
            }
        },
        {
            "type": "composer",
            "url": "http://our-satis"
        }
    ],

In the other project I've added only satis repository(the entities will be changed only in one project and imported to the other).

"repositories": [
            {
                "type": "composer",
                "url": "http://our-satis"
            }
        ],

So now in development when I do composer update the library is symlinked to vendor directory. If I don't have this directory it will be get from satis. In production repository will be get from satis because my direc tory does not exist. I've had some issues with PSR loading but everything works as expected.

I hope it will help someone having same issues as I had.

Robert
  • 19,800
  • 5
  • 55
  • 85