Skip to content

Commit 2bb07a2

Browse files
committed
Install.php
1 parent 4860571 commit 2bb07a2

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

src/Install.php

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

0 commit comments

Comments
 (0)