本文整理汇总了PHP中Illuminate\Support\Facades\Request::isJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isJson方法的具体用法?PHP Request::isJson怎么用?PHP Request::isJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Request
的用法示例。
在下文中一共展示了Request::isJson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate an array of attributes.
*
* @param ParameterBag|array $attributes
* @param callable|null $callback
*
* @throws ValidationException
*
* @return mixed
*/
public function validate($attributes = [], callable $callback = null)
{
// Unwrap parameter bags
if ($attributes instanceof ParameterBag) {
$attributes = $attributes->all();
}
// Get attributes and create Validator
$validation = $this->validator->make($attributes, $this->getRules($attributes), $this->getMessages());
// Alter rules and stuff
$validation = $this->alterValidation($validation);
if ($validation->fails()) {
$exception = ValidationException::class;
if (class_exists('Dingo\\Api\\Exception\\ResourceException') && (Request::wantsJson() || Request::isJson())) {
$exception = ResourceException::class;
}
throw new $exception('Validation failed', $validation->getMessageBag());
} elseif ($callback) {
return $callback($attributes, $this->model);
}
return true;
}
示例2: push
/**
* Push responses to user agent (browser or external app)
*
* @param array $data Response dasta
* @return mixed Response::json() or Redirect::to()
* @static
*/
public static function push($data = array())
{
$headers = isset($data['headers']) ? $data['headers'] : array();
$secure = isset($data['secure']) ? $data['secure'] : NULL;
$options = isset($data['options']) ? $data['options'] : NULL;
$input = isset($data['input']) ? TRUE : FALSE;
if (Request::ajax() or Request::isJson() or Request::wantsJson()) {
$status = '200';
return Response::json($data, $status, $headers, $options);
} else {
$status = '302';
$response = Redirect::to($data['path'], $status, $headers, $secure);
if (isset($data['errors'])) {
$response->withErrors($data['errors']);
}
if (isset($data['messages'])) {
$response->with($data['messages']);
}
if ($input) {
$response->withInput();
}
return $response;
}
}
示例3: validateMD5Data
/**
* Validate the request MD5 data header.
*
* @param string $clientSecret
* @return boolean
*/
public function validateMD5Data($clientSecret = '')
{
$md5 = $this->header('CONTENT_MD5');
if (parent::isJson()) {
$content = parent::getContent();
if (empty($md5) and empty($content)) {
return true;
}
return md5($content . $clientSecret) == $md5;
}
$input = $this->all();
if (!empty($input)) {
foreach ($input as $key => $item) {
if (str_contains($key, '/')) {
unset($input[$key]);
}
}
}
if (empty($md5) and empty($input)) {
return true;
}
return md5(http_build_query($input) . $clientSecret) == $md5;
}
示例4: __return
/**
* Return a response either view or json.
*
* @param string $status
* @param string $message
* @param obj|array $data
* @param integer $statusCode
* @param string $viewName
* @param array $headers
* @param string $callback
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Illuminate\Routing\ResponseFactory
*/
private function __return($status, $message, $data, $statusCode = 200, $viewName = 'data', $headers = [], $callback = 'callback')
{
if (Request::ajax() || Request::wantsJson() || Request::isJson() || Request::acceptsJson()) {
return $this->responseInJson($status, $message, $data, $statusCode, $headers, $callback);
}
return $this->responseInView(collect(['message' => $message, 'data' => $data]), $viewName);
}
示例5: all
/**
* @return array
*/
public static function all()
{
return Request::isJson() ? Input::json()->all() : Input::all();
}