沃梦达 / 编程问答 / php问题 / 正文

作曲家需要本地包

Composer require local package(作曲家需要本地包)

本文介绍了作曲家需要本地包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个库 [Foo 和 Bar] 我正在共同开发,但在技术上仍然是独立的东西.以前我只是将自动加载器重新定义为喜欢 "Foo\":"../Foo/src",但现在我已经向 Foo 添加了 Guzzle 依赖项,Bar 翻转它的盖子,因为它不是它的依赖项之一.

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.

目录结构:

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

理论自动加载语句:[in Bar/composer.json]

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

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

示例代码:

require('vendor/autoload.php');

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

如何在不设置本地 Composer 存储库的情况下解决此问题?我想将这些作为单独的包进行维护,只是一个需要另一个,因此处理另一个的依赖项.

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.

感谢 infomaniac,我完成了以下工作:

Thanks to infomaniac I've done the following:

初始化 git repo:

Initialized the git repo:

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

添加了作曲家配置:

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

然后作曲家更新

推荐答案

您可以使用 Composer 的 repositories 功能

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": "*"
  }
}

不使用 http 格式,而是指定磁盘上的文件路径.

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

这篇关于作曲家需要本地包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:作曲家需要本地包

基础教程推荐