1
|
|
|
<?php namespace Distilleries\Messenger; |
2
|
|
|
|
3
|
|
|
use Distilleries\Messenger\Helpers\Message; |
4
|
|
|
use GuzzleHttp\Client; |
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Illuminate\Foundation\AliasLoader; |
7
|
|
|
use Illuminate\Routing\Router; |
8
|
|
|
|
9
|
|
|
class MessengerLumenServiceProvider extends ServiceProvider { |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
protected $package = 'messenger'; |
13
|
|
|
protected $namespace = 'Distilleries\Messenger\Http\Controllers'; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$this->loadViewsFrom(__DIR__.'/../../views', $this->package); |
19
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../../lang', $this->package); |
20
|
|
|
$this->map(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Register the service provider. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function register() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$this->mergeConfigFrom( |
31
|
|
|
__DIR__.'/../../config/config.php', |
32
|
|
|
$this->package |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->app['messenger'] = $this->app->share(function($app) |
37
|
|
|
{ |
38
|
|
|
return new Message($app['config']->get('messenger'),new Client()); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
$this->alias(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the services provided by the provider. |
46
|
|
|
* |
47
|
|
|
* @return string[] |
48
|
|
|
*/ |
49
|
|
|
public function provides() |
50
|
|
|
{ |
51
|
|
|
return array('messenger'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function alias() { |
56
|
|
|
|
57
|
|
|
$this->app->alias('Route','Illuminate\Support\Facades\Route'); |
58
|
|
|
$this->app->alias('Log','Illuminate\Support\Facades\Log'); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Define the routes for the application. |
64
|
|
|
* |
65
|
|
|
* @param \Illuminate\Routing\Router $router |
|
|
|
|
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function map() |
69
|
|
|
{ |
70
|
|
|
$this->app->group(['namespace' => $this->namespace], function($app) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
require __DIR__ . '/Http/routes_lumen.php'; |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.