Skip to content

Commit

Permalink
Add laravel service provider.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Apr 9, 2019
1 parent 3f4d433 commit 117da2c
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/Laravel/SilverstreetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Silverstreet\Laravel;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Laravie\Codex\Discovery;
use Silverstreet\Client;

class SilverstreetServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register the service.
*
* @return void
*/
public function register()
{
$this->app->singleton('silverstreet', function (Application $app) {
return $this->createSilverstreetClient(
$app->make('config')->get('services.silverstreet')
);
});
}

/**
* Create Silverstreet Client.
*
* @param array $config
*
* @return \Silverstreet\Client
*/
protected function createSilverstreetClient(array $config): Client
{
return new Client(
$this->createHttpClient(), $config['username'], $config['password']
);
}

/**
* Create HTTP Client.
*
* @return \Http\Client\Common\HttpMethodsClient
*/
protected function createHttpClient()
{
return Discovery::client();
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['silverstreet'];
}
}

0 comments on commit 117da2c

Please sign in to comment.