1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Laravel MultiLang package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Longman\LaravelMultiLang; |
12
|
|
|
|
13
|
|
|
use Illuminate\Support\ServiceProvider; |
14
|
|
|
use Longman\LaravelMultiLang\Console\MigrationCommand; |
15
|
|
|
use Longman\LaravelMultiLang\Console\TextsCommand; |
16
|
|
|
use Blade; |
17
|
|
|
|
18
|
|
|
class MultiLangServiceProvider extends ServiceProvider |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Indicates if loading of the provider is deferred. |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $defer = false; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bootstrap any application services. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
33 |
|
public function boot() |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
// Publish config files |
37
|
33 |
|
$this->publishes([__DIR__ . '/../config/config.php' => config_path('multilang.php')]); |
38
|
|
|
|
39
|
|
|
// Append the country settings |
40
|
33 |
|
$this->mergeConfigFrom( |
41
|
33 |
|
__DIR__ . '/../config/config.php', |
42
|
33 |
|
'multilang' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
// Register blade directives |
46
|
|
|
Blade::directive('t', function ($expression) { |
47
|
|
|
return "<?php echo e(t({$expression})); ?>"; |
48
|
33 |
|
}); |
49
|
|
|
|
50
|
33 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Register any application services. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
33 |
|
public function register() |
58
|
|
|
{ |
59
|
33 |
|
$configPath = __DIR__ . '/../config/config.php'; |
60
|
33 |
|
$this->mergeConfigFrom($configPath, 'debugbar'); |
61
|
|
|
|
62
|
|
|
$this->app->singleton('multilang', function ($app) { |
63
|
3 |
|
$environment = $app->environment(); |
64
|
3 |
|
$config = $app['config']->get('multilang'); |
65
|
|
|
|
66
|
3 |
|
$multilang = new \Longman\LaravelMultiLang\MultiLang( |
67
|
|
|
$environment, |
68
|
|
|
$config, |
69
|
3 |
|
$app['cache'], |
70
|
3 |
|
$app['db'] |
71
|
|
|
); |
72
|
|
|
|
73
|
3 |
|
if ($multilang->autoSaveIsAllowed()) { |
74
|
|
|
$app->terminating(function () use ($multilang) { |
75
|
|
|
return $multilang->saveTexts(); |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
|
79
|
3 |
|
return $multilang; |
80
|
33 |
|
}); |
81
|
|
|
|
82
|
33 |
|
$this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang'); |
83
|
|
|
|
84
|
33 |
|
$this->app['command.multilang.migration'] = $this->app->share( |
85
|
|
|
function () { |
86
|
|
|
return new MigrationCommand(); |
87
|
33 |
|
} |
88
|
|
|
); |
89
|
|
|
|
90
|
33 |
|
$this->app['command.multilang.texts'] = $this->app->share( |
91
|
33 |
|
function () { |
92
|
|
|
return new TextsCommand(); |
93
|
33 |
|
} |
94
|
|
|
); |
95
|
|
|
|
96
|
33 |
|
$this->commands(['command.multilang.migration', 'command.multilang.texts']); |
97
|
|
|
|
98
|
33 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the services provided by the provider. |
102
|
|
|
* |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
3 |
|
public function provides() |
106
|
|
|
{ |
107
|
|
|
return [ |
108
|
3 |
|
'multilang', 'command.multilang.migration', |
109
|
|
|
'command.multilang.texts', 'Longman\LaravelMultiLang\MultiLang' |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|