Cake\Network\Response::mapType PHP Метод

mapType() публичный Метод

e.g mapType('application/pdf'); // returns 'pdf'
public mapType ( string | array $ctype ) : string | array | null
$ctype string | array Either a string content type to map, or an array of types.
Результат string | array | null Aliases for the types provided.
    public function mapType($ctype)
    {
        if (is_array($ctype)) {
            return array_map([$this, 'mapType'], $ctype);
        }
        foreach ($this->_mimeTypes as $alias => $types) {
            if (in_array($ctype, (array) $types)) {
                return $alias;
            }
        }
        return null;
    }

Usage Example

Пример #1
0
 /**
  * Tests the mapType method
  *
  * @return void
  */
 public function testMapType()
 {
     $response = new Response();
     $this->assertEquals('wav', $response->mapType('audio/x-wav'));
     $this->assertEquals('pdf', $response->mapType('application/pdf'));
     $this->assertEquals('xml', $response->mapType('text/xml'));
     $this->assertEquals('html', $response->mapType('*/*'));
     $this->assertEquals('csv', $response->mapType('application/vnd.ms-excel'));
     $expected = ['json', 'xhtml', 'css'];
     $result = $response->mapType(['application/json', 'application/xhtml+xml', 'text/css']);
     $this->assertEquals($expected, $result);
 }
All Usage Examples Of Cake\Network\Response::mapType