webman
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace support;
  3. class Plugin
  4. {
  5. public static function install($event)
  6. {
  7. static::findHepler();
  8. $operation = $event->getOperation();
  9. $autoload = method_exists($operation, 'getPackage') ? $operation->getPackage()->getAutoload() : $operation->getTargetPackage()->getAutoload();
  10. if (!isset($autoload['psr-4'])) {
  11. return;
  12. }
  13. foreach ($autoload['psr-4'] as $namespace => $path) {
  14. $install_function = "\\{$namespace}Install::install";
  15. $plugin_const = "\\{$namespace}Install::WEBMAN_PLUGIN";
  16. if (defined($plugin_const) && is_callable($install_function)) {
  17. $install_function();
  18. }
  19. }
  20. }
  21. public static function update($event)
  22. {
  23. static::install($event);
  24. }
  25. public static function uninstall($event)
  26. {
  27. static::findHepler();
  28. $autoload = $event->getOperation()->getPackage()->getAutoload();
  29. if (!isset($autoload['psr-4'])) {
  30. return;
  31. }
  32. foreach ($autoload['psr-4'] as $namespace => $path) {
  33. $uninstall_function = "\\{$namespace}Install::uninstall";
  34. $plugin_const = "\\{$namespace}Install::WEBMAN_PLUGIN";
  35. if (defined($plugin_const) && is_callable($uninstall_function)) {
  36. $uninstall_function();
  37. }
  38. }
  39. }
  40. protected static function findHepler()
  41. {
  42. // Plugin.php in vendor
  43. $file = __DIR__ . '/../../../../../support/helpers.php';
  44. if (is_file($file)) {
  45. require_once $file;
  46. return;
  47. }
  48. // Plugin.php in webman
  49. require_once __DIR__ . '/helpers.php';
  50. }
  51. }