本文整理汇总了PHP中REST::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::execute方法的具体用法?PHP REST::execute怎么用?PHP REST::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类REST
的用法示例。
在下文中一共展示了REST::execute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
//.........这里部分代码省略.........
$isDeepModel = FALSE;
$deepDatas = array();
$fields = $Model->getFieldKeys();
if (TRUE === $this->restResource['me'] && FALSE === in_array($this->authUserIDFieldName, $fields)) {
// フィールドが無いなら$baseQueryを再初期化
$baseQuery = ' 1=1 ';
$baseBinds = NULL;
}
} catch (Exception $Exception) {
// リソースが存在しない
$this->httpStatus = 404;
throw new RESTException($Exception->getMessage(), $this->httpStatus);
}
// オートバリデート
for ($fieldIdx = 0; $fieldIdx < count($fields); $fieldIdx++) {
if (isset($requestParams[$fields[$fieldIdx]])) {
try {
// XXX intのincrementとdecrimentは許可する
if (FALSE === ('int' === $Model->describes[$fields[$fieldIdx]]['type'] && TRUE === ('increment' === strtolower($requestParams[$fields[$fieldIdx]]) || 'decrement' === strtolower($requestParams[$fields[$fieldIdx]])))) {
// exec系以外はオートバリデート
$Model->validate($fields[$fieldIdx], $requestParams[$fields[$fieldIdx]]);
}
// バリデートに成功したので更新値として認める
$datas[$fields[$fieldIdx]] = $requestParams[$fields[$fieldIdx]];
} catch (Exception $Exception) {
// バリデーションエラー(必須パラメータチェックエラー)
$this->httpStatus = 400;
throw new RESTException($Exception->getMessage(), $this->httpStatus);
break;
}
} elseif (TRUE === $this->deepRESTMode && strlen($fields[$fieldIdx]) - 3 === strpos($fields[$fieldIdx], '_id') && $this->authUserIDFieldName != $fields[$fieldIdx]) {
$deepResource = substr($fields[$fieldIdx], 0, -3);
$deepResourcePath = $deepResource;
if (TRUE === $this->restResource['me']) {
$deepResourcePath = 'me/' . $deepResource;
}
debug('deep??' . $deepResourcePath . ' & ' . $this->authUserIDFieldName . ' & ' . $fields[$fieldIdx] . ' & ' . (strlen($fields[$fieldIdx]) - 3) . ' & ' . strpos($fields[$fieldIdx], '_id'));
$isDeepModel = TRUE;
try {
$deepModel = $this->_getModel($deepResource);
} catch (Exception $Exception) {
$isDeepModel = FALSE;
}
if (TRUE === $isDeepModel) {
// deepRESTを実行し、IDの取得をする
$DeepREST = new REST();
$DeepREST->AuthUser = $this->AuthUser;
$DeepREST->authUserID = $this->authUserID;
$DeepREST->authUserIDFieldName = $this->authUserIDFieldName;
$DeepREST->authUserQuery = $this->authUserQuery;
$DeepREST->rootREST = FALSE;
$res = $DeepREST->execute($deepResourcePath, $requestParams);
$datas[$fields[$fieldIdx]] = $res[0]['id'];
$deepDatas[$deepResource] = $res;
}
} elseif (TRUE === $this->deepRESTMode && $this->authUserIDFieldName == $fields[$fieldIdx]) {
// ログインIDの自動補完
$datas[$fields[$fieldIdx]] = $this->authUserID;
} elseif ($fields[$fieldIdx] == $this->restResourceCreateDateKeyName && TRUE !== 0 < strlen($Model->{$this->restResourceCreateDateKeyName})) {
// データ作成日付の自動補完
$datas[$fields[$fieldIdx]] = $gmtDate;
} elseif ($fields[$fieldIdx] == $this->restResourceModifyDateKeyName) {
// データ更新日付の自動補完
$datas[$fields[$fieldIdx]] = $gmtDate;
}
// Filterがあったらフィルター処理をする
$filerName = str_replace(' ', '', ucwords(str_replace('_', ' ', $this->restResourceModel . ' ' . $fields[$fieldIdx]))) . 'Filter';
debug('$filerName=' . $filerName);
if (FALSE !== MVCCore::loadMVCFilter($filerName, TRUE)) {
$filterClass = MVCCore::loadMVCFilter($filerName);
debug($filterClass);
$Filter = new $filterClass();
$Filter->REST = $this;
$Filter->Model = $Model;
if (!isset($datas[$fields[$fieldIdx]])) {
// 初期化
$datas[$fields[$fieldIdx]] = NULL;
if (0 < strlen($Model->{$fields[$fieldIdx]})) {
$datas[$fields[$fieldIdx]] = $Model->{$fields[$fieldIdx]};
}
}
debug('original value=' . $datas[$fields[$fieldIdx]]);
$filterMethod = 'filter' . ucfirst(strtolower($_SERVER['REQUEST_METHOD']));
$datas[$fields[$fieldIdx]] = $Filter->{$filterMethod}($datas[$fields[$fieldIdx]]);
debug('$filered value=' . $datas[$fields[$fieldIdx]]);
}
}
// POSTに従ってModelを作成する
$Model->save($datas);
// 更新の完了した新しいモデルのデータをレスポンスにセット
$resources[] = $this->_convertArrayFromModel($Model);
if (TRUE === $isDeepModel && 0 < count($deepDatas)) {
foreach ($deepDatas as $key => $val) {
$resources[count($resources) - 1][$key] = $val;
}
}
}
}
return $resources;
}
示例2: execute
/**
* Helper method to execute deferred HTTP requests.
*
* @param $request Request|Batch
* @throws Exception
* @return object of the type of the expected class or array.
*/
public function execute($request)
{
if ($request instanceof Request) {
$request->setUserAgent($this->getApplicationName() . " " . self::USER_AGENT_SUFFIX . $this->getLibraryVersion());
if (!$this->getClassConfig("Request", "disable_gzip")) {
$request->enableGzip();
}
$request->maybeMoveParametersToBody();
return REST::execute($this, $request);
} else {
if ($request instanceof Batch) {
return $request->execute();
} else {
throw new Exception("Do not know how to execute this type of object.");
}
}
}