|
5 | 5 | use App\Models\PeerServer; |
6 | 6 | use Illuminate\Support\Facades\Log; |
7 | 7 | use Illuminate\Support\Facades\Schema; |
| 8 | +use Illuminate\Support\Facades\DB; |
8 | 9 | use Illuminate\Support\ServiceProvider; |
9 | 10 |
|
10 | 11 | class AppServiceProvider extends ServiceProvider |
11 | 12 | { |
12 | 13 |
|
13 | | - // public const ActAsPeerServerKey = 'act_as_peer_server'; |
| 14 | + // public const ActAsPeerServerKey = 'act_as_peer_server'; |
14 | 15 |
|
15 | | - /** |
16 | | - * Register any application services. |
17 | | - * @return void |
18 | | - * @noinspection PhpMissingParentCallCommonInspection |
19 | | - */ |
20 | | - public function register() |
21 | | - { |
22 | | - // |
23 | | - } |
| 16 | + /** |
| 17 | + * Register any application services. |
| 18 | + * @return void |
| 19 | + * @noinspection PhpMissingParentCallCommonInspection |
| 20 | + */ |
| 21 | + public function register() |
| 22 | + { |
| 23 | + // |
| 24 | + } |
24 | 25 |
|
25 | | - /** |
26 | | - * Bootstrap any application services. |
27 | | - * |
28 | | - * @return void |
29 | | - */ |
30 | | - public function boot() |
31 | | - { |
| 26 | + /** |
| 27 | + * Bootstrap any application services. |
| 28 | + * |
| 29 | + * @return void |
| 30 | + */ |
| 31 | + public function boot() |
| 32 | + { |
32 | 33 |
|
33 | | - Schema::defaultStringLength(191); |
| 34 | + try { |
| 35 | + DB::connection(); |
| 36 | + } catch (\Exception $e) { |
| 37 | + Log::warning('Leaving AppServiceProvider because DB connection is not made'); |
| 38 | + return; |
| 39 | + } |
34 | 40 |
|
35 | | - $connection = config('database.default'); |
36 | | - $driver = config("database.connections.{$connection}.driver"); |
37 | | - if ($driver === "sqlite") { |
38 | | - \Illuminate\Support\Facades\DB::getDoctrineSchemaManager() |
39 | | - ->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'string'); |
40 | | - } |
| 41 | + Schema::defaultStringLength(191); |
41 | 42 |
|
42 | | - $me = null; |
43 | | - try { |
| 43 | + $connection = config('database.default'); |
| 44 | + $driver = config("database.connections.{$connection}.driver"); |
| 45 | + if ($driver === "sqlite") { |
| 46 | + \Illuminate\Support\Facades\DB::getDoctrineSchemaManager() |
| 47 | + ->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'string'); |
| 48 | + } |
44 | 49 |
|
45 | | - // TODO if testing and if request contains "act_as_peer_server" then act as another peer |
46 | | - // if (in_array(config('app.env'), ['testing', 'local']) |
47 | | - // && $request->hasHeader(self::ActAsPeerServerKey)) { |
48 | | - // $peerID = intval($request->header(self::ActAsPeerServerKey)); |
49 | | - // Log::warning("Acting as peer server $peerID"); |
50 | | - // $me = PeerServer::findOrFail($peerID); |
51 | | - // } else { |
52 | | - $me = PeerServer::me(false); |
53 | | - // } |
| 50 | + $me = null; |
| 51 | + try { |
54 | 52 |
|
55 | | - } catch (\Exception $e) { |
56 | | - Log::warning('Failed getCurrentServer() in AppServiceProvider'); |
57 | | - } |
58 | | - // take the RSA keypair of the current server for JWT auth |
| 53 | + // TODO if testing and if request contains "act_as_peer_server" then act as another peer |
| 54 | + // if (in_array(config('app.env'), ['testing', 'local']) |
| 55 | + // && $request->hasHeader(self::ActAsPeerServerKey)) { |
| 56 | + // $peerID = intval($request->header(self::ActAsPeerServerKey)); |
| 57 | + // Log::warning("Acting as peer server $peerID"); |
| 58 | + // $me = PeerServer::findOrFail($peerID); |
| 59 | + // } else { |
| 60 | + $me = PeerServer::me(false); |
| 61 | + // } |
59 | 62 |
|
60 | | - if ($me) { |
61 | | - config(['app.locale' => $me->locale]); |
62 | | - // config(['app.timezone' => $me->timezone]); |
63 | | - if ($me->jwt_public_key && $me->jwt_secret_key) { |
64 | | - config(['jwt.keys.private' => $me->jwt_secret_key->toString()]); |
65 | | - config(['jwt.keys.public' => $me->jwt_public_key->toString()]); |
66 | | - } |
67 | | - } |
| 63 | + } catch (\Exception $e) { |
| 64 | + Log::warning('Failed getCurrentServer() in AppServiceProvider'); |
| 65 | + } |
| 66 | + // take the RSA keypair of the current server for JWT auth |
68 | 67 |
|
69 | | - /** |
70 | | - * can be accessed with @see getCurrentServer() |
71 | | - */ |
72 | | - $this->app->singleton('peer_server_me', function ($app) use ($me) { |
73 | | - return $me; |
74 | | - }); |
| 68 | + if ($me) { |
| 69 | + config(['app.locale' => $me->locale]); |
| 70 | + // config(['app.timezone' => $me->timezone]); |
| 71 | + if ($me->jwt_public_key && $me->jwt_secret_key) { |
| 72 | + config(['jwt.keys.private' => $me->jwt_secret_key->toString()]); |
| 73 | + config(['jwt.keys.public' => $me->jwt_public_key->toString()]); |
| 74 | + } |
75 | 75 | } |
| 76 | + |
| 77 | + /** |
| 78 | + * can be accessed with @see getCurrentServer() |
| 79 | + */ |
| 80 | + $this->app->singleton('peer_server_me', function ($app) use ($me) { |
| 81 | + return $me; |
| 82 | + }); |
| 83 | + } |
76 | 84 | } |
0 commit comments