parse() 공개 메소드

Parse the accept header on the incoming request. If strict is enabled then the accept header must be available and must be a valid match.
public parse ( Illuminate\Http\Request $request, boolean $strict = false ) : array
$request Illuminate\Http\Request
$strict boolean
리턴 array
예제 #1
0
 /**
  * Parse the accept header.
  *
  * @return void
  */
 protected function parseAcceptHeader()
 {
     if ($this->accept) {
         return;
     }
     $this->accept = static::$acceptParser->parse($this);
 }
예제 #2
0
파일: Accept.php 프로젝트: joselfonseca/api
 /**
  * Validate the accept header on the request. If this fails it will throw
  * an HTTP exception that will be caught by the middleware. This
  * validator should always be run last and must not return
  * a success boolean.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *
  * @return bool
  */
 public function validate(Request $request)
 {
     try {
         $this->accept->parse($request, $this->strict);
     } catch (BadRequestHttpException $exception) {
         if ($request->getMethod() === 'OPTIONS') {
             return true;
         }
         throw $exception;
     }
 }
예제 #3
0
 public function testApiVersionWithoutVSuffix()
 {
     $parser = new Accept('vnd', 'api', '1.0', 'json');
     $accept = $parser->parse($this->createRequest('foo', 'GET', ['accept' => 'application/vnd.api.1.0+xml']));
     $this->assertEquals('api', $accept['subtype']);
     $this->assertEquals('1.0', $accept['version']);
     $this->assertEquals('xml', $accept['format']);
 }
예제 #4
0
 public function getCurrentAcceptHeader($request = null)
 {
     if (!isset($request)) {
         $request = Request::instance();
     }
     $config = $this->app['config']['api'];
     $acceptClass = new Accept($config['standardsTree'], $config['subtype'], $config['version'], $config['defaultFormat']);
     return $acceptClass->parse($request);
 }
예제 #5
0
파일: Router.php 프로젝트: jieke360/api
 /**
  * Dispatch a request via the adapter.
  *
  * @param \Dingo\Api\Http\Request $request
  *
  * @throws \Exception
  *
  * @return \Dingo\Api\Http\Response
  */
 public function dispatch(Request $request)
 {
     $this->currentRoute = null;
     $accept = $this->accept->parse($request);
     $this->container->instance('Dingo\\Api\\Http\\Request', $request);
     $this->routesDispatched++;
     try {
         $response = $this->adapter->dispatch($request, $accept['version']);
     } catch (Exception $exception) {
         if ($request instanceof InternalRequest) {
             throw $exception;
         }
         $response = $this->exception->handle($exception);
     }
     return $this->prepareResponse($response, $request, $accept['format']);
 }
예제 #6
0
파일: Accept.php 프로젝트: khlipeng/api
 /**
  * Validate the accept header on the request. If this fails it will throw
  * an HTTP exception that will be caught by the middleware. This
  * validator should always be run last and must not return
  * a success boolean.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *
  * @return void
  */
 public function validate(Request $request)
 {
     $this->accept->parse($request, $this->strict);
 }