1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Locale; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Thinktomorrow\Locale\Parsers\RouteParser; |
7
|
|
|
use Thinktomorrow\Locale\Parsers\UrlParser; |
8
|
|
|
use Thinktomorrow\Locale\Values\Config; |
9
|
|
|
|
10
|
|
|
class LocaleServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
66 |
|
public function register() |
13
|
|
|
{ |
14
|
66 |
|
require_once __DIR__.'/helpers.php'; |
15
|
|
|
|
16
|
66 |
|
$this->publishes([ |
17
|
66 |
|
__DIR__.'/config/locale.php' => config_path('thinktomorrow/locale.php'), |
18
|
|
|
]); |
19
|
|
|
|
20
|
66 |
|
$this->mergeConfigFrom( |
21
|
66 |
|
__DIR__.'/config/locale.php', 'thinktomorrow.locale' |
22
|
|
|
); |
23
|
|
|
|
24
|
66 |
|
$this->app->singleton(Detect::class, function ($app) { |
25
|
|
|
return new Detect($app['request'], Config::from($this->getConfigValues())); |
26
|
66 |
|
}); |
27
|
|
|
|
28
|
66 |
|
$this->app->singleton(UrlParser::class, function ($app) { |
29
|
63 |
|
return new UrlParser( |
30
|
63 |
|
$app['Illuminate\Contracts\Routing\UrlGenerator'] |
31
|
|
|
); |
32
|
66 |
|
}); |
33
|
|
|
|
34
|
66 |
|
$this->app->singleton(RouteParser::class, function ($app) { |
35
|
63 |
|
return new RouteParser( |
36
|
63 |
|
$app['Thinktomorrow\Locale\Parsers\UrlParser'], |
37
|
63 |
|
$app['translator'] |
38
|
|
|
); |
39
|
66 |
|
}); |
40
|
|
|
|
41
|
66 |
|
$this->app->singleton(LocaleUrl::class, function ($app) { |
42
|
|
|
return new LocaleUrl( |
43
|
|
|
$app['Thinktomorrow\Locale\Detect'], |
44
|
|
|
$app['Thinktomorrow\Locale\Parsers\UrlParser'], |
45
|
|
|
$app['Thinktomorrow\Locale\Parsers\RouteParser'], |
46
|
|
|
Config::from($this->getConfigValues()) |
47
|
|
|
); |
48
|
66 |
|
}); |
49
|
|
|
|
50
|
|
|
/* |
51
|
|
|
* Facade for getting current active scope |
52
|
|
|
*/ |
53
|
66 |
|
$this->app->singleton('tt-locale-scope', function ($app) { |
54
|
8 |
|
return $app->make(Detect::class)->detectLocale()->getScope(); |
55
|
66 |
|
}); |
56
|
66 |
|
} |
57
|
|
|
|
58
|
|
|
private function getConfigValues() |
59
|
|
|
{ |
60
|
|
|
if (file_exists(config_path('thinktomorrow/locale.php'))) { |
61
|
|
|
return require config_path('thinktomorrow/locale.php'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return require __DIR__.'/config/locale.php'; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|