如何将程序包添加到自定义的laravel程序包?

时间:2018-11-10 19:00:10

标签: laravel guzzle

我正在构建一个需要guzzlehttp/guzzle软件包的自定义Laravel软件包。以下是我的composer.json文件:

{
  "name": "lomse/awesomePackage",
  "description": "this an awesome package",
  "type": "library",
  "license": "MIT",
  "authors": [
    {
      "name": "Selom",
      "email": "awesome@gmail.com"
    }
  ],
  "minimum-stability": "dev",
  "require": {
    "guzzlehttp/guzzle": "^6.3"
  },
  "autoload": {
    "psr-4": {
      "Lomse\\AwesomePackage\\": "src/"
    }
  }
}

下面是我的AwesomeProvider.php文件的内容:

<?php

namespace Lomse\AwesomePackage;

use GuzzleHttp\Client;
use Illuminate\Support\ServiceProvider;

class AwesomeProvider extends ServiceProvider
{
    public function boot(){
    }

    public function register()
    {
        $this->app->singleton(Awesome::class, function ($app) {
            return new Awesome(new Client); //Class 'GuzzleHttp\Client' not found
        });
    }
}

我不断收到Class 'GuzzleHttp\Client' not found。 我在做什么错了?

1 个答案:

答案 0 :(得分:1)

因此,事实证明这很简单。我重点介绍了解决此问题要采取的步骤。希望这对遇到相同问题的所有人有所帮助。

  1. 我不得不将代码推送到Github上的仓库lomse/awesome-package
  2. 然后在preferred-install配置属性中将dist指定为./lomse/awesome-package/package.json

    “配置”:{     “ preferred-install”:“ dist” }

完整代码是

{
  "name": "lomse/awesome-package",
  "description": "this an awesome package",
  "type": "library",
  "license": "MIT",
  "authors": [
    {
      "name": "Selom",
      "email": "awesome@gmail.com"
    }
  ],
  "minimum-stability": "dev",
  "require": {
    "guzzlehttp/guzzle": "^6.3"
  },
  "autoload": {
    "psr-4": {
      "Lomse\\AwesomePackage\\": "src/"
    }
  },
  "config": {
    "preferred-install": "dist"
  }
}

在根package.json中,如下指定软件包的存储库:

"repositories": [
   {
      "type": "git",
      "url": "git@github.com:lomse/awesome-package.git"
   }
]

还将您的软件包存储库添加到package.json require属性中,如下所示:

"lomse/awesome-package": "dev-master"

在您的根目录中,运行以下代码以更新依赖关系。这会将lomse/awesome-package存储库克隆到您的供应商文件夹中,并安装您的软件包所需的任何其他依赖项:

composer update -vvv

-vvv用于调试

enter image description here

enter image description here