|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Amelia\Monzo; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client as Guzzle; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Amelia\Monzo\Socialite\MonzoProvider; |
|
8
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
9
|
|
|
use Amelia\Monzo\Contracts\Client as ClientContract; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Laravel 5.4+ service provider. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Amelia Ikeda <[email protected]> |
|
15
|
|
|
* @license BSD-3-Clause |
|
16
|
|
|
*/ |
|
17
|
|
|
class MonzoServiceProvider extends ServiceProvider |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Boot this service provider. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
|
|
public function boot() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/monzo.php', 'monzo'); |
|
27
|
|
|
|
|
28
|
|
|
if (class_exists('Laravel\Socialite\SocialiteManager')) { |
|
29
|
|
|
\Laravel\Socialite\Facades\Socialite::extend('monzo', function () { |
|
30
|
|
|
$config = $this->app['config']['monzo']; |
|
31
|
|
|
|
|
32
|
|
|
return new MonzoProvider( |
|
33
|
|
|
$this->app['request'], |
|
34
|
|
|
$config['id'], |
|
35
|
|
|
$config['secret'], |
|
36
|
|
|
$config['redirect'] |
|
37
|
|
|
); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$source = __DIR__ . '/../migrations/add_monzo_columns.php'; |
|
42
|
|
|
$destination = database_path('2017_12_25_000000_add_monzo_columns.php'); |
|
43
|
|
|
|
|
44
|
|
|
$this->publishes([$source => $destination], 'monzo'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register services with the container. |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function register() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->app->bind(ClientContract::class, function (Application $app) { |
|
55
|
|
|
$config = $app['config']['monzo']; |
|
56
|
|
|
|
|
57
|
|
|
return new Client(new Guzzle, $config['id'], $config['secret']); |
|
58
|
|
|
}); |
|
59
|
|
|
|
|
60
|
|
|
$this->app->singleton(Monzo::class, function (Application $app) { |
|
61
|
|
|
return new Monzo($app->make(ClientContract::class)); |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
$this->app->alias(Monzo::class, 'monzo'); |
|
65
|
|
|
$this->app->alias(ClientContract::class, 'monzo.client'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|