1e1d9dcc8SAndreas Gohr<?php 2e1d9dcc8SAndreas Gohr 3e1d9dcc8SAndreas Gohrnamespace dokuwiki\Extension; 4e1d9dcc8SAndreas Gohr 5e1d9dcc8SAndreas Gohruse dokuwiki\Remote\Api; 642e66c7aSAndreas Gohruse dokuwiki\Remote\ApiCall; 7e1d9dcc8SAndreas Gohruse ReflectionException; 8e1d9dcc8SAndreas Gohruse ReflectionMethod; 9e1d9dcc8SAndreas Gohr 10e1d9dcc8SAndreas Gohr/** 11e1d9dcc8SAndreas Gohr * Remote Plugin prototype 12e1d9dcc8SAndreas Gohr * 13e1d9dcc8SAndreas Gohr * Add functionality to the remote API in a plugin 14e1d9dcc8SAndreas Gohr */ 15e1d9dcc8SAndreas Gohrabstract class RemotePlugin extends Plugin 16e1d9dcc8SAndreas Gohr{ 171490c177SAndreas Gohr private Api $api; 18e1d9dcc8SAndreas Gohr 19e1d9dcc8SAndreas Gohr /** 20e1d9dcc8SAndreas Gohr * Constructor 21e1d9dcc8SAndreas Gohr */ 22e1d9dcc8SAndreas Gohr public function __construct() 23e1d9dcc8SAndreas Gohr { 24e1d9dcc8SAndreas Gohr $this->api = new Api(); 25e1d9dcc8SAndreas Gohr } 26e1d9dcc8SAndreas Gohr 27e1d9dcc8SAndreas Gohr /** 28e1d9dcc8SAndreas Gohr * Get all available methods with remote access. 29e1d9dcc8SAndreas Gohr * 30e1d9dcc8SAndreas Gohr * By default it exports all public methods of a remote plugin. Methods beginning 31e1d9dcc8SAndreas Gohr * with an underscore are skipped. 32e1d9dcc8SAndreas Gohr * 33*1468a128SAndreas Gohr * @return ApiCall[] Information about all provided methods. ('methodname' => ApiCall) 34e1d9dcc8SAndreas Gohr * @throws ReflectionException 35e1d9dcc8SAndreas Gohr */ 3642e66c7aSAndreas Gohr public function getMethods() 37e1d9dcc8SAndreas Gohr { 381490c177SAndreas Gohr $result = []; 39e1d9dcc8SAndreas Gohr 40e1d9dcc8SAndreas Gohr $reflection = new \ReflectionClass($this); 41e1d9dcc8SAndreas Gohr foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { 42e1d9dcc8SAndreas Gohr // skip parent methods, only methods further down are exported 43e1d9dcc8SAndreas Gohr $declaredin = $method->getDeclaringClass()->name; 4427f63a23SAndreas Gohr if ($declaredin === 'dokuwiki\Extension\Plugin' || $declaredin === 'dokuwiki\Extension\RemotePlugin') { 4527f63a23SAndreas Gohr continue; 4627f63a23SAndreas Gohr } 47e1d9dcc8SAndreas Gohr $method_name = $method->name; 4842e66c7aSAndreas Gohr if ($method_name[0] === '_') { 4927f63a23SAndreas Gohr continue; 5027f63a23SAndreas Gohr } 5142e66c7aSAndreas Gohr if($method_name === 'getMethods') { 5242e66c7aSAndreas Gohr continue; // skip self, if overridden 53e1d9dcc8SAndreas Gohr } 54e1d9dcc8SAndreas Gohr 55e1d9dcc8SAndreas Gohr // add to result 5642e66c7aSAndreas Gohr $result[$method_name] = new ApiCall([$this, $method_name]); 57e1d9dcc8SAndreas Gohr } 58e1d9dcc8SAndreas Gohr 59e1d9dcc8SAndreas Gohr return $result; 60e1d9dcc8SAndreas Gohr } 61e1d9dcc8SAndreas Gohr 62e1d9dcc8SAndreas Gohr /** 6342e66c7aSAndreas Gohr * @deprecated 2023-11-30 64e1d9dcc8SAndreas Gohr */ 6542e66c7aSAndreas Gohr public function _getMethods() 66e1d9dcc8SAndreas Gohr { 6742e66c7aSAndreas Gohr dbg_deprecated('getMethods()'); 68e1d9dcc8SAndreas Gohr } 6942e66c7aSAndreas Gohr 7042e66c7aSAndreas Gohr 71e1d9dcc8SAndreas Gohr 72e1d9dcc8SAndreas Gohr /** 73e1d9dcc8SAndreas Gohr * @return Api 74e1d9dcc8SAndreas Gohr */ 75e1d9dcc8SAndreas Gohr protected function getApi() 76e1d9dcc8SAndreas Gohr { 77e1d9dcc8SAndreas Gohr return $this->api; 78e1d9dcc8SAndreas Gohr } 79e1d9dcc8SAndreas Gohr} 80