1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UrlSigner\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
6
|
|
|
use Illuminate\Routing\Router; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Spatie\UrlSigner\Laravel\Http\Middleware\ValidateSignature; |
9
|
|
|
use Spatie\UrlSigner\UrlSigner as UrlSignerContract; |
10
|
|
|
|
11
|
|
|
class UrlSignerServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Bootstrap the application events. |
15
|
|
|
*/ |
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$this->setupConfig($this->app); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Setup the config. |
23
|
|
|
* |
24
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
protected function setupConfig(Application $app) |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$source = realpath(__DIR__.'/../config/laravel-url-signer.php'); |
31
|
|
|
$this->publishes([$source => config_path('laravel-url-signer.php')]); |
32
|
|
|
$this->mergeConfigFrom($source, 'laravel-url-signer'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Register the service provider. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function register() |
41
|
|
|
{ |
42
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/laravel-url-signer.php', 'laravel-url-signer'); |
43
|
|
|
|
44
|
|
|
$config = config('laravel-url-signer'); |
45
|
|
|
|
46
|
|
|
$config['signatureKey'] = 'mysecretkey'; |
47
|
|
|
|
48
|
|
|
$this->app->singleton(UrlSignerContract::class, function () use ($config) { |
49
|
|
|
return new UrlSigner( |
50
|
|
|
$config['signatureKey'], |
51
|
|
|
$config['parameters']['expires'], |
52
|
|
|
$config['parameters']['signature'] |
53
|
|
|
); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
$this->app->alias(UrlSignerContract::class, 'url-signer'); |
57
|
|
|
|
58
|
|
|
$this->app[Router::class]->middleware('signedurl', ValidateSignature::class); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.