@@ -28,9 +28,8 @@ class Api_IndexController extends Api_AppController
28
28
public $ _components = array ('Upload ' , 'Search ' , 'Uuid ' , 'Sortdao ' );
29
29
30
30
var $ kwWebApiCore = null ;
31
-
32
- // Use this parameter to map API methods to your protected or private controller methods
33
31
var $ apicallbacks = array ();
32
+ var $ helpContent = array ();
34
33
35
34
// Config parameters
36
35
var $ apiEnable = '' ;
@@ -48,7 +47,6 @@ function preDispatch()
48
47
$ modulesConfig = Zend_Registry::get ('configsModules ' );
49
48
$ this ->apiSetup ['apiMethodPrefix ' ] = $ modulesConfig ['api ' ]->methodprefix ;
50
49
51
- $ this ->_setApiCallbacks ($ this ->apiSetup ['apiMethodPrefix ' ]);
52
50
$ this ->action = $ actionName = Zend_Controller_Front::getInstance ()->getRequest ()->getActionName ();
53
51
switch ($ this ->action )
54
52
{
@@ -68,6 +66,7 @@ function preDispatch()
68
66
function indexAction ()
69
67
{
70
68
$ this ->view ->header = 'Web API ' ;
69
+ $ this ->_computeApiHelp ($ this ->apiSetup ['apiMethodPrefix ' ]);
71
70
72
71
// Prepare the data used by the view
73
72
$ data = array (
@@ -81,10 +80,42 @@ function indexAction()
81
80
$ this ->view ->serverURL = $ this ->getServerURL ();
82
81
}
83
82
84
- /** Set the call back API */
85
- private function _setApiCallbacks ($ apiMethodPrefix )
83
+ /** This is called when calling a web api method */
84
+ private function _computeApiCallback ($ method_name , $ apiMethodPrefix )
85
+ {
86
+ $ tokens = explode ('. ' , $ method_name );
87
+ if (array_shift ($ tokens ) != $ apiMethodPrefix ) //pop off the method prefix token
88
+ {
89
+ return ; //let the web API core write out its method doesn't exist message
90
+ }
91
+
92
+ $ method = implode ($ tokens );
93
+ if (method_exists ($ this , $ method ))
94
+ {
95
+ $ this ->apicallbacks [$ method_name ] = array (&$ this , $ method );
96
+ }
97
+ else //it doesn't exist here, check in the module specified by the 2nd token
98
+ {
99
+ $ moduleName = array_shift ($ tokens );
100
+ $ moduleMethod = implode ('' , $ tokens );
101
+ $ retVal = Zend_Registry::get ('notifier ' )->callback ('CALLBACK_API_METHOD_ ' .strtoupper ($ moduleName ), array ());
102
+ // print_r($retVal);
103
+ // exit;
104
+ /*foreach($additionalMethods as $module => $methods)
105
+ {
106
+ foreach($methods as $method)
107
+ {
108
+ $this->helpContent[$apiMethodPrefix.strtolower($module).'.'.$method['name']] = $method['help'];
109
+ $this->apicallbacks[$apiMethodPrefix.strtolower($module).'.'.$method['name']] = array($method['callbackObject'], $method['callbackFunction']);
110
+ }
111
+ }*/
112
+ }
113
+ }
114
+
115
+ /** This index function uses this to display the list of web api methods */
116
+ private function _computeApiHelp ($ apiMethodPrefix )
86
117
{
87
- $ apiMethodPrefix = KwWebApiCore::checkApiMethodPrefix ($ apiMethodPrefix );
118
+ $ apiMethodPrefix = KwWebApiCore::checkApiMethodPrefix ($ apiMethodPrefix ); //append the . if needed
88
119
89
120
$ help = array ();
90
121
$ help ['params ' ] = array ();
@@ -375,8 +406,8 @@ private function _setApiCallbacks($apiMethodPrefix)
375
406
$ this ->helpContent [$ apiMethodPrefix .'item.getmetadata ' ] = $ help ;
376
407
$ this ->apicallbacks [$ apiMethodPrefix .'item.getmetadata ' ] = array (&$ this , 'itemGetMetadata ' );
377
408
378
- // Extend web API to other modules via CALLBACK_API_METHODS
379
- $ additionalMethods = Zend_Registry::get ('notifier ' )->callback ('CALLBACK_API_METHODS ' , array ());
409
+ // Get the lists from other modules
410
+ $ additionalMethods = Zend_Registry::get ('notifier ' )->callback ('CALLBACK_API_HELP ' , array ());
380
411
foreach ($ additionalMethods as $ module => $ methods )
381
412
{
382
413
foreach ($ methods as $ method )
@@ -423,6 +454,7 @@ function restAction()
423
454
}
424
455
425
456
$ request_data = $ this ->_getAllParams ();
457
+ $ this ->_computeApiCallback ($ method_name , $ this ->apiSetup ['apiMethodPrefix ' ]);
426
458
// Handle XML-RPC request
427
459
$ this ->kwWebApiCore = new KwWebApiRestCore ($ this ->apiSetup , $ this ->apicallbacks , $ request_data );
428
460
}
@@ -443,6 +475,7 @@ function jsonAction()
443
475
}
444
476
445
477
$ request_data = $ this ->_getAllParams ();
478
+ $ this ->_computeApiCallback ($ method_name , $ this ->apiSetup ['apiMethodPrefix ' ]);
446
479
// Handle XML-RPC request
447
480
$ this ->kwWebApiCore = new KwWebApiRestCore ($ this ->apiSetup , $ this ->apicallbacks , array_merge ($ request_data , array ('format ' => 'json ' )));
448
481
}
0 commit comments