本文整理汇总了PHP中VuFindSearch\ParamBag::request方法的典型用法代码示例。如果您正苦于以下问题:PHP ParamBag::request方法的具体用法?PHP ParamBag::request怎么用?PHP ParamBag::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VuFindSearch\ParamBag
的用法示例。
在下文中一共展示了ParamBag::request方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
/**
* Send query to SOLR and return response body.
*
* @param string $handler SOLR request handler to use
* @param ParamBag $params Request parameters
*
* @return string Response body
*/
public function query($handler, ParamBag $params)
{
$url = $this->url . '/' . $handler;
$paramString = implode('&', $params->request());
if (strlen($paramString) > self::MAX_GET_URL_LENGTH) {
$method = Request::METHOD_POST;
} else {
$method = Request::METHOD_GET;
}
if ($method === Request::METHOD_POST) {
$client = $this->createClient($url, $method);
$client->setRawBody($paramString);
$client->setEncType(HttpClient::ENC_URLENCODED);
$client->setHeaders(['Content-Length' => strlen($paramString)]);
} else {
$url = $url . '?' . $paramString;
$client = $this->createClient($url, $method);
}
$this->debug(sprintf('Query %s', $paramString));
return $this->send($client);
}
示例2: search
/**
* Perform a search and return record collection.
*
* @param AbstractQuery $query Search query
* @param integer $offset Search offset
* @param integer $limit Search limit
* @param ParamBag $params Search backend parameters
*
*@return \VuFindSearch\Response\RecordCollectionInterface
**/
public function search(AbstractQuery $query, $offset, $limit, ParamBag $params = null)
{
// process EDS API communication tokens.
$authenticationToken = $this->getAuthenticationToken();
$sessionToken = $this->getSessionToken();
$this->debugPrint("Authentication Token: {$authenticationToken}, SessionToken: {$sessionToken}");
// check to see if there is a parameter to only process this call as a setup
if (null !== $params && true == $params->get('setuponly')) {
return false;
}
// create query parameters from VuFind data
$queryString = !empty($query) ? $query->getAllTerms() : '';
$paramsStr = implode('&', null !== $params ? $params->request() : []);
$this->debugPrint("Query: {$queryString}, Limit: {$limit}, Offset: {$offset}, " . "Params: {$paramsStr}");
$baseParams = $this->getQueryBuilder()->build($query);
$paramsStr = implode('&', $baseParams->request());
$this->debugPrint("BaseParams: {$paramsStr} ");
if (null !== $params) {
$baseParams->mergeWith($params);
}
$baseParams->set('resultsPerPage', $limit);
$page = $limit > 0 ? floor($offset / $limit) + 1 : 1;
$baseParams->set('pageNumber', $page);
$searchModel = $this->paramBagToEBSCOSearchModel($baseParams);
$qs = $searchModel->convertToQueryString();
$this->debugPrint("Search Model query string: {$qs}");
try {
$response = $this->client->search($searchModel, $authenticationToken, $sessionToken);
} catch (\EbscoEdsApiException $e) {
// if the auth or session token was invalid, try once more
switch ($e->getApiErrorCode()) {
case 104:
case 108:
case 109:
try {
// For error 104, retry auth token; for 108/9, retry sess token:
if ($e->getApiErrorCode() == 104) {
$authenticationToken = $this->getAuthenticationToken(true);
} else {
$sessionToken = $this->getSessionToken(true);
}
$response = $this->client->search($searchModel, $authenticationToken, $sessionToken);
} catch (Exception $e) {
throw new BackendException($e->getMessage(), $e->getCode(), $e);
}
break;
default:
$response = [];
break;
}
} catch (Exception $e) {
$this->debugPrint("Exception found: " . $e->getMessage());
throw new BackendException($e->getMessage(), $e->getCode(), $e);
}
$collection = $this->createRecordCollection($response);
$this->injectSourceIdentifier($collection);
return $collection;
}
示例3: query
/**
* Send query to SOLR and return response body.
*
* @param string $handler SOLR request handler to use
* @param ParamBag $params Request parameters
*
* @return string Response body
*/
public function query($handler, ParamBag $params)
{
$urlSuffix = '/' . $handler;
$paramString = implode('&', $params->request());
if (strlen($paramString) > self::MAX_GET_URL_LENGTH) {
$method = Request::METHOD_POST;
$callback = function ($client) use($paramString) {
$client->setRawBody($paramString);
$client->setEncType(HttpClient::ENC_URLENCODED);
$client->setHeaders(['Content-Length' => strlen($paramString)]);
};
} else {
$method = Request::METHOD_GET;
$urlSuffix .= '?' . $paramString;
$callback = null;
}
$this->debug(sprintf('Query %s', $paramString));
return $this->trySolrUrls($method, $urlSuffix, $callback);
}