1 | <?php |
||
14 | class SquantoServiceProvider extends BaseServiceProvider |
||
15 | { |
||
16 | protected $defer = true; |
||
17 | |||
18 | /** |
||
19 | * @return array |
||
20 | */ |
||
21 | public function provides() |
||
31 | |||
32 | /** |
||
33 | * Bootstrap any application services. |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | 53 | public function boot() |
|
38 | { |
||
39 | 53 | if ($this->app->runningInConsole()) { |
|
40 | 53 | $this->publishes([ |
|
41 | 53 | __DIR__.'/../config/squanto.php' => config_path('squanto.php') |
|
42 | 53 | ], 'config'); |
|
43 | |||
44 | 53 | if (!class_exists('CreateSquantoTables')) { |
|
45 | 1 | $this->publishes([ |
|
46 | 1 | __DIR__.'/../database/migrations/create_squanto_tables.php' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_squanto_tables.php'), |
|
47 | 1 | ], 'migrations'); |
|
48 | } |
||
49 | |||
50 | 53 | $this->commands([ |
|
51 | 53 | ImportTranslationsCommand::class, |
|
52 | CacheTranslationsCommand::class, |
||
53 | ]); |
||
54 | } |
||
55 | 53 | } |
|
56 | |||
57 | /** |
||
58 | * Register our translator |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 53 | public function register() |
|
63 | { |
||
64 | 53 | $this->app['squanto.cache_path'] = $this->getSquantoCachePath(); |
|
65 | 53 | $this->app['squanto.lang_path'] = $this->getSquantoLangPath(); |
|
66 | |||
67 | 53 | $this->registerTranslator(); |
|
68 | |||
69 | 53 | $this->app->bind(CachedTranslationFile::class, function ($app) { |
|
|
|||
70 | return new CachedTranslationFile( |
||
71 | new Filesystem(new Local($this->getSquantoCachePath())) |
||
72 | ); |
||
73 | 53 | }); |
|
74 | |||
75 | 53 | $this->app->bind(LaravelTranslationsReader::class, function ($app) { |
|
76 | 5 | return new LaravelTranslationsReader( |
|
77 | 5 | new Filesystem(new Local($this->getSquantoLangPath())) |
|
78 | ); |
||
79 | 53 | }); |
|
80 | |||
81 | 53 | $this->mergeConfigFrom(__DIR__.'/../config/squanto.php', 'squanto'); |
|
82 | |||
83 | // Load translations in the register method because since 5.4 the boot method for the translation service provider |
||
84 | // doesn't seem to be triggered by the calls to the translator anymore. |
||
85 | 53 | $this->loadTranslationsFrom($this->getSquantoCachePath(), 'squanto'); |
|
86 | 53 | } |
|
87 | |||
88 | 53 | private function registerTranslator() |
|
89 | { |
||
90 | 53 | $this->registerLoader(); |
|
91 | |||
92 | 53 | $this->app->singleton('translator', function ($app) { |
|
93 | |||
94 | 53 | $loader = $app['translation.loader']; |
|
95 | 53 | $locale = $app['config']['app.locale']; |
|
96 | |||
97 | 53 | $trans = new SquantoTranslator($loader, $locale); |
|
98 | |||
99 | 53 | $trans->setFallback($app['config']['app.fallback_locale']); |
|
100 | |||
101 | // Custom Squanto option to display key or null when translation is not found |
||
102 | 53 | $trans->setKeyAsDefault($app['config']['squanto.key_as_default']); |
|
103 | |||
104 | 53 | return $trans; |
|
105 | 53 | }); |
|
106 | 53 | } |
|
107 | |||
108 | 53 | private function getSquantoCachePath() |
|
113 | |||
114 | 53 | private function getSquantoLangPath() |
|
119 | } |
||
120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.