Install.php 1.7 KB

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