@@ -78,6 +78,16 @@ public function setReturnFormat($return_format)
78
78
79
79
public function __call ($ fn , $ params )
80
80
{
81
+ // parse parameters
82
+ $ apiparams = array ();
83
+ if (count ($ params ) > 0 ) {
84
+ if (is_array ($ params [0 ])) {
85
+ $ apiparams = $ params [0 ];
86
+ } else {
87
+ parse_str ($ params [0 ], $ apiparams );
88
+ }
89
+ }
90
+
81
91
// map function name to API method
82
92
$ method = '' ;
83
93
@@ -90,29 +100,31 @@ public function __call($fn, $params)
90
100
$ method .= $ path [$ i ];
91
101
}
92
102
93
- // replace AA by {aa}
103
+ // replace AA by URL parameters
104
+ $ method2 = $ method ;
94
105
$ match = array ();
95
106
if (preg_match ('/[A-Z]{2,}/ ' , $ method , $ match )) {
96
- print_r ($ match );
97
- die ();
107
+ foreach ($ match as $ param ) {
108
+ $ param_l = strtolower ($ param );
109
+ if (! isset ($ apiparams [$ param_l ])) {
110
+ throw new Exception ('To call the templated method " ' . $ method
111
+ . '", specify the parameter value for " ' . $ param_l . '". ' );
112
+ }
113
+ $ method = str_replace ($ param , $ apiparams [$ param_l ], $ method );
114
+ $ method2 = str_replace ($ param , ': ' . $ param_l , $ method2 );
115
+ unset($ apiparams [$ param_l ]);
116
+ }
98
117
}
99
118
100
119
// replace A-Z by _a-z
101
120
for ($ i = 0 ; $ i < 26 ; $ i ++) {
102
121
$ method = str_replace (chr (65 + $ i ), '_ ' . chr (97 + $ i ), $ method );
122
+ $ method2 = str_replace (chr (65 + $ i ), '_ ' . chr (97 + $ i ), $ method2 );
103
123
}
104
- $ httpmethod = $ this ->_detectMethod ($ method );
105
- $ sign = $ this ->_detectSign ($ method );
106
- $ multipart = $ this ->_detectMultipart ($ method );
107
124
108
- $ apiparams = array ();
109
- if (count ($ params ) > 0 ) {
110
- if (is_array ($ params [0 ])) {
111
- $ apiparams = $ params [0 ];
112
- } else {
113
- parse_str ($ params [0 ], $ apiparams );
114
- }
115
- }
125
+ $ httpmethod = $ this ->_detectMethod ($ method2 );
126
+ $ sign = $ this ->_detectSign ($ method2 );
127
+ $ multipart = $ this ->_detectMultipart ($ method2 );
116
128
117
129
return $ this ->_callApi ($ httpmethod , $ method , $ apiparams , $ sign , $ multipart );
118
130
}
@@ -339,7 +351,7 @@ private function _detectMethod($method)
339
351
return $ httpmethod ;
340
352
}
341
353
}
342
- return null ;
354
+ throw new Exception ( ' Can \' t find HTTP method to use for " ' . $ method . ' ". ' ) ;
343
355
}
344
356
345
357
/**
0 commit comments