Dingo\Api\Http\Parser\Accept::parse PHP Method

parse() public method

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
return array
    public function parse(Request $request, $strict = false)
    {
        $pattern = '/application\\/' . $this->standardsTree . '\\.(' . $this->subtype . ')\\.([\\w\\d\\.\\-]+)\\+([\\w]+)/';
        if (!preg_match($pattern, $request->header('accept'), $matches)) {
            if ($strict) {
                throw new BadRequestHttpException('Accept header could not be properly parsed because of a strict matching process.');
            }
            $default = 'application/' . $this->standardsTree . '.' . $this->subtype . '.' . $this->version . '+' . $this->format;
            preg_match($pattern, $default, $matches);
        }
        return array_combine(['subtype', 'version', 'format'], array_slice($matches, 1));
    }

Usage Example

Example #1
0
 /**
  * Parse the accept header.
  *
  * @return void
  */
 protected function parseAcceptHeader()
 {
     if ($this->accept) {
         return;
     }
     $this->accept = static::$acceptParser->parse($this);
 }
All Usage Examples Of Dingo\Api\Http\Parser\Accept::parse