Install.php 1.6 KB

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