PHP_api接口教程(9)
发布时间:2021-06-06
发布时间:2021-06-06
public function exec($paramsArray) {
if (!isset($paramsArray["method"])) {
trigger_error("No api name passed"); }
$inflector = new LtInflector; $inflector->conf["separator"] = ".";
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"],
7))) . "Request";
if (!class_exists($requestClassName)) {
trigger_error("No such api: " . $paramsArray["method"]); }
$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
$req = new $requestClassName;
foreach($paramsArray as $paraKey => $paraValue) {
$inflector->conf["separator"] = "_";
$setterMethodName = $inflector->camelize($paraKey); $inflector->conf["separator"] = ".";
$setterMethodName = "set" . $inflector->camelize($setterMethodName); if (method_exists($req, $setterMethodName)) {
$req->$setterMethodName($paraValue); } }
return $this->execute($req, $session); } } ?> <?php
$url = "/members/"; $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);