|
1
|
|
|
<?php |
|
2
|
|
|
namespace NwLaravel\ServiceProvider; |
|
3
|
|
|
|
|
4
|
|
|
use Carbon\Carbon; |
|
5
|
|
|
use NwLaravel\Socialite\OlxProvider; |
|
6
|
|
|
use Laravel\Socialite\Facades\Socialite; |
|
7
|
|
|
use NwLaravel\Validation\ValidatorResolver; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
use Symfony\Component\Translation\Translator; |
|
10
|
|
|
use Symfony\Component\Translation\Loader\ArrayLoader; |
|
11
|
|
|
use NwLaravel\Activity\ActivityManager; |
|
12
|
|
|
use NwLaravel\ActivityLog\Commands\CleanLogCommand; |
|
13
|
|
|
/** |
|
14
|
|
|
* Class NwLaravelServiceProvider |
|
15
|
|
|
*/ |
|
16
|
|
|
class NwLaravelServiceProvider extends ServiceProvider |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Indicates if loading of the provider is deferred. |
|
20
|
|
|
* |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $defer = false; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Bootstrap any necessary services. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function boot() |
|
31
|
|
|
{ |
|
32
|
|
|
// Publish config files |
|
33
|
|
|
$this->publishes([ |
|
34
|
|
|
__DIR__.'/../../config/nwlaravel.php' => config_path('nwlaravel.php'), |
|
35
|
|
|
], 'config'); |
|
36
|
|
|
|
|
37
|
|
|
$this->bootValidator(); |
|
38
|
|
|
$this->bootTranslatorCarbon(); |
|
39
|
|
|
$this->bootActivityLog(); |
|
40
|
|
|
$this->bootOlxDriver(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Register the service provider. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function register() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->registerActivityLog(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Boot Translator Carbon |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function bootTranslatorCarbon() |
|
59
|
|
|
{ |
|
60
|
|
|
$locale = $this->app['config']->get('app.locale'); |
|
61
|
|
|
$path = __DIR__.'/../../resources/lang/'.$locale.'/carbon.php'; |
|
62
|
|
|
|
|
63
|
|
|
if (file_exists($path)) { |
|
64
|
|
|
$translator = new Translator($locale); |
|
65
|
|
|
$translator->addLoader('array', new ArrayLoader()); |
|
66
|
|
|
$translator->addResource('array', require $path, $locale); |
|
67
|
|
|
Carbon::setTranslator($translator); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Boot Validator |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function bootValidator() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->app['validator']->resolver(function ($translator, $data, $rules, $messages, $customAttributes) { |
|
79
|
|
|
return new ValidatorResolver($translator, $data, $rules, $messages, $customAttributes); |
|
80
|
|
|
}); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Boot Activity Log |
|
85
|
|
|
* |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function bootActivityLog() |
|
89
|
|
|
{ |
|
90
|
|
|
// Publish migration |
|
91
|
|
|
$files = glob(database_path('/migrations/*_create_activity_log_table.php')); |
|
92
|
|
|
if (count($files) == 0) { |
|
93
|
|
|
$timestamp = date('Y_m_d_His', time()); |
|
94
|
|
|
$this->publishes([ |
|
95
|
|
|
__DIR__ . "/../../migrations/create_activity_log_table.stub" => database_path("/migrations/{$timestamp}_create_activity_log_table.php"), |
|
96
|
|
|
], 'migrations'); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Registero Activity Log |
|
102
|
|
|
* |
|
103
|
|
|
* @return void |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function registerActivityLog() |
|
106
|
|
|
{ |
|
107
|
|
|
$config = $this->app['config']; |
|
108
|
|
|
$handler = $this->app->make($config->get('nwlaravel.activity.handler')); |
|
109
|
|
|
$activityManager = new ActivityManager($handler, $this->app['auth'], $config); |
|
110
|
|
|
|
|
111
|
|
|
$this->app->bind('nwlaravel.activity', $activityManager); |
|
112
|
|
|
$this->app->alias('nwlaravel.activity', ActivityManager::class); |
|
113
|
|
|
|
|
114
|
|
|
$cleanLogCommand = new CleanLogCommand; |
|
|
|
|
|
|
115
|
|
|
$this->app->bind('nwlaravel.command.activity:clean', $cleanLogCommand); |
|
|
|
|
|
|
116
|
|
|
$this->commands(['nwlaravel.command.activity:clean']); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Boot OlxDriver |
|
121
|
|
|
* |
|
122
|
|
|
* @return void |
|
123
|
|
|
*/ |
|
124
|
|
|
protected function bootOlxDriver() |
|
125
|
|
|
{ |
|
126
|
|
|
if (class_exists(Socialite::class)) { |
|
127
|
|
|
Socialite::extend('olx', function ($app) { |
|
128
|
|
|
$config = $app['config']['services.olx']; |
|
129
|
|
|
return new OlxProvider( |
|
130
|
|
|
$app['request'], |
|
131
|
|
|
$config['client_id'], |
|
132
|
|
|
$config['client_secret'], |
|
133
|
|
|
$config['redirect'] |
|
134
|
|
|
); |
|
135
|
|
|
}); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for function calls that miss required arguments.