Returns a new instance of a serializer depending on the given type.

@param string $mimeType the serializer type; Default: application/json
@return IRestSerializer an instance of a serializer
@throws RestUserException
962981
public static function create($mimeType='application/json') {
        $availableSerializers = \ClassInfo::implementorsOf('Ntb\RestAPI\IRestSerializer');
        foreach($availableSerializers as $serializer) {
            /** @var IRestSerializer $instance */
            $instance = new $serializer();
            if($instance->active() && $instance->contentType() === $mimeType) {
                return $instance;
            }
        }
        throw new RestUserException("Requested Accept '$mimeType' not supported", 404);
    }
1304055
public function readString($data, $mimeType = null)
    {
        if (null === $mimeType) {
            $mimeType = ContentType::JSON()->primaryMimeType();
        }

        return $this->read($this->uriFactory()->fromData($data, $mimeType), $mimeType);
    }
1209709
public static function is_convertable($mimetype = null)
    {
        $rcube = rcube::get_instance();

        // @TODO: check if specified mimetype is really supported
        return class_exists('Imagick', false) || $rcube->config->get('im_convert_path');
    }
1144391
public function makeFromUrl($url, $name = null, $mimeType = null)
    {
        try {
            $localPath = $this->downloader->download($url);

        } catch (Exception $e) {

            throw new CouldNotRetrieveRemoteFileException(
                "Could not retrieve file from '{$url}'",
                $e->getcode(),
                $e
            );
        }

        if (null === $name) {
            $name = $this->getBaseNameFromUrl($url);
        }

        // Always flag as uploaded, since we downloaded to a local path
        return $this->uploaded()->makeFromLocalPath($localPath, $name, $mimeType);
    }
360719
protected function _getCommonJsData($mimeType)
    {
        $commonJsData = parent::_getCommonJsData($mimeType);
        if ($commonJsData) {
            $deps = array_merge(
                $this->_loadedPackage->_getFilteredUniqueDependencies('text/javascript'),
                $this->_loadedPackage->_getFilteredUniqueDependencies('text/javascript; defer')
            );
            foreach ($deps as $i) {
                $data = array();
                $commonJsDeps = $this->_getCommonJsDeps($i, $data);
                foreach (array_keys($data) as $key) {
                    if (isset($commonJsData[$key])) {
                        unset($commonJsData[$key]);
                    }
                }
            }
        }
        return $commonJsData;
    }
695629
public function body($mimeType = 'html')
    {
        $body = [];

        foreach ($this->body as $part) {
            if ($part->mime_type === $mimeType) {
                $body[] = $part->body;
            }
        }

        return implode(static::partSeparator($mimeType), $body);
    }
74879
public function get($mimeType)
    {
        if (!array_key_exists($mimeType, $this->map)) {
            throw new Exception\UndefinedProtocolException($mimeType);
        }

        return $this->map[$mimeType];
    }
523713
public function write($path, $string, $mimeType = null)
    {
        return $this->getFile($path)->write($string, $mimeType);
    }
1182087
public function getDriver(string $mimetype)
    {
        foreach ($this->byMimetype as $match => $driver) {
            if ($mimetype === $match) {
                return $driver;
            }
        }

        foreach ($this->byMimeStart as $match => $driver) {
            if (strpos($mimetype, $match) === 0) {
                return $driver;
            }
        }

        return 'DefaultDriver';
    }
838913
public static function provideDefaultClassFor(string $mimeType): bool
    {
        if (in_array($mimeType, array_keys(self::$supported))) {
            return true;
        }

        if (class_exists('stubbles\xml\serializer\XmlSerializerFacade') && in_array($mimeType, array_keys(self::$xml))) {
            return true;
        }

        if (class_exists('stubbles\img\Image') && in_array($mimeType, array_keys(self::$image))) {
            return true;
        }

        return false;
    }
816542
public function setMimeType(string $mime_type) {
        if(!$this->setModified('mime_type', $mime_type)->isModified()) {
            return $this;
        }
		$this->mime_type = $mime_type;
		return $this;
    }
292944
public function makeFromRawData($data, $name = null, $mimeType = null)
    {
        $file = new RawStorableFile;

        if ($data instanceof RawContentInterface) {
            $data = $data->content();
        }

        // Guess the mimetype directly from the content
        if (null === $mimeType) {
            $mimeType = $this->mimeTypeHelper->guessMimeTypeForContent($data);
        }

        if (empty($name)) {
            $name = $this->makeRandomName(
                $this->mimeTypeHelper->guessExtensionForMimeType($mimeType)
            );
        }

        $file->setName($name);
        $file->setData($data);
        $file->setMimeType($mimeType);

        return $this->getReturnPreparedFile($file);
    }
1111729
public function allowMimetype($Mimetype) {
        if ( ! $this->returnUrl() ) return false;
        if ( isset($this->claim->accept_media_types) ) {
            $ma = $Mimetype;
            if ( ! is_array($ma) ) $ma = array($Mimetype);
            $m = new Mimeparse;
            $allowed = $m->best_match($ma, $this->claim->accept_media_types);
            if ( $Mimetype != $allowed ) return false;
            return true;
        }
        return false;
    }
298012
public function readString($data, $mimeType = null)
    {
        return $this->schemaFactory()->create(
            $this->reader()->readString($data, $mimeType)
        );
    }
637654
static protected function achieveSerializer_( string$mime ):S\ASerializer
	{
		static::checkSerializerSupported_( $mime );

		$serializer= static::getSerializer_( $mime );

		return static::instantiateSerializer_( $serializer );
	}
1075408
public function setMimetype($type)
    {
        if ($type === null || $type === false) {
            $this->mimetype = null;

            return $this;
        }

        if (!is_string($type)) {
            throw new InvalidArgumentException(
                'Mimetype must be a string'
            );
        }

        $this->mimetype = $type;

        return $this;
    }
386670
protected function achieveSerializer( string$mime ):S\ASerializer
	{
		$this->checkSerializerSupported( $mime );

		$serializer= $this->getSerializer( $mime );

		return static::instantiateSerializer_( $serializer );
	}