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.
 
 
 
 
 

80 lines
1.8 KiB

  1. <?php
  2. namespace dokuwiki\Extension;
  3. use dokuwiki\Remote\Api;
  4. use dokuwiki\Remote\ApiCall;
  5. use ReflectionException;
  6. use ReflectionMethod;
  7. /**
  8. * Remote Plugin prototype
  9. *
  10. * Add functionality to the remote API in a plugin
  11. */
  12. abstract class RemotePlugin extends Plugin
  13. {
  14. private Api $api;
  15. /**
  16. * Constructor
  17. */
  18. public function __construct()
  19. {
  20. $this->api = new Api();
  21. }
  22. /**
  23. * Get all available methods with remote access.
  24. *
  25. * By default it exports all public methods of a remote plugin. Methods beginning
  26. * with an underscore are skipped.
  27. *
  28. * @return ApiCall[] Information about all provided methods. ('methodname' => ApiCall)
  29. * @throws ReflectionException
  30. */
  31. public function getMethods()
  32. {
  33. $result = [];
  34. $reflection = new \ReflectionClass($this);
  35. foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
  36. // skip parent methods, only methods further down are exported
  37. $declaredin = $method->getDeclaringClass()->name;
  38. if ($declaredin === 'dokuwiki\Extension\Plugin' || $declaredin === 'dokuwiki\Extension\RemotePlugin') {
  39. continue;
  40. }
  41. $method_name = $method->name;
  42. if ($method_name[0] === '_') {
  43. continue;
  44. }
  45. if ($method_name === 'getMethods') {
  46. continue; // skip self, if overridden
  47. }
  48. // add to result
  49. $result[$method_name] = new ApiCall([$this, $method_name], 'plugins');
  50. }
  51. return $result;
  52. }
  53. /**
  54. * @deprecated 2023-11-30
  55. */
  56. public function _getMethods()
  57. {
  58. dbg_deprecated('getMethods()');
  59. }
  60. /**
  61. * @return Api
  62. */
  63. protected function getApi()
  64. {
  65. return $this->api;
  66. }
  67. }