4
4
5
5
use Illuminate \Support \Arr ;
6
6
use Native \Laravel \Commands \LoadStartupConfigurationCommand ;
7
+ use Native \Laravel \Commands \MigrateCommand ;
7
8
use Native \Laravel \Commands \MinifyApplicationCommand ;
8
9
use Native \Laravel \Logging \LogWatcher ;
9
10
use Spatie \LaravelPackageTools \Package ;
@@ -16,6 +17,7 @@ public function configurePackage(Package $package): void
16
17
$ package
17
18
->name ('nativephp ' )
18
19
->hasCommands ([
20
+ MigrateCommand::class,
19
21
MinifyApplicationCommand::class,
20
22
LoadStartupConfigurationCommand::class,
21
23
])
@@ -28,6 +30,10 @@ public function packageRegistered()
28
30
{
29
31
$ this ->mergeConfigFrom ($ this ->package ->basePath ('/../config/nativephp-internal.php ' ), 'nativephp-internal ' );
30
32
33
+ $ this ->app ->singleton (MigrateCommand::class, function ($ app ) {
34
+ return new MigrateCommand ($ app ['migrator ' ], $ app ['events ' ]);
35
+ });
36
+
31
37
if (config ('nativephp-internal.running ' )) {
32
38
$ this ->configureApp ();
33
39
}
@@ -39,6 +45,20 @@ protected function configureApp()
39
45
app (LogWatcher::class)->register ();
40
46
}
41
47
48
+ $ this ->rewriteStoragePath ();
49
+
50
+ $ this ->rewriteDatabase ();
51
+
52
+ config (['session.driver ' => 'file ' ]);
53
+ config (['queue.default ' => 'database ' ]);
54
+ }
55
+
56
+ protected function rewriteStoragePath ()
57
+ {
58
+ if (config ('app.debug ' )) {
59
+ return ;
60
+ }
61
+
42
62
$ oldStoragePath = $ this ->app ->storagePath ();
43
63
44
64
$ this ->app ->useStoragePath (config ('nativephp-internal.storage_path ' ));
@@ -52,18 +72,28 @@ protected function configureApp()
52
72
config ([$ key => $ newValue ]);
53
73
}
54
74
}
75
+ }
76
+
77
+ public function rewriteDatabase ()
78
+ {
79
+ $ databasePath = config ('nativephp-internal.database_path ' );
80
+
81
+ if (config ('app.debug ' )) {
82
+ $ databasePath = database_path ('nativephp.sqlite ' );
83
+
84
+ if (! file_exists ($ databasePath )) {
85
+ touch ($ databasePath );
86
+ }
87
+ }
55
88
56
89
config (['database.connections.nativephp ' => [
57
90
'driver ' => 'sqlite ' ,
58
91
'url ' => env ('DATABASE_URL ' ),
59
- 'database ' => config ( ' nativephp-internal.database_path ' ) ,
92
+ 'database ' => $ databasePath ,
60
93
'prefix ' => '' ,
61
94
'foreign_key_constraints ' => env ('DB_FOREIGN_KEYS ' , true ),
62
95
]]);
63
96
64
97
config (['database.default ' => 'nativephp ' ]);
65
- config (['session.driver ' => 'file ' ]);
66
-
67
- config (['queue.default ' => 'database ' ]);
68
98
}
69
99
}
0 commit comments