1+ <?php
2+ namespace Webman \Database ;
3+
4+ class Install
5+ {
6+ const WEBMAN_PLUGIN = true ;
7+
8+ /**
9+ * @var array
10+ */
11+ protected static array $ pathRelation = [];
12+
13+ /**
14+ * Install
15+ * @return void
16+ */
17+ public static function install (): void
18+ {
19+ $ database_file = config_path ('database.php ' );
20+ if (!is_file ($ database_file )) {
21+ echo 'Create config/database.php ' . PHP_EOL ;
22+ copy (__DIR__ . '/config/database.php ' , $ database_file );
23+ }
24+ static ::installByRelation ();
25+ }
26+
27+ /**
28+ * Uninstall
29+ * @return void
30+ */
31+ public static function uninstall (): void
32+ {
33+ $ database_file = config_path ('database.php ' );
34+ if (is_file ($ database_file )) {
35+ echo 'Remove config/database.php ' . PHP_EOL ;
36+ unlink ($ database_file );
37+ }
38+ self ::uninstallByRelation ();
39+ }
40+
41+ /**
42+ * installByRelation
43+ * @return void
44+ */
45+ public static function installByRelation (): void
46+ {
47+ foreach (static ::$ pathRelation as $ source => $ dest ) {
48+ if ($ pos = strrpos ($ dest , '/ ' )) {
49+ $ parent_dir = base_path ().'/ ' .substr ($ dest , 0 , $ pos );
50+ if (!is_dir ($ parent_dir )) {
51+ mkdir ($ parent_dir , 0777 , true );
52+ }
53+ }
54+ copy_dir (__DIR__ . "/ $ source " , base_path ()."/ $ dest " );
55+ }
56+ }
57+
58+ /**
59+ * uninstallByRelation
60+ * @return void
61+ */
62+ public static function uninstallByRelation (): void
63+ {
64+ foreach (static ::$ pathRelation as $ source => $ dest ) {
65+ $ path = base_path ()."/ $ dest " ;
66+ if (!is_dir ($ path ) && !is_file ($ path )) {
67+ continue ;
68+ }
69+ remove_dir ($ path );
70+ }
71+ }
72+
73+ }
0 commit comments