1 | <?php |
||
2 | |||
3 | namespace JosephNC\Translation; |
||
4 | |||
5 | use Illuminate\Contracts\Foundation\Application; |
||
6 | use Illuminate\Support\Facades\Blade; |
||
7 | use Illuminate\Support\ServiceProvider; |
||
8 | |||
9 | class TranslationServiceProvider extends ServiceProvider |
||
10 | { |
||
11 | /** |
||
12 | * Indicates if loading of the provider is deferred. |
||
13 | * |
||
14 | * @var bool |
||
15 | */ |
||
16 | protected $defer = false; |
||
17 | |||
18 | /** |
||
19 | * Set up the blade directive. |
||
20 | */ |
||
21 | public function boot() |
||
22 | { |
||
23 | Blade::directive('trans', function ( string $text, array $replacements = [], string $to_locale = '' ) { |
||
24 | $translation = __trans( $text, $replacements, $to_locale ); |
||
25 | |||
26 | return "<?php echo $translation ?>"; |
||
27 | }); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Register the service provider. |
||
32 | * |
||
33 | * @method void package(string $package, string $namespace, string $path) |
||
34 | */ |
||
35 | public function register() |
||
36 | { |
||
37 | if (PHP_SESSION_NONE == session_status()) session_start(); // Start Session |
||
38 | |||
39 | // Allow configuration to be publishable. |
||
40 | $this->publishes([ |
||
41 | __DIR__.'/Config/config.php' => config_path('translation.php'), |
||
42 | ], 'config'); |
||
43 | |||
44 | // Allow migrations to be publishable. |
||
45 | $this->publishes([ |
||
46 | __DIR__.'/Migrations/' => base_path('/database/migrations'), |
||
47 | ], 'migrations'); |
||
48 | |||
49 | // Include the helpers file for global `__trans()` function |
||
50 | require_once __DIR__.'/helpers.php'; |
||
51 | |||
52 | // Bind translation to the IoC. |
||
53 | $this->app->bind( 'translation', function ( Application $app ) { |
||
54 | return new Translation( $app ); |
||
55 | } ); |
||
56 | |||
57 | register_shutdown_function( [ $this->app->translation, 'shutdown' ] ); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Get the services provided by the provider. |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | public function provides() : array |
||
66 | { |
||
67 | return ['translation']; |
||
68 | } |
||
69 | } |
||
70 |