E
E
Evgen Trezvykh2015-08-25 12:26:47
PHP
Evgen Trezvykh, 2015-08-25 12:26:47

How to implement mutual dependency in composer?

There are two packages, they depend on each other.
composer.json for Package1:

{
   "name": "my/Package1",
   ...
   "require": {
   "my/Package2": "master"
   },
   "repositories":[
      {
        "type": "vcs",
        "url": "https://github.com/my/Package2"
      }
   ]
   ...
}

composer.json for Package2:
{
   "name": "my/Package2",
   ...
   "require": {
   "my/Package1": "master"
   },
   "repositories":[
      {
        "type": "vcs",
        "url": "https://github.com/my/Package1"
      }
   ]
   ...
}

When updating (composer update) Package1 composer throws an error that my/Package2 requires my/Package1 which is not found. Adding itself as a dependency to Package1 does not work, as there is a collision of package names in composer.json.
Actually the question is:
How to implement mutual dependency in composer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Ovchinnikov, 2015-08-25
@ova777

And yet something is wrong with the architecture. The question sounds something like this: to get an egg - you need a chicken, to get a chicken - you need an egg, how to get both a chicken and an egg at the same time?
Unit tests for that and unit (modular) that test one unit - in isolation!
There are two ways out of the situation:
1. Move common things from both packages to the third one, and include it as dependencies of the first two.
2. Remove the second one from the dependencies of one of the packages. That. both packages will still be updated.
3. Official solutions: Why can't Composer load repositories recursively?

D
Dmitry Evgrafovich, 2015-08-25
@Tantacula

If two packages are interdependent, then why are there two and not one?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question