Viewed   116 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

2

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.

Saturday, September 10, 2022
2

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.

Saturday, August 6, 2022
 
hoaz
 
5

It's not anything to do with Yii directly.

Composer allows you to install dependencies globally or per-project (the default).

https://getcomposer.org/doc/03-cli.md#global

This is merely a helper to manage a project stored in a central location that can hold CLI tools or Composer plugins that you want to have available everywhere.

You might want to install something like phpunit or phpcs globally (so it's available for every project) whereas installing a library or framework that you need for your project should be a per-project installation.

Sunday, September 25, 2022
 
loktar
 
4

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.

Thursday, September 15, 2022
4
"require": {
    "my/package": "*"
}

In case of VCS or path repository types, you need to specify version of the package you request. So instead of using *, as you have currently, use @dev:

"require": {
    "my/package": "@dev"
}
Tuesday, November 1, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :