当外部存储库不再存在时,Composer/Laravel从现有文件安装软件包 [英] Composer/Laravel install package from existing files when external repository no longer exists

查看:149
本文介绍了当外部存储库不再存在时,Composer/Laravel从现有文件安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:我有一个旧项目,该项目使用Laravel 4.2,PHP 5.5.9和Composer.我正在尝试在另一台计算机上安装它(使用Laravel 4.2.2和PHP 5.6),但是其中一个必需的软件包缺少依赖项,因为管理该GitHub帐户的人决定删除它.因此,无法通过Composer安装所需的软件包.

I have the following problem: I have an old project which uses Laravel 4.2, PHP 5.5.9 and Composer. I'm trying to set it up on a different computer (With Laravel 4.2.2 and PHP 5.6) but one of the required packages has a dependency which is missing because whoever was managing that GitHub account decided to remove it. Thus, the required package can't be installed via Composer.

现在,旧项目已下载了这些软件包,我可以手动复制它们.我不知道的是如何以这种方式将它们正确添加到项目中,并阻止作曲家尝试重新下载它们.

Now, the old project has these packages downloaded and I can copy both of them manually. What I don't know, is how to correctly add them to the project this way and stop composer from trying to download them anew.

没有代码示例,因为不需要.

No code examples give as none are needed.

推荐答案

如果您拥有文件,将无法继续使用作曲家来管理该程序包(例如,更新,删除等),那么您只需将文件视为属于您的项目即可.

If you have the files, and you won't be able to continue using composer to manage that package (e.g. for updates, removal, etc), then you just need to treat the files as if they belonged to your project.

在不了解您要使用的软件包的情况下很难给您提供具体信息,但是一般的方法是:

It's hard to give you specifics without knowing more about the package you want to use, but a general approach would be:

假设您要使用的软件包是funtastic/foobar.如果您有旧vendor中的文件,我们只需要vendor/funtastic中的目录,该目录可能称为foobar.

Let's say that the package you want to use is funtastic/foobar. If you have the files from your old vendor, we just need the directory inside the vendor/funtastic, which might be called foobar.

首先,在您的项目中复制文件.由于它们与应用程序的其余部分属于不同的名称空间,因此我个人不会将它们放在src中.例如,您可以将它们放置在名为lib的新目录中.

First, copy your files within your project. Since they belong to a different namespace than the rest of your application, I personally wouldn't put them in src. You could put them in a new directory called lib, for example.

所以现在您的文件结构如下:

So now your file structure would be something like:

project-root-dir
├── public
│  └── index.php
├── vendor/
├── lib/
│  └── foobar/
│     └── some files ...
│     └── src/
├── composer.json
├── composer.lock

现在,您需要检查软件包的composer.json,特别是autoload部分.它可能会说:

Now you need to check the package's composer.json, specifically the autoload section. It might say something like:

"autoload": {
        "psr-4": { "Funtastic\\FooBar\\": "src" }
    }

您现在需要转到您应用程序的 composer.json,找到autoload部分并对其进行编辑,以使其包含Funtastic\FooBar名称空间.假设您已经有一个App命名空间:

You now need to go to your application's composer.json, find the autoload section and edit it so it includes the Funtastic\FooBar namespace. Assuming you already had an App namespace:

  "autoload": {
    "psr-4": {
      "App\\": "src/",
      "Funtastic\\FooBar\\": "lib/foobar/src"
    }

此外,您还需要检查原始软件包的require部分,查看它是否依赖于任何软件包,并将这些软件包添加到应用程序的composer.json中的"require"部分.

Additionally, you also need to check the require section of the original package and see if it depends on any package and add those packages to your application's "require" section in its composer.json.

所有这些都准备好并且正确地编辑了composer.json,您只需重新生成自动装带器(composer dump-autload)就可以了.

With all this in place and the composer.json correctly edited, you could simply regenerate the autoloader (composer dump-autload) and you would be ready to go.

很显然,由于我不知道您的软件包和项目的详细信息,因此您必须根据具体情况调整这些说明,但是使该软件包在您的应用程序中运行不需要花很长时间.

Obviously, since I don't know the specifics of your package and project, you'll have to adjust these instructions to your specific case, but it should not take long to have the package working within your application.

或者,如果您想继续将此程序包视为外部"依赖项,则:

Alternatively, if you want to continue treating this package as if it were an "external" dependency:

  1. 将所有软件包文件压缩到package.zip中,然后放入base_dir/lib
  2. 将以下内容添加到您的composer.json中:
  1. Zip all the package files into package.zip and put it into base_dir/lib
  2. Add the following to your composer.json:
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "vendor/name",
            "version": "1.0",
            "dist": {
                "url": "lib/package.zip",
                "type": "zip"
            }
        }
    }
],

(解决方案最初是由问题作者自己提出的.)

(Solution originally proposed by the question author themselves).

使用此文件,文件将在您的项目中存在两次:作为存储库",并安装在vendor上,我发现这不理想.您还可以将文件保留在项目之外,但这将需要其他跟踪.

With this the files will exist twice in your project: as a "repository", and installed on vendor, which I find less than ideal. You can also keep the files outside of your project, but that would require additional tracking.

我个人会忍无可忍,接受此软件包不再是外部依赖,而是应由应用程序开发人员维护的文件.

I would personally bite the bullet an accept this package is no longer an external dependency, but files that should be maintained be application developer.

这篇关于当外部存储库不再存在时,Composer/Laravel从现有文件安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆