1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel TransIP. |
5
|
|
|
* |
6
|
|
|
* (c) Hidde Beydals <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace TransIP\Laravel; |
13
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Foundation\Application; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use TransIP\Client; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Hidde Beydals <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class TransIPServiceProvider extends ServiceProvider |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Boot the service provider. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function boot() |
29
|
|
|
{ |
30
|
|
|
$this->setupConfig(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Setup the config. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
protected function setupConfig() |
39
|
|
|
{ |
40
|
|
|
$source = realpath(__DIR__.'/../config/transip.php'); |
41
|
|
|
|
42
|
|
|
if (class_exists('Illuminate\Foundation\Application', false)) { |
43
|
|
|
$this->publishes([$source => config_path('transip.php')]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->mergeConfigFrom($source, 'transip'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register the service provider. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function register() |
55
|
|
|
{ |
56
|
|
|
$this->registerFactory($this->app); |
57
|
|
|
$this->registerManager($this->app); |
58
|
|
|
$this->registerBindings($this->app); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Register the factory class. |
63
|
|
|
* |
64
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
protected function registerFactory(Application $app) |
69
|
|
|
{ |
70
|
|
|
$app->singleton('transip.factory', function ($app) { |
|
|
|
|
71
|
|
|
return new TransIPFactory(); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
$app->alias('transip.factory', TransIPFactory::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Register the manager class. |
79
|
|
|
* |
80
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
protected function registerManager(Application $app) |
85
|
|
|
{ |
86
|
|
|
$app->singleton('transip', function ($app) { |
87
|
|
|
$config = $app['config']; |
88
|
|
|
$factory = $app['transip.factory']; |
89
|
|
|
|
90
|
|
|
return new TransIPManager($config, $factory); |
91
|
|
|
}); |
92
|
|
|
|
93
|
|
|
$app->alias('transip', TransIPManager::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Register the bindings. |
98
|
|
|
* |
99
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
protected function registerBindings(Application $app) |
104
|
|
|
{ |
105
|
|
|
$app->bind('transip.connection', function ($app) { |
106
|
|
|
$manager = $app['transip']; |
107
|
|
|
|
108
|
|
|
return $manager->connection(); |
109
|
|
|
}); |
110
|
|
|
|
111
|
|
|
$app->alias('transip.connection', Client::class); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the services provided by the provider. |
116
|
|
|
* |
117
|
|
|
* @return string[] |
118
|
|
|
*/ |
119
|
|
|
public function provides() |
120
|
|
|
{ |
121
|
|
|
return [ |
122
|
|
|
'transip.factory', |
123
|
|
|
'transip', |
124
|
|
|
'transip.connection', |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.