private function applyPreferHeader(Document $document, Request $request, &$headers, &$options) { $prefer = $request->headers->get('Prefer'); $minimal = preg_match("/\\brepresentation\\s*=\\s*(minimal\\b|\"minimal\")/i", $prefer); if ($minimal) { $document->minimize(); if ($options >= JSON_PRETTY_PRINT) { $options -= JSON_PRETTY_PRINT; } $headers['Preference-Applied'] = 'representation=minimal'; } elseif ($options < JSON_PRETTY_PRINT) { $options += JSON_PRETTY_PRINT; } }
/** * @param Request $request HTTP request * @param Container $container Container for storing or querying the data set */ public function __construct(Request $request, Container $container) { parent::__construct(); $this->request = $request; $this->container = $container; }
protected function makeMasonResponse(Document $document, Request $request, array $routeParams = [], $status = 200, array $headers = []) { if (method_exists($this, 'outputSchema') || method_exists($this, 'schema')) { $url = method_exists($this, 'schema') ? static::getSchemaUrl() : static::getOutputSchemaUrl(); $document->setMetaProperty('relation', static::getRelation())->setControl('profile', new Control($url, ['output' => [SchemaResponse::MIME_TYPE]])); if (isset($headers['Link']) && !is_array($headers['Link'])) { $headers['Link'] = [$headers['Link']]; } $headers['Link'][] = sprintf('<%s>; rel="profile"', $url); } if (!isset($document->{'@controls'}->self)) { $document->setControl('self', static::getMasonControl($routeParams)); } if (method_exists($this, 'addDefaultMasonNamespace')) { $this->addDefaultMasonNamespace($document); } return MasonResponse::create($document, $request, $status, $headers, JSON_UNESCAPED_SLASHES); }