本文整理汇总了PHP中Api::processRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Api::processRequest方法的具体用法?PHP Api::processRequest怎么用?PHP Api::processRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Api
的用法示例。
在下文中一共展示了Api::processRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
if (isset($_REQUEST['url'])) {
//si por ejemplo pasamos explode('/','////controller///method////args///') el resultado es un array con elem vacios;
//Array ( [0] => [1] => [2] => [3] => [4] => controller [5] => [6] => [7] => method [8] => [9] => [10] => [11] => args [12] => [13] => [14] => )
$url = explode('/', trim($_REQUEST['url']));
//con array_filter() filtramos elementos de un array pasando función callback, que es opcional.
//si no le pasamos función callback, los elementos false o vacios del array serán borrados
//por lo tanto la entre la anterior función (explode) y esta eliminamos los '/' sobrantes de la URL
$url = array_filter($url);
$this->class = $this->instanceClass(strtolower(array_shift($url)));
$this->method = strtolower(array_shift($url));
$this->arguments = $url;
$func = $this->method;
if ($this->class != NULL && (int) method_exists($this->class, $func) > 0) {
if (count($this->arguments) > 0) {
call_user_func_array(array($this->class, $this->method), $this->arguments);
} else {
//si no lo llamamos sin argumentos, al metodo del controlador
call_user_func(array($this->class, $this->method));
}
} else {
$rest = new Rest();
$rest->processErrorResponse('', Rest::STATUS_METHOD_NOT_ALLOWED, self::REQUEST_NOT_FOUND);
}
}
$rest = new Rest();
$rest->processErrorResponse('', Rest::STATUS_METHOD_NOT_ALLOWED, self::REQUEST_NOT_FOUND);
}
}
$api = new Api();
$api->processRequest();
示例2: processRequest
/**
* Overrides parent::processRequest
*
*/
protected function processRequest()
{
// Get request params
$apiKey = self::getRequestVar('_api_key', '/^\\w+$/');
$method = self::getRequestVar('_method', '/^[\\w\\.]+$/');
$globals = self::getRequestVar('_globals');
$server = self::getRequestVar('_compiler');
// the compiler which is calling this api
$configExists = Config::exists($this->configFile);
// Check api-key
if (!$apiKey) {
throw new UserFeedback("You need to provide an api-key to use this API");
}
if ($configExists && !$this->compiler->apiKey) {
throw new UserFeedback("You need to set the api-key in your TinyQueries config-file");
}
if ($configExists && $apiKey != $this->compiler->apiKey) {
throw new UserFeedback("api-key does not match");
}
// Ensure that there is only one compiler which is speaking with this api, otherwise queries might get mixed up
if ($configExists && $server && strpos($this->compiler->server, $server) === false) {
throw new UserFeedback('Compiler which is calling this api does not match with compiler in config');
}
// Set global query params
if ($this->db && $globals) {
$globals = json_decode($globals);
foreach ($globals as $name => $value) {
$this->db->param($name, $value);
}
}
// If no method is send, just do the default request handler for queries
if (!$method) {
return parent::processRequest();
}
// Method mapper
switch ($method) {
case 'compile':
return $this->compile();
case 'createView':
return $this->createView();
case 'deleteQuery':
return $this->deleteQuery();
case 'downloadQueries':
return $this->downloadQueries();
case 'getDbScheme':
return $this->getDbScheme();
case 'getInterface':
return $this->getInterface();
case 'getProject':
return $this->getProject();
case 'getSource':
return $this->getSource();
case 'getSQL':
return $this->getSQL();
case 'getStatus':
return $this->getStatus();
case 'getTermParams':
return $this->getTermParams();
case 'renameQuery':
return $this->renameQuery();
case 'saveSource':
return $this->saveSource();
case 'setup':
return $this->setup();
case 'testApi':
return array("message" => "Api is working");
}
throw new \Exception('Unknown API method');
}