Exemplo n.º 1
0
 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'));
 }
Exemplo n.º 2
0
 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);
 }