IsraelOrtuno / pipedrive

Complete Pipedrive API client for PHP
MIT License
166 stars 58 forks source link

Service Provider :: Wrong Dependency Injection #104

Closed walkingCommiter closed 1 year ago

walkingCommiter commented 3 years ago

It seems like PipedriveServiceProvider does not exactly follow the Laravel instructions for creating a provider. Since the register() method should only be used to bind interfaces and the rest should be moved to the boot() method. //This might affect the backward compatibility

Reference: https://laravel.com/docs/8.x/providers#writing-service-providers cc: @pultho


class PipedriveServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->booting( function () {
            $loader = \Illuminate\Foundation\AliasLoader::getInstance();
            $loader->alias( 'Pipedrive', 'Devio\Pipedrive\PipedriveFacade' );
        } );

        $this->app->singleton(Pipedrive::class, function ($app) {
            $token = $app['config']->get('services.pipedrive.token');
            $uri = $app['config']->get('services.pipedrive.uri') ?: 'https://api.pipedrive.com/v1/';
            $guzzleVersion = $app['config']->get('services.pipedrive.guzzle_version') ?: 6;

            if (! $token) {
                throw new PipedriveException('Pipedrive was not configured in services.php configuration file.');
            }
...
IsraelOrtuno commented 3 years ago

You are right, could you submit a PR?