1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nikaia\TranslationSheet; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Nikaia\TranslationSheet\Client\Client; |
7
|
|
|
use Nikaia\TranslationSheet\Commands\Lock; |
8
|
|
|
use Nikaia\TranslationSheet\Commands\Open; |
9
|
|
|
use Nikaia\TranslationSheet\Commands\Prepare; |
10
|
|
|
use Nikaia\TranslationSheet\Commands\Pull; |
11
|
|
|
use Nikaia\TranslationSheet\Commands\Push; |
12
|
|
|
use Nikaia\TranslationSheet\Commands\Setup; |
|
|
|
|
13
|
|
|
use Nikaia\TranslationSheet\Commands\Status; |
14
|
|
|
use Nikaia\TranslationSheet\Commands\Unlock; |
15
|
|
|
|
16
|
|
|
class TranslationSheetServiceProvider extends ServiceProvider |
17
|
|
|
{ |
18
|
36 |
|
public function boot() |
19
|
|
|
{ |
20
|
36 |
|
$this->publishes([ |
21
|
36 |
|
__DIR__.'/../config/config.php' => config_path('translation_sheet.php'), |
22
|
36 |
|
], 'config'); |
23
|
36 |
|
} |
24
|
|
|
|
25
|
36 |
|
public function register() |
26
|
|
|
{ |
27
|
36 |
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'translation_sheet'); |
28
|
|
|
|
29
|
36 |
|
$this->registerGoogleApiClient(); |
30
|
|
|
|
31
|
36 |
|
$this->registerSpreadsheet(); |
32
|
|
|
|
33
|
36 |
|
$this->registerCommands(); |
34
|
36 |
|
} |
35
|
|
|
|
36
|
36 |
|
private function registerGoogleApiClient() |
37
|
|
|
{ |
38
|
|
|
$this->app->singleton(Client::class, function () { |
39
|
18 |
|
return Client::create( |
40
|
18 |
|
$this->app['config']['translation_sheet.serviceAccountCredentialsFile'], |
41
|
18 |
|
$this->app['config']['translation_sheet.googleApplicationName'] |
42
|
|
|
); |
43
|
36 |
|
}); |
44
|
36 |
|
} |
45
|
|
|
|
46
|
36 |
|
private function registerSpreadsheet() |
47
|
|
|
{ |
48
|
|
|
$this->app->singleton(Spreadsheet::class, function () { |
49
|
1 |
|
return new Spreadsheet( |
50
|
1 |
|
$this->app['config']['translation_sheet.spreadsheetId'], |
51
|
1 |
|
Util::asArray($this->app['config']['translation_sheet.locales']) |
52
|
|
|
); |
53
|
36 |
|
}); |
54
|
36 |
|
} |
55
|
|
|
|
56
|
36 |
|
private function registerCommands() |
57
|
|
|
{ |
58
|
36 |
|
$this->commands([ |
59
|
36 |
|
Setup::class, |
60
|
|
|
Push::class, |
61
|
|
|
Pull::class, |
62
|
|
|
Prepare::class, |
63
|
|
|
Lock::class, |
64
|
|
|
Unlock::class, |
65
|
|
|
Status::class, |
66
|
|
|
Open::class, |
67
|
|
|
]); |
68
|
36 |
|
} |
69
|
|
|
} |
70
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: