2
2
3
3
namespace Native \Laravel ;
4
4
5
+ use Illuminate \Foundation \Bootstrap \LoadConfiguration ;
5
6
use Illuminate \Foundation \Console \ServeCommand ;
7
+ use Illuminate \Support \Arr ;
8
+ use Illuminate \Support \Facades \Config ;
9
+ use Illuminate \Support \Facades \Storage ;
6
10
use Spatie \LaravelPackageTools \Package ;
7
11
use Spatie \LaravelPackageTools \PackageServiceProvider ;
8
12
9
13
class NativeServiceProvider extends PackageServiceProvider
10
14
{
15
+ protected $ passThrough = [
16
+ 'NATIVE_PHP_SECRET ' ,
17
+ 'NATIVE_PHP_RUNNING ' ,
18
+ 'NATIVE_PHP_STORAGE_PATH ' ,
19
+ 'NATIVE_PHP_DATABASE_PATH ' ,
20
+ ];
21
+
11
22
public function configurePackage (Package $ package ): void
12
23
{
13
24
$ package
@@ -17,8 +28,41 @@ public function configurePackage(Package $package): void
17
28
->publishesServiceProvider ('NativeAppServiceProvider ' );
18
29
}
19
30
20
- public function bootingPackage ()
31
+ public function packageRegistered ()
32
+ {
33
+ foreach ($ this ->passThrough as $ env ) {
34
+ ServeCommand::$ passthroughVariables [] = $ env ;
35
+ }
36
+
37
+ if (config ('native-php.running ' )) {
38
+ $ this ->configureApp ();
39
+ }
40
+ }
41
+
42
+ protected function configureApp ()
21
43
{
22
- ServeCommand::$ passthroughVariables [] = 'NATIVE_PHP_SECRET ' ;
44
+ $ oldStoragePath = $ this ->app ->storagePath ();
45
+
46
+ $ this ->app ->useStoragePath (config ('native-php.storage_path ' ));
47
+
48
+ // Patch all config values that contain the old storage path
49
+ $ config = Arr::dot (config ()->all ());
50
+
51
+ foreach ($ config as $ key => $ value ) {
52
+ if (is_string ($ value ) && str_contains ($ value , $ oldStoragePath )) {
53
+ $ newValue = str_replace ($ oldStoragePath , config ('native-php.storage_path ' ), $ value );
54
+ config ([$ key => $ newValue ]);
55
+ }
56
+ }
57
+
58
+ config (['database.connections.nativephp ' => [
59
+ 'driver ' => 'sqlite ' ,
60
+ 'url ' => env ('DATABASE_URL ' ),
61
+ 'database ' => config ('native-php.database_path ' ),
62
+ 'prefix ' => '' ,
63
+ 'foreign_key_constraints ' => env ('DB_FOREIGN_KEYS ' , true ),
64
+ ]]);
65
+
66
+ config (['database.default ' => 'nativephp ' ]);
23
67
}
24
68
}
0 commit comments