Sulu\Bundle\MediaBundle\Media\TypeManager\TypeManager::get PHP Method

get() public method

public get ( $id )
    public function get($id)
    {
        /** @var MediaType $type */
        $type = $this->objectManager->getRepository(self::ENTITY_NAME_MEDIATYPE)->find($id);
        if (!$type) {
            throw new MediaTypeNotFoundException('Collection Type with the ID ' . $id . ' not found');
        }
        return $type;
    }

Usage Example

Example #1
0
 public function testMediaTypes()
 {
     $data = ['application/pdf' => 'document', 'application/msword' => 'document', 'application/vnd.ms-excel' => 'document', 'application/zip' => 'document', 'text/html' => 'document', 'image/jpg' => 'image', 'image/jepg' => 'image', 'image/gif' => 'image', 'image/png' => 'image', 'image/vnd.adobe.photoshop' => 'image', 'video/mp4' => 'video', 'video/mov' => 'video', 'audio/mpeg' => 'audio', 'audio/mp3' => 'audio'];
     foreach ($data as $mimeType => $mediaType) {
         $mediaTypeName = null;
         $id = $this->typeManager->getMediaType($mimeType);
         $setMediaType = $this->typeManager->get($id);
         if ($setMediaType) {
             $mediaTypeName = $setMediaType->getName();
         }
         $this->assertEquals($mediaTypeName, $mediaType);
     }
 }