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

如何在没有 Composer 的情况下安装 Composer PHP 包?

How do I install Composer PHP packages without Composer?(如何在没有 Composer 的情况下安装 Composer PHP 包?)

本文介绍了如何在没有 Composer 的情况下安装 Composer PHP 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装 Coinbase PHP API,但它需要 Composer:

I'm trying to install the Coinbase PHP API but it requires Composer:

https://github.com/coinbase/coinbase-php

我正在寻找一个通用的 PHP 解决方案(可能是一个函数),让我可以将 composer 包直接安装到我的服务器上,而无需使用 Composer.

I'm looking for a universal PHP solution (perhaps a function) to let me install composer packages directly onto my server, without having to use Composer.

我认为 Composer 的开发人员相信他们在帮助人们,但实际上有成千上万的初学者开发人员因为Composer 障碍"而无法学习 Web 开发.

I think the developers of Composer believe they are helping people, but actually there are thousands of beginner developers that are being locked out of learning web development by the 'Composer barrier'.

如果有一个灵活的解决方案或某种方法可以在没有 Composer 的情况下进行安装,那真的会有所帮助吗?我该怎么做?

It would really help if there was a flexible solution or some approach where we could install without Composer? How can I do this?

请不要回复一些讽刺的评论.有些人不想使用 Composer,我不明白为什么我们应该被引入特定的第三方软件来进行 Web 开发.

Please don't respond with some sarcastic comment. There are people that don't want to use Composer and I don't see why we should be herded into a specific third-party software in order to do web development.

推荐答案

composer.json 文件 列出了依赖项.在您的示例中:

The composer.json file lists the dependencies. In your example:

"require": {
    "php": ">=5.5.0",
    "guzzlehttp/guzzle": "^6.0",
    "psr/http-message": "^1.0",
    "psr/log": "^1.0"
},

然后您必须在 packagist 站点中找到相应的包.对每个依赖项重复相同的过程:在其对应的 composer.json 文件中找到其他依赖项并再次搜索.

You must then find the corresponding packages in the packagist site. Repeat the same process for each dependency: find additional dependencies in their corresponding composer.json files and search again.

当您最终获得所需软件包的完整列表时,您只需将它们一一安装即可.在大多数情况下,只需将文件放在项目目录中的某个位置即可.但是您还必须确保 PHP 可以找到所需的类.由于您没有使用 Composer 的自动加载器,因此您需要将它们添加到您自己的自定义自动加载器中.您可以从相应的 composer.json 文件中找出信息,例如:

When you finally have a complete list of the required packages, you only need to install them all one by one. For the most part, it's just a matter of dropping the files somewhere in your project directory. But you must also ensure that PHP can find the needed classes. Since you aren't using Composer's auto-loader, you need to add them to your own custom autoloader. You can figure out the information from the respective composer.json files, e.g.:

"autoload": {
    "psr-4": { "Coinbase\Wallet\": "src/" }
},

如果您不使用类自动加载器,则需要找出单独的 require_once 语句.您可能需要大量的试验和错误,因为大多数图书馆作者不会关心记录这些.

If you don't use a class auto-loader you'll need to figure out the individual require_once statements. You'll probably need a lot of trial and error because most library authors won't care documenting that.

另外,以防万一对此感到困惑:

Also, and just in case there's confusion about this:

  • Composer 具有适用于 Windows 的官方 GUI 安装程序和适用于所有平台的复制和粘贴命令行安装程序.
  • Composer 可以在本地运行,其输出只需上传到其他地方.您的共享主机不需要 SSH.
  • 可以从包网站复制和粘贴安装库所需的命令——即使包维护者不关心它,packagist.org 默认会生成它.

Composer 并不完美,它并不适合所有用例,但在安装依赖它的库时,它无疑是最好的选择,而且相当不错.

Composer is not perfect and it doesn't suit all use cases but, when it comes to installing a library that relies on it, it's undoubtedly the best alternative and it's a fairly decent one.

我检查了我之后的其他答案.它们主要分为两类:

I've checked other answers that came after mine. They mostly fall in two categories:

  1. 安装一个库并使用它编写一个自定义下载脚本
  2. 为 Composer 使用基于 Web 的在线界面

除非我遗漏了什么,否则他们都没有解决 OP 表达的抱怨:

Unless I'm missing something, none of them address the complaints expressed by the OP:

  • 学习曲线
  • 使用第三方软件
  • 可以在服务器上进行开发(我猜是使用 SSH)
  • 潜在的深度依赖树

这篇关于如何在没有 Composer 的情况下安装 Composer PHP 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在没有 Composer 的情况下安装 Composer PHP 包?

基础教程推荐