getPreferredFormat() static public method

static public getPreferredFormat ( $default = 'plain' )
 public function testGetPreferredFormat()
 {
     $_SERVER['HTTP_ACCEPT'] = '';
     $actual = ARC2::getPreferredFormat('xml');
     $this->assertEquals('XML', $actual);
     $actual = ARC2::getPreferredFormat('foo');
     $this->assertEquals(null, $actual);
     $_SERVER['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
     $actual = ARC2::getPreferredFormat();
     $this->assertEquals('HTML', $actual);
     $_SERVER['HTTP_ACCEPT'] = 'application/rdf+xml,text/html;q=0.9,*/*;q=0.8';
     $actual = ARC2::getPreferredFormat();
     $this->assertEquals('RDFXML', $actual);
 }
Ejemplo n.º 2
0
 function getArraySerialization($v, $context)
 {
     $v_type = ARC2::getStructType($v);
     /* string|array|triples|index */
     $pf = ARC2::getPreferredFormat();
     /* string */
     if ($v_type == 'string') {
         return $v;
     }
     /* simple array (e.g. from SELECT) */
     if ($v_type == 'array') {
         return join(', ', $v);
         $m = method_exists($this, 'toLegacy' . $pf) ? 'toLegacy' . $pf : 'toLegacyXML';
     }
     /* rdf */
     if ($v_type == 'triples' || $v_type == 'index') {
         $m = method_exists($this, 'to' . $pf) ? 'to' . $pf : ($context == 'query' ? 'toNTriples' : 'toRDFXML');
     }
     /* else */
     return $this->{$m}($v);
 }