mardi 26 mars 2019

How to fix provider in config/app.php Laravel that's starting not found error

I'm setting up a new private composer package that has a provider called DatapageSDKProvider.

When I put the provider in config/app.php in providers array : 'Datapage\DatapageSDK\Providers\DatapageSDKProvider' and try to enter in any url, this throws an exception:

'Datapage\DatapageSDK\Providers\DatapageSDKProvider' Not found

This is my composer.json of the package:

{
  "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/"
  }
}


This is my package structure where Provider is:

src\Application\Providers

And this is my Provider:

<?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',
        ];
    }
}




from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2WoLMub
via IFTTT

Aucun commentaire:

Enregistrer un commentaire