Install.php 1.5 KB

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