Ejemplo n.º 1
0
 public function testRegisterTypes()
 {
     Mad_Controller_Mime_Type::$registered = false;
     Mad_Controller_Mime_Type::$set = array();
     $this->assertTrue(empty(Mad_Controller_Mime_Type::$set));
     Mad_Controller_Mime_Type::registerTypes();
     $this->assertFalse(empty(Mad_Controller_Mime_Type::$set));
 }
Ejemplo n.º 2
0
 /**
  * Returns the Mime type for the format used in the request. If there is no 
  * format available, the first of the 
  * 
  * @return  string
  */
 public function getFormat()
 {
     if (!isset($this->_format)) {
         $params = $this->getParameters();
         if (isset($params['format'])) {
             $this->_format = Mad_Controller_Mime_Type::lookupByExtension($params['format']);
         } else {
             $this->_format = current($this->getAccepts());
         }
     }
     return $this->_format;
 }
Ejemplo n.º 3
0
 /**
  * Set the content type for this mock request.
  *
  * $contentType may be a type ("application/xml"), an
  * extension ("xml"), a Mad_Controller_Mime_Type, or NULL.
  *
  *   $request->setContentType('application/xml');  // type  
  *   $request->setContentType('xml')               // extension
  *
  * If you want to manipulate the content type header directly,
  * you need to call this method with NULL after setting the header
  * to wipe any previously cached value.  See getContentType().
  *
  *   $request->setServer('CONTENT_TYPE', 'raw header value');
  *   $request->setContentType(null);
  *
  * @param  mixed $contentType
  * @return void
  */
 public function setContentType($contentType)
 {
     if (is_string($contentType)) {
         if (strpos($contentType, '/') !== false) {
             $contentType = Mad_Controller_Mime_Type::lookup($contentType);
         } else {
             $contentType = Mad_Controller_Mime_Type::lookupByExtension($contentType);
         }
     }
     $this->_contentType = $contentType;
 }
Ejemplo n.º 4
0
 public static function registerTypes()
 {
     if (!self::$registered) {
         Mad_Controller_Mime_Type::register("*/*", 'all');
         Mad_Controller_Mime_Type::register("text/plain", 'text', array(), array('txt'));
         Mad_Controller_Mime_Type::register("text/html", 'html', array('application/xhtml+xml'), array('xhtml'));
         Mad_Controller_Mime_Type::register("text/javascript", 'js', array('application/javascript', 'application/x-javascript'), array('xhtml'));
         Mad_Controller_Mime_Type::register("text/csv", 'csv');
         Mad_Controller_Mime_Type::register("application/xml", 'xml', array('text/xml', 'application/x-xml'));
         self::$registered = true;
     }
 }