1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nikaia\TranslationSheet; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Nikaia\TranslationSheet\Util; |
7
|
|
|
use Nikaia\TranslationSheet\Client\Client; |
8
|
|
|
use Nikaia\TranslationSheet\Commands\Lock; |
9
|
|
|
use Nikaia\TranslationSheet\Commands\Open; |
10
|
|
|
use Nikaia\TranslationSheet\Commands\Prepare; |
11
|
|
|
use Nikaia\TranslationSheet\Commands\Pull; |
12
|
|
|
use Nikaia\TranslationSheet\Commands\Push; |
13
|
|
|
use Nikaia\TranslationSheet\Commands\Setup; |
|
|
|
|
14
|
|
|
use Nikaia\TranslationSheet\Commands\Status; |
15
|
|
|
use Nikaia\TranslationSheet\Commands\Unlock; |
16
|
|
|
|
17
|
|
|
class TranslationSheetServiceProvider extends ServiceProvider |
18
|
35 |
|
{ |
19
|
|
|
public function boot() |
20
|
35 |
|
{ |
21
|
35 |
|
$this->publishes([ |
22
|
35 |
|
__DIR__.'/../config/config.php' => config_path('translation_sheet.php'), |
23
|
35 |
|
], 'config'); |
24
|
|
|
} |
25
|
35 |
|
|
26
|
|
|
public function register() |
27
|
35 |
|
{ |
28
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'translation_sheet'); |
29
|
35 |
|
|
30
|
|
|
$this->registerGoogleApiClient(); |
31
|
35 |
|
|
32
|
|
|
$this->registerSpreadsheet(); |
33
|
35 |
|
|
34
|
35 |
|
$this->registerCommands(); |
35
|
|
|
} |
36
|
35 |
|
|
37
|
|
|
private function registerGoogleApiClient() |
38
|
|
|
{ |
39
|
18 |
|
$this->app->singleton(Client::class, function () { |
40
|
18 |
|
return Client::create( |
41
|
18 |
|
$this->app['config']['translation_sheet.serviceAccountCredentialsFile'], |
42
|
18 |
|
$this->app['config']['translation_sheet.googleApplicationName'] |
43
|
35 |
|
); |
44
|
35 |
|
}); |
45
|
|
|
} |
46
|
35 |
|
|
47
|
|
|
private function registerSpreadsheet() |
48
|
|
|
{ |
49
|
1 |
|
$this->app->singleton(Spreadsheet::class, function () { |
50
|
1 |
|
return new Spreadsheet( |
51
|
1 |
|
$this->app['config']['translation_sheet.spreadsheetId'], |
52
|
1 |
|
Util::asArray($this->app['config']['translation_sheet.locales']) |
53
|
35 |
|
); |
54
|
35 |
|
}); |
55
|
|
|
} |
56
|
35 |
|
|
57
|
|
|
private function registerCommands() |
58
|
35 |
|
{ |
59
|
35 |
|
$this->commands([ |
60
|
35 |
|
Setup::class, |
61
|
35 |
|
Push::class, |
62
|
35 |
|
Pull::class, |
63
|
35 |
|
Prepare::class, |
64
|
35 |
|
Lock::class, |
65
|
35 |
|
Unlock::class, |
66
|
35 |
|
Status::class, |
67
|
35 |
|
Open::class, |
68
|
35 |
|
]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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: