forked from rmariuzzo/Laravel-JS-Localization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaravelJsLocalizationServiceProvider.php
More file actions
97 lines (83 loc) · 2.58 KB
/
LaravelJsLocalizationServiceProvider.php
File metadata and controls
97 lines (83 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Mariuzzo\LaravelJsLocalization;
use Illuminate\Support\ServiceProvider;
/**
* The LaravelJsLocalizationServiceProvider class.
*
* @author Rubens Mariuzzo <rubens@mariuzzo.com>
*/
class LaravelJsLocalizationServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* The path of this package configuration file.
*
* @var string
*/
protected $configPath;
public function __constructor()
{
parent::__constructor();
$this->configPath = $this->app['path.config'].DIRECTORY_SEPARATOR;
}
/**
* Bootstrap the application events.
*/
public function boot()
{
$configPath = __DIR__.'/../../config/config.php';
$configKey = 'localization-js';
// Determines Laravel major version.
$app = $this->app;
$laravelMajorVersion = (int) $app::VERSION;
// Publishes Laravel-JS-Localization package files and merge user and
// package configurations.
if ($laravelMajorVersion === 4) {
$config = $this->app['config']->get($configKey, []);
$this->app['config']->set($configKey, array_merge(require $configPath, $config));
} elseif ($laravelMajorVersion >= 5) {
$this->publishes([
$configPath => config_path("$configKey.php"),
]);
$this->mergeConfigFrom(
$configPath, $configKey
);
}
}
/**
* Register the service provider.
*/
public function register()
{
// Bind the Laravel JS Localization command into the app IOC.
$this->app->singleton('localization.js', function ($app) {
$app = $this->app;
$laravelMajorVersion = (int) $app::VERSION;
$files = $app['files'];
if ($laravelMajorVersion === 4) {
$langs = $app['path.base'].'/app/lang';
} else {
$langs = $app->langPath();
}
$messages = $app['config']->get('localization-js.messages');
$generator = new Generators\LangJsGenerator($files, $langs, $messages);
return new Commands\LangJsCommand($generator);
});
// Bind the Laravel JS Localization command into Laravel Artisan.
$this->commands('localization.js');
}
/**
* Get the services provided by this provider.
*
* @return array
*/
public function provides()
{
return ['localization.js'];
}
}