Skip to content

Commit eb2a26f

Browse files
committed
Install
1 parent b40d46b commit eb2a26f

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"description": "Webman database",
66
"require": {
77
"workerman/webman-framework": "^2.0 || dev-master",
8-
"workerman/webman": "^2.0",
98
"webman/coroutine": "^1.0 || dev-main",
109
"illuminate/database": "^10.0",
1110
"laravel/serializable-closure": "^2.0"

src/Install.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

src/config/database.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
return [
3+
'default' => 'mysql',
4+
'connections' => [
5+
'mysql' => [
6+
'driver' => 'mysql',
7+
'host' => '127.0.0.1',
8+
'port' => '3306',
9+
'database' => 'your_database',
10+
'username' => 'your_username',
11+
'password' => 'your_password',
12+
'charset' => 'utf8mb4',
13+
'collation' => 'utf8mb4_general_ci',
14+
'prefix' => '',
15+
'strict' => true,
16+
'engine' => null,
17+
'options' => [
18+
PDO::ATTR_EMULATE_PREPARES => false,
19+
],
20+
'pool' => [
21+
'max_connections' => 5,
22+
'min_connections' => 1,
23+
'wait_timeout' => 3,
24+
'idle_timeout' => 60,
25+
'heartbeat_interval' => 50,
26+
],
27+
],
28+
],
29+
];

0 commit comments

Comments
 (0)