Composer にはローカルパッケージが必要です 質問する

Composer にはローカルパッケージが必要です 質問する

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 \Bar\BarClient(new \Foo\FooClient());

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 "vendor\ncomposer.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!

ベストアンサー1

The way to link to a local, in-development package is to first add in your main project's composer.json a repository, like this:

"repositories": [
    {
        "type": "path",
        "url": "/full/or/relative/path/to/development/package"
    }
]

You also need to either have a version specified in your development package's composer.json or the way I do it is to require the package using @dev, like this:

composer require "vendorname/packagename @dev"

It should output:

- Installing vendor/packagename (dev-develop)
Symlinked from /full/or/relative/path/to/development/package

The @dev in the require command is important, composer uses this to pickup the source code and symlink it to your new package.

It's a stability flag added to the version constraint (see package link).

These allow you to further restrict or expand the stability of a package beyond the scope of the minimum-stability setting.

The minimum-stability flags are:

Available options (in order of stability) are dev, alpha, beta, RC, and stable.

おすすめ記事