-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAdWordsServiceProvider.php
58 lines (46 loc) · 1.72 KB
/
AdWordsServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace SchulzeFelix\AdWords;
use Illuminate\Support\ServiceProvider;
use SchulzeFelix\AdWords\Commands\GenerateRefreshTokenCommand;
use SchulzeFelix\AdWords\Exceptions\InvalidConfiguration;
class AdWordsServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/config/adwords-targeting-idea-service.php' => config_path('adwords-targeting-idea-service.php'),
]);
}
/**
* Register the service provider.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/config/adwords-targeting-idea-service.php', 'adwords-targeting-idea-service');
$adwordsConfig = config('adwords-targeting-idea-service');
$this->app->bind('command.adwords:token', GenerateRefreshTokenCommand::class);
$this->commands([
'command.adwords:token',
]);
$this->app->bind(AdWordsService::class, function () use ($adwordsConfig) {
return AdWordsServiceFactory::createForConfig($adwordsConfig);
});
$this->app->bind(AdWords::class, function () use ($adwordsConfig) {
$this->guardAgainstInvalidConfiguration($adwordsConfig);
$adWordsService = app(AdWordsService::class);
return new AdWords($adWordsService);
});
$this->app->alias(AdWords::class, 'laravel-adwords-targeting-idea-service');
}
protected function guardAgainstInvalidConfiguration(array $adwordsConfig = null)
{
if (empty($adwordsConfig['developer_token'])) {
throw InvalidConfiguration::developerTokenNotSpecified();
}
}
}