如何在没有Composer的情况下安装Composer PHP软件包? [英] How do I install Composer PHP packages without Composer?

查看:257
本文介绍了如何在没有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障碍"而无法学习网络开发.

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 has an official GUI installer for Windows and a copy and paste command-line installation procedure for all platforms.
  • Composer can be run locally and its output just uploaded elsewhere. You don't need SSH in your shared hosting.
  • The command needed to install a library can be copied and pasted from the package web site—even if the package maintainer didn't care to document it, packagist.org generates it by default.

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软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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