-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |