/** * Determines if the Accepts header types match what this responder is configured to return. * If not, we throw an exception. * * @throws Exception\ContentTypeNotValidException */ protected function determineResponseType($availableTypes) { $bestType = $this->contentNegotiation->negotiateMedia($availableTypes); if ($bestType instanceof Accept\Media\MediaValue) { $contentType = $bestType->getValue(); $subType = $bestType->getSubtype(); $this->contentType = $contentType; return $contentType; } }
/** * @param Runner $runner * @param array $loggers */ public function __construct(Runner $runner, Accept $accept, array $loggers = array(), array $availableFormatters = array()) { $this->errorHandler = $runner; $this->loggers = $loggers; if ($availableFormatters) { $possibleAccepts = array_keys($availableFormatters); $result = $accept->negotiateMedia($possibleAccepts); if ($result) { $this->errorHandler->pushFormatter($availableFormatters[$result->getValue()]); } } foreach ($loggers as $name => $logger) { if ($name == 'event') { ModusLogger::registerLogger($logger); } else { ModusLogger::registerLogger($logger, $name); } } }
public function getFormat() { $this->media = $this->accept->negotiateMedia($this->available()); return $this->hasDetected() ? $this->acceptMap()[$this->media->getValue()] : Format::JSON; }