public function testFindByType() { $html = MediaType::add('html', ['conditions' => ['type' => 'html']]); $json = MediaType::add('json', ['conditions' => ['type' => 'json']]); $this->assertEquals($json, MediaType::findByType('json')); $this->assertFalse(MediaType::findByType('xml')); }
public static function render($request, $response) { $mediaByType = MediaType::findByType($request['type']); $mediaByAccept = MediaType::findByAccept($request['accept']); $mediaType = $mediaByType ?: $mediaByAccept; if (!$mediaType) { return App::abort(406, 'Unrecognized accept type.'); } return $mediaType->encode($request, $response); }