Install.php 1.3 KB

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