1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace RattfieldNz\Shodan; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ShodanServiceProvider. |
10
|
|
|
* |
11
|
|
|
* @category PHP |
|
|
|
|
12
|
|
|
* |
13
|
|
|
* @author Rob Attfield <[email protected]> |
|
|
|
|
14
|
|
|
* @license https://github.com/rattfieldnz/shodan/blob/master/LICENSE MIT |
|
|
|
|
15
|
|
|
*/ |
|
|
|
|
16
|
|
|
class ShodanServiceProvider extends ServiceProvider |
17
|
|
|
{ |
|
|
|
|
18
|
|
|
const CONFIG_PATH = __DIR__.'/../config/shodan.php'; |
|
|
|
|
19
|
|
|
|
20
|
18 |
|
public function boot() |
|
|
|
|
21
|
|
|
{ |
|
|
|
|
22
|
18 |
|
$this->publishes( |
|
|
|
|
23
|
|
|
[ |
|
|
|
|
24
|
18 |
|
self::CONFIG_PATH => config_path('shodan.php'), |
|
|
|
|
25
|
18 |
|
], 'config' |
26
|
|
|
); |
27
|
18 |
|
} |
|
|
|
|
28
|
|
|
|
29
|
18 |
|
public function register() |
|
|
|
|
30
|
|
|
{ |
|
|
|
|
31
|
18 |
|
$this->mergeConfigFrom( |
32
|
18 |
|
self::CONFIG_PATH, |
33
|
18 |
|
'shodan' |
34
|
|
|
); |
35
|
|
|
|
36
|
18 |
|
$this->app->alias(Shodan::class, 'shodan'); |
|
|
|
|
37
|
|
|
|
38
|
18 |
|
$this->app->bind( |
|
|
|
|
39
|
|
|
'shodan', function () { |
40
|
|
|
return new Shodan(); |
41
|
18 |
|
} |
42
|
|
|
); |
43
|
18 |
|
} |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the services provided by the provider. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
1 |
|
public function provides() |
51
|
|
|
{ |
|
|
|
|
52
|
1 |
|
return ['shodan']; |
|
|
|
|
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Console-specific booting. |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
1 |
|
public function bootForConsole() |
61
|
|
|
{ |
|
|
|
|
62
|
|
|
// Publishing the configuration file. |
63
|
1 |
|
$this->publishes( |
64
|
|
|
[ |
|
|
|
|
65
|
1 |
|
__DIR__.'/../config/shodan.php' => config_path('shodan.php'), |
|
|
|
|
66
|
1 |
|
], 'shodan' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
// Registering package commands. |
70
|
1 |
|
$this->commands(['shodan']); |
|
|
|
|
71
|
1 |
|
} |
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Merge the given configuration with the existing configuration. |
75
|
|
|
* |
76
|
|
|
* @param string $path |
|
|
|
|
77
|
|
|
* @param string $key |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
18 |
|
protected function mergeConfigFrom($path, $key) |
|
|
|
|
82
|
|
|
{ |
|
|
|
|
83
|
18 |
|
$config = $this->app['config']->get($key, []); |
|
|
|
|
84
|
18 |
|
$this->app['config']->set($key, $this->mergeConfig($config, include $path)); |
85
|
18 |
|
} |
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Merges the configs together and takes multi-dimensional arrays into account. |
89
|
|
|
* |
90
|
|
|
* @param array $original |
|
|
|
|
91
|
|
|
* @param array $merging |
|
|
|
|
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
18 |
|
protected function mergeConfig(array $original, array $merging) |
96
|
|
|
{ |
|
|
|
|
97
|
18 |
|
$array = array_merge($original, $merging); |
98
|
18 |
|
foreach ($original as $key => $value) { |
99
|
1 |
|
if (!is_array($value)) { |
|
|
|
|
100
|
1 |
|
continue; |
101
|
|
|
} |
|
|
|
|
102
|
1 |
|
if (!Arr::exists($merging, $key)) { |
|
|
|
|
103
|
|
|
continue; |
104
|
|
|
} |
|
|
|
|
105
|
1 |
|
if (is_numeric($key)) { |
106
|
|
|
continue; |
107
|
|
|
} |
|
|
|
|
108
|
1 |
|
$array[$key] = $this->mergeConfig($value, $merging[$key]); |
109
|
|
|
} |
110
|
|
|
|
111
|
18 |
|
return $array; |
112
|
|
|
} |
|
|
|
|
113
|
|
|
} |
|
|
|
|
114
|
|
|
|