使用 composer 将 github 包安装到 Laravel 项目中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38323965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:08:06  来源:igfitidea点击:

Installing github package into Laravel project using composer

phplaravelcomposer-phplaravel-5.2

提问by IoC

I need to install custom packages from github url using composer. My Laravel 5.2 based project is clean and fresh install.

我需要使用composer从github url安装自定义包。我的基于 Laravel 5.2 的项目是全新安装的。

The github project I need is: https://github.com/cmcdonaldca/ohShopify.php

我需要的github项目是:https: //github.com/cmcdonaldca/ohShopify.php

I am still new to Laravel and composer and need help with clear steps as much as possible.

我还是 Laravel 和作曲家的新手,需要尽可能明确步骤的帮助。

Any help?

有什么帮助吗?

采纳答案by vsharper

Composer uses packages from the repository https://packagist.org/. You can't really just use github packages directly from github.

Composer 使用来自存储库https://packagist.org/ 的包。你真的不能直接从 github 使用 github 包。

You have 2 options here.

您在这里有 2 个选择。

  1. Use a package available on https://packagist.org/to integrate with the shopify API. I've had a look on packagist and found rocket-code/shopifyand phpish/shopify. To add them to your laravel project, in the folder that contains the composer.json file use the following command:

    composer require rocket-code/shopify

  2. You could create your own packagist package using the git repository. so you'll clone the repo and then create your own packagist account. So sign up, get a packagist account, upload the file and then require it in your laravel project.

  1. 使用https://packagist.org/上提供的软件包与 shopify API 集成。我看过 packagist 并找到了 Rocket -code/shopifyphpish/shopify。要将它们添加到 Laravel 项目,请在包含 composer.json 文件的文件夹中使用以下命令:

    composer require rocket-code/shopify

  2. 您可以使用 git 存储库创建自己的 packagist 包。所以你将克隆 repo,然后创建你自己的 packagist 帐户。所以注册,获得一个 packagist 帐户,上传文件,然后在你的 Laravel 项目中使用它。

I suggest that you use an existing composer package, as it takes away the responsibility of managing your own package.

我建议您使用现有的 composer 包,因为它可以消除管理您自己的包的责任。

回答by geckob

I am going to use this repoto explain the steps. The reasons is because the repo you includes do not have composer.jsonwhich I don't think possible to install using composer in that case

我将使用这个repo来解释这些步骤。原因是因为您包含的 repo 没有composer.json我认为在这种情况下无法使用 composer 安装

  1. Add repositories in composer.json

    "repositories": [
       {
         "url": "https://github.com/notmaintained/shopify.php",
    
          "type": "git"
        }
     ],
    
  2. Add the package name in require with the branch name after the dev:

    "sandeepshetty/shopify.php" : "dev-master"
    
  1. 在 composer.json 中添加存储库

    "repositories": [
       {
         "url": "https://github.com/notmaintained/shopify.php",
    
          "type": "git"
        }
     ],
    
  2. 在 require 中添加包名称,并在 之后添加分支名称dev

    "sandeepshetty/shopify.php" : "dev-master"
    

EDIT:

编辑:

Just tested this. There are some error since it was unmaintained package but you should get the idea of installing composer package using git.

刚刚测试了这个。由于它是未维护的包,因此存在一些错误,但您应该了解使用 git 安装 composer 包的想法。