【问题标题】:How to fix provider in config/app.php Laravel that's starting not found error如何修复 config/app.php Laravel 中启动未找到错误的提供程序
【发布时间】:2019-08-17 04:12:06
【问题描述】:

我正在设置一个新的私有作曲家包,它有一个名为 DatapageSDKProvider 的提供程序。

当我将提供程序放在提供程序数组中的 config/app.php 中时: 'Datapage\DatapageSDK\Providers\DatapageSDKProvider' 并尝试输入任何网址,这会引发异常:

'Datapage\DatapageSDK\Providers\DatapageSDKProvider' 未找到

这是我的 laravel 项目的 composer.json:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "ms/datapage-sdk-laravel",
                "version": "0.0.3",
                "source": {
                    "url": "url_git",
                    "type": "git",
                    "reference": "develop"
                },
                "options": {
                    "ssl": {
                        "verify_peer": "false"
                    }
                }
            }
        }
    ],
    "require": {
        "php": "^7.1.3",
        "artesaos/defender": "~0.8.0",
        "aws/aws-sdk-php-laravel": "~3.0",
        "darkaonline/l5-swagger": "5.7.*",
        "doctrine/dbal": "^2.8",
        "fideloper/proxy": "^4.0",
        "laravel-notification-channels/onesignal": "^1.2",
        "laravel/framework": "5.7.*",
        "laravel/passport": "^7.0",
        "laravel/tinker": "^1.0",
        "laravellegends/pt-br-validator": "^5.1",
        "league/flysystem-aws-s3-v3": "^1.0",
        "league/fractal": "^0.17.0",
        "ms/datapage-sdk-laravel": "0.0.*",
        "prettus/l5-repository": "2.6.*"
    },
    "require-dev": {
        "barryvdh/laravel-ide-helper": "^2.5",
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

这是我的 composer.json 包:

{
  "name": "datapage/datapage-sdk-laravel",
  "description": "Datapage SDK",
  "authors": [
    {
      "name": "Márcio Winicius",
      "email": "marciowinicius.mw@gmail.com"
    }
  ],
  "autoload": {
    "psr-4": {
      "Datapage\\DatapageSDK\\": "src/Application"
    }
  },
  "extra": {
    "laravel": {
      "providers": [
        "Datapage\\DatapageSDK\\Providers\\DatapageSDKProvider"
      ],
      "aliases": {
        "DatapageSDK": "Datapage\\DatapageSDK\\Facades\\DatapageSDK",
        "HttpClient": "Datapage\\DatapageSDK\\Facades\\HttpClient",
        "OAuthClient": "Datapage\\DatapageSDK\\Facades\\OAuthClient"
      }
    }
  },
  "require": {
    "php": ">=7.0"
  },
  "require-dev": {
    "phpunit/phpunit": "~5.7"
  },
  "config": {
    "bin-dir": "bin/"
  }
}

这是我的包结构,其中 Provider 是:

src\Application\Providers

这是我的提供者:

<?php

namespace Datapage\DatapageSDK\Providers;

use Datapage\DatapageSDK\Auth\OAuthClient;
use Datapage\DatapageSDK\DatapageSDKFactory;
use GuzzleHttp\Client;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;

class DatapageSDKProvider extends ServiceProvider
{
    protected $defer = true;

    public function boot()
    {
        $this->publishes([
            __DIR__.'/../../config.php' => config_path('datapage_sdk.php'),
        ], 'datapage-sdk-config');
    }

    public function register()
    {
        $this->app->singleton('DatapageSDK', function() {
            return new DatapageSDKFactory();
        });

        $this->app->singleton('OAuthClient', function() {
            return new OAuthClient(new Application());
        });

        $this->app->singleton('HttpClient', function() {
            return new Client([
                'headers' => [
                    'Authorization' => \Datapage\DatapageSDK\Facades\OAuthClient::getToken()
                ]
            ]);
        });

        $this->app->bind(DatapageSDKFactory::class, 'DatapageSDK');
        $this->app->bind(OAuthClient::class, 'OAuthClient');
        $this->app->bind(Client::class, 'HttpClient');
    }

    public function provides()
    {
        return [
            DatapageSDKFactory::class, 'DatapageSDK',
            OAuthClient::class, 'OAuthClient',
            Client::class, 'HttpClient',
        ];
    }
}

编辑: 只是像这样更改了我的 laravel 项目的 composer.json:

"repositories": [
        {
            "type": "vcs",
            "url": "http://git2.datapage.com.br/ms/datapage-sdk-laravel.git"
        }
    ],

并在 Require 中输入:

"ms/datapage-sdk-laravel": "dev-develop"

然后 composer update 和 composer dump-autoload

【问题讨论】:

标签: php laravel laravel-5 composer-php package


【解决方案1】:

您需要在 require 或 require-dev 中使用它,具体取决于您使用它的目的。您可能将它列为您需要的东西,但作曲家不知道从那里安装它。

【讨论】:

  • 我用我的 laravel 项目的 composer.json 编辑了这篇文章。
猜你喜欢
  • 1970-01-01
  • 2023-01-30
  • 2021-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-25
  • 1970-01-01
  • 2019-01-22
相关资源
最近更新 更多