本文整理汇总了PHP中Illuminate\Http\Request::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::format方法的具体用法?PHP Request::format怎么用?PHP Request::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::format方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->format() == 'json') {
return $next($request);
} else {
abort(403, 'Wrong Accept Header');
}
}
示例2: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
$topics = Topic::orderBy('status', 'asc')->orderBy('sorter', 'desc')->get();
if ($request->format() != 'html') {
return $topics;
} else {
return view('topic.index', ['topics' => $topics]);
}
}
示例3: show
public function show(Request $request)
{
$page = Router::getActivePage();
$format = $request->format();
if ($request->route() && $request->route()->getParameter('format')) {
$format = $request->route()->getParameter('format');
}
$method = 'as' . ucfirst($format);
if (method_exists($this, $method)) {
return $this->{$method}($page);
}
abort(406);
}
示例4: onBefore
/**
* Check the Request before running it through the router.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response|null
*/
public function onBefore($request)
{
$keys = $this->app['config']->get('api-inspector');
App::bind('Pusher', function ($app) {
$keys = $this->app['config']->get('api-inspector');
return new \Pusher($keys['public'], $keys['secret'], $keys['app_id']);
});
if ($keys['active'] == false) {
return;
}
App::make('Pusher')->trigger('apiChannel', 'apiCall', ['method' => $request->method(), 'root' => $request->root(), 'url' => $request->url(), 'path' => $request->path(), 'ajax' => $request->ajax(), 'ip' => $request->ip(), 'input' => $request->all(), 'is-json' => $request->isJson(), 'format' => $request->format(), 'session' => json_encode($request->session()), 'header' => $request->header(), 'input-json' => json_encode($request->json()), 'wants-json' => $request->wantsJson()]);
return;
}
示例5: make
/**
* 以客户端需求自动转换响应格式
*
* @param array $data
* @param string $message
* @param int $code
* @param null|string $format
*
* @return Response
*/
public function make($data = array(), $message = '', $code = 0, $format = null)
{
!empty($data) && $this->setData($data);
!empty($message) && $this->setMessage($message);
$code && $this->setCode($code);
!empty($format) && $this->setFormat($format);
switch ($this->getFormat() ?: $this->request->format()) {
case 'xml':
return $this->response->make($this->toXML())->header('Content-Type', 'application/xml');
break;
case 'html':
return $this->response->make($this->getMessage());
break;
case 'jsonp':
$this->response->setCallback($this->getCallback());
case 'json':
default:
return $this->response->json($this->toArray());
break;
}
}
示例6: omdbUpdate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function omdbUpdate($id)
{
if (Request::format() == 'json') {
}
$rev = Movie::find($id);
$rev->fl_dir_ar_id = Input::get('info.Director');
$rev->fl_writer = Input::get('info.Writer');
//$rev->fl_stars = Input::get('info.Actors');
$rev->fl_outline = Input::get('info.Plot');
$rev->fl_genre = Input::get('info.Genre');
$rev->fl_duration = Input::get('info.Runtime');
$rev->fl_country = Input::get('info.Country');
$rev->fl_imdbID = Input::get('info.imdbID');
$rev->fl_imdbRating = Input::get('info.imdbRating');
$rev->fl_imdbVotes = Input::get('info.imdbVotes');
$rev->fl_metascore = Input::get('info.Metascore');
$rev->fl_tomatoConsensus = Input::get('info.tomatoConsensus');
$rev->fl_tomatoMeter = Input::get('info.tomatoMeter');
$rev->fl_tomatoUserMeter = Input::get('info.tomatoUserMeter');
$rev->save();
}
示例7: modifyResponse
/**
* Modify the response and inject the debugbar (or data in headers)
*
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
public function modifyResponse($request, $response)
{
$app = $this->app;
if ($app->runningInConsole() or !$this->isEnabled() || $this->isDebugbarRequest()) {
return $response;
}
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->getItems());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app['session'];
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('symfony_request', true) and !$this->hasCollector('request')) {
try {
$this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addException(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($response->isRedirection()) {
try {
$this->stackData();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($request->isXmlHttpRequest() || $request->wantsJson() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)) {
try {
$this->sendDataInHeaders(true);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->format()) {
//Do nothing
} elseif ($app['config']->get('laravel-debugbar::config.inject', true)) {
try {
$this->injectDebugbar($response);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
}
// Stop further rendering (on subrequests etc)
$this->disable();
return $response;
}
示例8: format
/**
* Get the data format expected in the response.
*
* @param string $default
* @return string
* @static
*/
public static function format($default = 'html')
{
return \Illuminate\Http\Request::format($default);
}
示例9: get
/**
* Presenter Package 는 JsonRenderer, HtmlRenderer 를 지원한다.
* Xpressengine 은 Register Container 로 등록된 Renderer 를 사용한다.
*
* @return RendererInterface
*/
protected function get()
{
$format = $this->request->format();
if (isset($this->presentables[$format]) === false) {
throw new NotFoundFormatException(['name' => $format]);
}
if ($format == HtmlPresenter::format() && $this->api === true && $this->html === false) {
$format = JsonPresenter::format();
}
$presenter = $this->getPresenter($format);
if (is_subclass_of($presenter, RendererInterface::class) === false && is_subclass_of($presenter, Presentable::class) === false) {
throw new InvalidPresenterException(['name' => get_class($presenter)]);
}
return $presenter;
}
示例10: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $productId)
{
// Check the request format
if ('json' !== $request->format()) {
$this->response['status'] = 'fail';
$this->response['messages'][] = 'Unknown request format';
} else {
$data = $request->json()->all();
// Check whether the data is empty
if (!empty($data)) {
$validator = $this->validator($data);
// Check whether the data is valid
if (false === $validator->fails()) {
// Check whether the data able to be saved to database
if ($this->model->update($productId, $data)) {
$this->response['status'] = 'success';
$this->response['messages'][0] = 'none';
} else {
$this->response['status'] = 'fail';
$this->response['messages'][0] = 'Failed to save to database';
}
} else {
$this->response['status'] = 'fail';
$this->response['messages'] = $validator->errors()->all();
}
} else {
$this->response['status'] = 'fail';
$this->response['messages'][0] = "Can't parse the data";
}
}
return response($this->response)->header('Content-Type:', 'json');
}
示例11: get
/**
* Presenter Package 는 JsonRenderer, HtmlRenderer 를 지원한다.
* Xpressengine 은 Register Container 로 등록된 Renderer 를 사용한다.
*
* @return RendererInterface
*/
protected function get()
{
// is ajax call ? remove theme, skin html tags
// $this->request->ajax();
$format = $this->request->format();
if ($this->isApproveFormat($format) === false) {
throw new Exceptions\NotApprovedFormatException();
}
if (isset($this->renderes[$format]) === false) {
throw new Exceptions\NotFoundFormatException();
}
$callback = $this->renderes[$format];
$renderer = call_user_func_array($callback, [$this]);
if (is_subclass_of($renderer, 'Xpressengine\\Presenter\\RendererInterface') === false) {
throw new Exceptions\InvalidRendererException();
}
return $renderer;
}
示例12: format
/**
* Get the expected format type.
*
* @return string
*/
public function format($default = 'html')
{
$this->parseAcceptHeader();
return $this->accept['format'] ?: parent::format($default);
}
示例13: get
/**
* Presenter Package 는 JsonRenderer, HtmlRenderer 를 지원한다.
* Xpressengine 은 Register Container 로 등록된 Renderer 를 사용한다.
*
* @return RendererInterface
*/
protected function get()
{
// is ajax call ? remove theme, skin html tags
// $this->request->ajax();
$format = $this->request->format();
if ($this->isApproveFormat($format) === false) {
throw new NotApprovedFormatException(['name' => $format]);
}
if (isset($this->renderers[$format]) === false) {
throw new NotFoundFormatException(['name' => $format]);
}
$renderer = $this->getRenderer($format);
if (is_subclass_of($renderer, 'Xpressengine\\Presenter\\RendererInterface') === false) {
throw new InvalidRendererException(['name' => get_class($renderer)]);
}
return $renderer;
}
示例14: modifyResponse
/**
* Modify the laravel response, if needed, to add the toolbar.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
*
* @return \Illuminate\Http\Response
* @return mixed
*/
public function modifyResponse($request, $response)
{
$app = $this->app;
if ($app->runningInConsole() || $request->isXmlHttpRequest() || $request->wantsJson()) {
return $response;
} elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || 'html' !== $request->format()) {
return $response;
} elseif (!$response instanceof Response) {
return $response;
}
$this->injectToolbar($response);
return $response;
}