|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of laravel-env-security. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Signature Tech Studio, Inc <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace STS\EnvSecurity; |
|
12
|
|
|
|
|
13
|
|
|
use Illuminate\Support\ServiceProvider; |
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
use STS\EnvSecurity\Console\Decrypt; |
|
16
|
|
|
use STS\EnvSecurity\Console\Edit; |
|
17
|
|
|
use function config; |
|
18
|
|
|
use function sprintf; |
|
19
|
|
|
use Tests\EditDouble; |
|
20
|
|
|
|
|
21
|
|
|
class EnvSecurityServiceProvider extends ServiceProvider |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Indicates if loading of the provider is deferred. |
|
25
|
|
|
* |
|
26
|
|
|
* @var bool |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $defer = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Default path to configuration. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $configPath = __DIR__ . '/../config/env-security.php'; |
|
36
|
|
|
|
|
37
|
|
|
public function boot() |
|
38
|
|
|
{ |
|
39
|
|
|
// helps deal with Lumen vs Laravel differences |
|
40
|
|
|
if (function_exists('config_path')) { |
|
41
|
|
|
$publishPath = config_path('env-security.php'); |
|
42
|
|
|
} else { |
|
43
|
|
|
$publishPath = base_path('config/env-security.php'); |
|
44
|
|
|
} |
|
45
|
|
|
$this->publishes([$this->configPath => $publishPath], 'config'); |
|
46
|
|
|
|
|
47
|
|
|
$this->verifyDirectory(); |
|
48
|
|
|
|
|
49
|
|
|
if ($this->app->runningInConsole()) { |
|
50
|
|
|
$this->commands($this->getConsoleCommands()); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Make sure our directory is setup and ready |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function verifyDirectory() |
|
58
|
|
|
{ |
|
59
|
|
|
try { |
|
60
|
|
|
if (! is_dir(config('env-security.store'))) { |
|
61
|
|
|
if (! mkdir(config('env-security.store'))) { |
|
62
|
|
|
throw new RuntimeException( |
|
63
|
|
|
sprintf('Error creating the cipertext directory - %s', config('env-security.store')) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} catch (\Throwable $e) { |
|
68
|
|
|
throw new RuntimeException( |
|
69
|
|
|
sprintf('Error creating the cipertext directory - %s', config('env-security.store')), |
|
70
|
|
|
$e->getCode(), |
|
71
|
|
|
$e |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Register our console commands |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getConsoleCommands() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->app->environment('testing') |
|
82
|
|
|
? [Decrypt::class, EditDouble::class] |
|
83
|
|
|
: [Decrypt::class, Edit::class]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get the services provided by the provider. |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function provides() |
|
92
|
|
|
{ |
|
93
|
|
|
return ['sts.env-security', EnvSecurityManager::class]; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function register() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->app->singleton(EnvSecurityManager::class, function () { |
|
99
|
|
|
return new EnvSecurityManager($this->app); |
|
100
|
|
|
}); |
|
101
|
|
|
$this->app->alias(EnvSecurityManager::class, 'sts.env-security'); |
|
102
|
|
|
|
|
103
|
|
|
if (is_a($this->app, 'Laravel\Lumen\Application')) { |
|
104
|
|
|
$this->app->configure('env-security'); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
$this->mergeConfigFrom($this->configPath, 'env-security'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.