Asked  7 Months ago    Answers:  5   Viewed   40 times

I've got a couple of libraries [Foo and Bar] that I'm developing in concert, but are still technically separate things. Previously I've just re-defined the autoloader to like "Foo\": "../Foo/src", but now that I've added a Guzzle dependency to Foo, Bar flips it's lid because it's not one of its dependencies.

Directory structure:

/home/user/src/
    Foo/
        src/
            FooClient.php
        composer.json
    Bar/
        src/
            BarClient.php
        composer.json

Theoretical Autoload Statement: [in Bar/composer.json]

"require": {
    "local": "../Foo/composer.json"
}

Example code:

require('vendor/autoload.php');

$f = new BarBarClient(new FooFooClient());

How can I resolve this without setting up a local Composer repo? I want to maintain these as separate packages, just that one requires the other, and therefor processes the other's dependencies.

post-answer edit:

Thanks to infomaniac I've done the following:

Initialized the git repo:

cd ~/src/Foo && git init && echo -e "vendorncomposer.lock" > .gitignore && git add ./ && git commit -m "Initial Commit"

Added the composer config:

"require": {
    "sammitch/foo": "dev-master"
},
"repositories": [{
    "type": "vcs",
    "url": "/home/sammitch/src/Foo"
}],

And then composer update!

 Answers

34

You can use Composer's repositories feature

https://getcomposer.org/doc/05-repositories.md#path

{
  "repositories": [
    {
        "type": "path",
        "url": "../../packages/my-package"
    }
  ],
  "require": {
    "my/package": "*"
  }
}

Instead of using the http format, specify a file path on disk.

Wednesday, March 31, 2021
 
superhero
answered 7 Months ago
60

try

composer config disable-tls true
composer config secure-http false

you can also change composer config repositories.packagist.org.url to https?://repo.packagist.org.

Wednesday, March 31, 2021
 
MDDY
answered 7 Months ago
35

The answer is just add @dev

{
    "require": {
        "cartalyst/sentry": "2.0.*@dev"
    },
}

You can read more about minimum stability settings here.

An alternative is to set your minimum-stability to dev, but tell composer you want to use stable whenever possible:

"minimum-stability": "dev",
"prefer-stable" : true

This basically means it will always use stable UNLESS there is no way to install a stable dependency, and therefore use dev.

Saturday, May 29, 2021
 
Bharanikumar
answered 5 Months ago
86

This issue was actually the proxy variables. While the console was picking up the changes, PHP required a system restart to pick it up. So unsetting the environment variables and restarting allowed the Composer installer to retrieve the required files. Thanks Seldaek for your recommendation to check the proxy.

Saturday, May 29, 2021
 
Muazam
answered 5 Months ago
14

Indeed, Composer will not recursively look at composer.json files in the file system. It needs to see the composer.json files in the repository. The way it usually works is that a package has a git or svn URL somewhere. Composer will fetch, for instance, git://<host>/<package>/composer.json directly from the repository to figure out that package's dependencies before it's even installed to calculate the overall dependencies.

In your case, you are defining a package inline in your own composer.json file. This is used instead of a composer.json file in the dependency. This means Composer takes the "package": { ... } to be the canonical composer.json file for that package, it will not look into the code itself; especially not after unpacking it. It treats the Zip file as if it had no composer.json file of its own.

Define the dependencies in the "package": { ... } or host the code in a version control system from which Composer can fetch the composer.json file.

Saturday, May 29, 2021
 
sassy_geekette
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share