-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance service provider to be deferrable with better DI support (#20)
- Loading branch information
1 parent
31e96ed
commit 86e8220
Showing
2 changed files
with
32 additions
and
19 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
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 |
---|---|---|
@@ -1,44 +1,57 @@ | ||
<?php | ||
/* | ||
* (c) Wessel Strengholt <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
/** | ||
* (c) Wessel Strengholt <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Shivella\Bitly; | ||
|
||
use GuzzleHttp\Client; | ||
use Illuminate\Support\ServiceProvider as AppServiceProvider; | ||
use Illuminate\Contracts\Support\DeferrableProvider; | ||
use Illuminate\Support\ServiceProvider; | ||
use Shivella\Bitly\Client\BitlyClient; | ||
|
||
/** | ||
* Class BitlyServiceProvider | ||
* BitlyServiceProvider registers Bitly client as an application service. | ||
*/ | ||
class BitlyServiceProvider extends AppServiceProvider | ||
class BitlyServiceProvider extends ServiceProvider implements DeferrableProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->singleton('bitly', function () { | ||
return new BitlyClient(new Client(), config('bitly.accesstoken', '')); | ||
return new BitlyClient(new Client(), $this->app->make('config')->get('bitly.accesstoken', '')); | ||
}); | ||
|
||
$this->app->bind(BitlyClient::class, 'bitly'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([__DIR__ . '/config/bitly.php' => config_path('bitly.php')]); | ||
if ( ! $this->app->runningInConsole()) { | ||
return; | ||
} | ||
|
||
$configPath = $this->app->make('path.config'); | ||
|
||
$this->publishes([__DIR__ . '/config/bitly.php' => $configPath.'/bitly.php']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function provides() | ||
{ | ||
return [ | ||
BitlyClient::class, | ||
'bitly' | ||
]; | ||
} | ||
} |