Composer require local package

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

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:

You can use Composer's repositories feature

https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

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



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!