Install.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Webman\RedisQueue;
  3. class Install
  4. {
  5. const WEBMAN_PLUGIN = true;
  6. /**
  7. * @var array
  8. */
  9. protected static $pathRelation = array (
  10. 'config/plugin/webman/redis-queue' => 'config/plugin/webman/redis-queue',
  11. );
  12. /**
  13. * Install
  14. * @return void
  15. */
  16. public static function install()
  17. {
  18. static::installByRelation();
  19. if (!is_dir(app_path() . '/queue/redis')){
  20. mkdir(app_path() . '/queue/redis', 0777, true);
  21. }
  22. }
  23. /**
  24. * Uninstall
  25. * @return void
  26. */
  27. public static function uninstall()
  28. {
  29. self::uninstallByRelation();
  30. }
  31. /**
  32. * installByRelation
  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. * @return void
  51. */
  52. public static function uninstallByRelation()
  53. {
  54. foreach (static::$pathRelation as $source => $dest) {
  55. $path = base_path()."/$dest";
  56. if (!is_dir($path) && !is_file($path)) {
  57. continue;
  58. }
  59. /*if (is_link($path) {
  60. unlink($path);
  61. }*/
  62. remove_dir($path);
  63. }
  64. }
  65. }