本文整理汇总了PHP中CB\Config::getApiFunctions方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getApiFunctions方法的具体用法?PHP Config::getApiFunctions怎么用?PHP Config::getApiFunctions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CB\Config
的用法示例。
在下文中一共展示了Config::getApiFunctions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _doRpc
/**
* Remote procedure call.
*
* Execute api function.
*
* @param \stdObject $cdata
* @return array
* @throws \CB\Controller\Exception
*/
private function _doRpc($cdata)
{
$api = \CB\Config::getApiFunctions();
if (!isset($api[$cdata['action']])) {
throw new \CB\Controller\Exception('Call to undefined action: ' . $cdata['action']);
}
$action = $cdata['action'];
$a = $api[$action];
$this->_doAroundCalls($a['before'], $cdata);
$method = $cdata['method'];
$mdef = $a['methods'][$method];
if (!$mdef) {
throw new \CB\Controller\Exception('Call to undefined method: ' . $method . ' on action $action');
}
$this->_doAroundCalls($mdef['before'], $cdata);
$r = array('type' => 'rpc', 'tid' => $cdata['tid'], 'action' => $action, 'method' => $method);
// load api controller
$Class = '\\CB\\Api\\' . $action;
$Controller = $Class::getInstance();
// build function params
if (isset($mdef['len'])) {
$params = isset($cdata['data']) && is_array($cdata['data']) ? $cdata['data'] : array();
} else {
$params = array($cdata['data']);
}
// prepare fields and values
array_walk($params, function ($param) {
(array) $param;
});
// call api controller function
$r['result'] = call_user_func_array(array($Controller, $method), $params);
$this->_doAroundCalls($mdef['after'], $cdata, $r);
$this->_doAroundCalls($a['after'], $cdata, $r);
return $r;
}
示例2: __construct
/**
* Api info controller
*
* @access public
* @return void
*/
public function __construct()
{
// convert API functions to Ext.Direct specs
$actions = array();
$api = \CB\Config::getApiFunctions();
foreach ($api as $aname => &$a) {
$methods = array();
foreach ($a['methods'] as $mname => &$m) {
if (isset($m['len'])) {
$md = array('name' => $mname, 'len' => $m['len']);
} else {
$md = array('name' => $mname, 'params' => $m['params']);
}
if (isset($m['formHandler']) && $m['formHandler']) {
$md['formHandler'] = true;
}
$methods[] = $md;
}
$actions[$aname] = $methods;
}
// API specs
$api = array('url' => \CB\Config::get('folder.root') . '/api/router/', 'namespace' => 'CB.api', 'type' => 'remoting', 'actions' => $actions);
// send javascript headers
header('Content-Type: text/javascript');
// init api
$response = 'var CB = {}; CB.init = {};';
$response .= 'CB.init.API=' . json_encode($api) . ';';
// init config
$config = $this->getApiController('Config')->read();
if ($config['success']) {
$response .= 'CB.init.Config=' . json_encode($config['data']) . ';';
}
// init session user
$user = $this->getApiController('User')->readSession();
if ($user['success']) {
$response .= 'CB.init.User=' . json_encode($user['data']) . ';';
}
/*
$countries = $this->getApiController('Country')->read()['data'];
$response .= 'CB.init.Countries=' . json_encode($countries) . ';';
$locations = $this->getApiController('Location')->read()['data'];
$response .= 'CB.init.Locations=' . json_encode($locations) . ';';
$locationTypes = $this->getApiController('LocationType')->read()['data'];
$response .= 'CB.init.LocationTypes=' . json_encode($locationTypes) . ';';
$gradeTypes = $this->getApiController('GradeTypes')->read()['data'];
$response .= 'CB.init.GradeTypes=' . json_encode($gradeTypes) . ';';
*/
echo $response;
exit;
die;
}