formats() public static method

Alias for types(); included for interface compatibility with lithium\util\Collection::to(), which allows a collection object to be exported to any format supported by a Media handler. See the documentation for Collection::to() for more information.
See also: lithium\net\http\Media
public static formats ( ) : array
return array Returns the value of `Media::types()`.
Exemplo n.º 1
0
 /**
  * Tests setting, getting and removing custom media types.
  *
  * @return void
  */
 public function testMediaTypes()
 {
     // Get a list of all available media types:
     $types = Media::types();
     // returns array('html', 'json', 'rss', ...);
     $expected = array('html', 'htm', 'form', 'json', 'rss', 'atom', 'css', 'js', 'text', 'txt', 'xml');
     $this->assertEqual($expected, $types);
     $this->assertEqual($expected, Media::formats());
     $result = Media::type('json');
     $expected = 'application/json';
     $this->assertEqual($expected, $result['content']);
     $expected = array('cast' => true, 'encode' => 'json_encode', 'decode' => $result['options']['decode']);
     $this->assertEqual($expected, $result['options']);
     // Add a custom media type with a custom view class:
     Media::type('my', 'text/x-my', array('view' => 'my\\custom\\View', 'layout' => false));
     $result = Media::types();
     $this->assertTrue(in_array('my', $result));
     $result = Media::type('my');
     $expected = 'text/x-my';
     $this->assertEqual($expected, $result['content']);
     $expected = array('view' => 'my\\custom\\View', 'template' => null, 'layout' => null, 'encode' => null, 'decode' => null, 'cast' => true, 'conditions' => array());
     $this->assertEqual($expected, $result['options']);
     // Remove a custom media type:
     Media::type('my', false);
     $result = Media::types();
     $this->assertFalse(in_array('my', $result));
 }
Exemplo n.º 2
0
 /**
  * Tests setting, getting and removing custom media types.
  *
  * @return void
  */
 public function testMediaTypes()
 {
     $result = Media::types();
     $this->assertTrue(is_array($result));
     $this->assertTrue(in_array('json', $result));
     $this->assertFalse(in_array('my', $result));
     $this->assertEqual($result, Media::formats());
     $result = Media::type('json');
     $expected = 'application/json';
     $this->assertEqual($expected, $result['content']);
     $expected = array('view' => false, 'layout' => false, 'cast' => true, 'encode' => 'json_encode', 'decode' => $result['options']['decode']);
     $this->assertEqual($expected, $result['options']);
     Media::type('my', 'text/x-my', array('view' => 'my\\custom\\View', 'layout' => false));
     $result = Media::types();
     $this->assertTrue(in_array('my', $result));
     $result = Media::type('my');
     $expected = 'text/x-my';
     $this->assertEqual($expected, $result['content']);
     $expected = array('view' => 'my\\custom\\View', 'template' => null, 'layout' => null, 'encode' => null, 'decode' => null, 'cast' => true);
     $this->assertEqual($expected, $result['options']);
     Media::type('my', false);
     $result = Media::types();
     $this->assertFalse(in_array('my', $result));
 }