本文整理汇总了PHP中sfWebRequest::getContentType方法的典型用法代码示例。如果您正苦于以下问题:PHP sfWebRequest::getContentType方法的具体用法?PHP sfWebRequest::getContentType怎么用?PHP sfWebRequest::getContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfWebRequest
的用法示例。
在下文中一共展示了sfWebRequest::getContentType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extractParameters
/**
*
* @param sfWebRequest $request
* @return WSRequestParameters
*/
public function extractParameters(sfWebRequest $request)
{
$webRequestParameters = new WSRequestParameters();
$logger = Logger::getLogger('core.webservices');
$requestMethod = $request->getMethod();
$contentType = $request->getContentType();
$logger->debug("HTTP Method: {$requestMethod}, Content-Type: {$contentType}");
$requestParameters = $request->getRequestParameters();
$logger->debug("Request Parameters: " . print_r($requestParameters, true));
if (!isset($requestParameters['ws_method'])) {
throw new WebServiceException('Web service method is not specified', 400);
}
$webServiceMethod = $requestParameters['ws_method'];
$methodParameters = array();
// Checking for deprecated method of sending parameters using an http header
$header = $request->getHttpHeader('ohrm_ws_method_parameters');
if (!empty($header)) {
$methodParameters = json_decode($header, true);
if (!is_array($methodParameters)) {
throw new WebServiceException("header ohrm_ws_method_parameters should be json encoded", 400);
}
} else {
// get request parameters in URL (eg: /empNumber/11) after removing the default parameters
$methodParameters = array_diff_key($requestParameters, array_flip(array('action', 'module', 'ws_method', '_sf_route')));
// Merge with GET parameters
$methodParameters = array_merge($methodParameters, $request->getGetParameters());
// Check for JSON encoded body
if ($contentType === 'application/json') {
$postParams = json_decode(file_get_contents('php://input'), true);
$methodParameters = array_merge($methodParameters, $postParams);
} else {
if ($requestMethod === 'POST') {
$methodParameters = array_merge($methodParameters, $request->getPostParameters());
}
}
}
// $arrayName = $this->getArrayNameForFunction($function);
// if(!array_key_exists($arrayName, $methodParameters)) {
// throw new WebServiceException('Required array name not provided', 404);
// }
$webRequestParameters->setRequestMethod($requestMethod);
$webRequestParameters->setMethod($webServiceMethod);
$webRequestParameters->setParameters($methodParameters);
// $webRequestParameters->setAppId($authenticationParamerters['app_id']);
// $webRequestParameters->setAppToken($authenticationParamerters['app_token']);
// $webRequestParameters->setSessionToken($authenticationParamerters['session_token']);
return $webRequestParameters;
}