Translate and validate content-types.

@param string $contentType The content-type or type alias.
@return string The resolved content-type
@throws \InvalidArgumentException When an invalid content-type or alias is used.
320757
protected function resolveType($contentType)
    {
        $mapped = $this->getMimeType($contentType);
        if ($mapped) {
            return is_array($mapped) ? current($mapped) : $mapped;
        }
        if (strpos($contentType, '/') === false) {
            throw new InvalidArgumentException(sprintf('"%s" is an invalid content type.', $contentType));
        }

        return $contentType;
    }
801666
public function contentTypeToResponseFormat($contentType, $url = null)
    {
        if (!empty($url)) {
            $url = parse_url($url, PHP_URL_PATH);
        }

        $contentTypeClean = strstr($contentType, ';') ? substr($contentType, 0,
                strpos($contentType, ';')) : $contentType;

        switch ($url) {
            case '/login-logout/login';
                $responseFormat = 'json';
                break;
            default :
                switch ($contentTypeClean) {
                    case 'text/javascript':
                        $responseFormat = 'js';
                        break;

                    default:
                        $responseFormat = Formats::contentTypeToSuffix($contentTypeClean);
                        break;
                }
                break;
        }

        return $responseFormat;
    }
462523
public function accept(string $contentType): HttpRequest
    {
        $contentType = trim($contentType);

        return $this->header("Accept", $contentType);
    }
505422
public function save(ContentType $contentType)
    {
        $this->em->persist($contentType);
        $this->em->flush();

        return $contentType;
    }
244635
protected function getConverter($contentType)
    {
        if (!isset($this->supportedMediaTypes[$contentType])) {
            throw new Exception("No converter found for content type '$contentType'");
        }

        $converterClass = $this->supportedMediaTypes[$contentType];

        return new $converterClass;
    }
898755
public function isImageType($contentType)
    {
        if (strpos($contentType, '.') !== false) {
            $ext = pathinfo($contentType, PATHINFO_EXTENSION);
            if (in_array($ext, ['gif', 'jpe', 'jpeg', 'jpg'])) {
                return true;
            }
        } else {
            if ($pos = strpos($contentType, '/')) {
                $contentType = substr($contentType, 0, $pos);
            }
            if ($contentType === 'image') {
                return true;
            }
        }
        return false;
    }
51126
public function loadFromContentType(ContentType $contentType): self
    {
        $languages = [];
        foreach ($contentType->languageCodes as $languageCode) {
            $languages[] = $this->languageService->loadLanguage($languageCode);
        }

        $this->data = array_map(
            function (Language $language) use ($contentType) {
                return $this->valueFactory->createLanguageFromContentType($language, $contentType);
            },
            $languages
        );

        return $this;
    }
1035899
protected function getConfigForContentType(ContentType $contentType)
    {
        if ($this->hasConfigForContentType($contentType)) {
            return $this->config['override_by_type'][$contentType->identifier];
        }

        return [];
    }
763911
public static function contentType($type, $charset = 'utf-8'){
        $type = isset( self::$types[$type] ) ? self::$types[$type] : $type;
        self::set('Content-Type: '. $type. '; charset='. $charset);
    }
601183
private function processContentType($contentType)
    {
        foreach (explode(';', $contentType) as $type) {
            $type = strtolower(trim($type));
            if (isset($this->supported_formats[$type])) {
                return $this->supported_formats[$type];
            }
        }

        return false;
    }
31228
protected function setAssumedContentType($type)
    {
        if (!in_array($type, $this->acceptedContentTypes)) {
            throw new \InvalidArgumentException("Content type '$type' is not accepted, so it can not be assumed");
        }
        $this->assumedContentType = $type;
    }
1003728
public function getContenttypeTablename($contenttype)
    {
        if (is_string($contenttype)) {
            $contenttype = $this->getContentType($contenttype);
        }

        return $this->getTablename($contenttype['tablename']);
    }
430995
private function getNewContentTypeDraft(ContentType $contentType)
    {
        try {
            $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentType->id);
        } catch (NotFoundException $e) {
            $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($contentType);
        }

        return $contentTypeDraft;
    }
551267
public function getPart($type)
    {
        $parts = $this->getParts();

        foreach ($parts as $part) {
            if (0 === strpos($part->getHeaders()->get('Content-Type'), $type)) {
                return $part;
            }
        }

        throw new \InvalidArgumentException(sprintf('Unable to find part with Content-Type "%s" in parts. Got: %s', $type, implode("", array_map(function ($part) {
            return "\n- ".$part->getHeaders()->get('Content-Type');
        }, $parts))));
    }
45814
public function resolveUrlAliasSchema(Content $content, ContentType $contentType = null)
    {
        if ($contentType === null) {
            $contentType = $this->contentTypeHandler->load($content->contentInfo->contentTypeId);
        }

        return $this->resolve(
            strlen($contentType->urlAliasSchema) === 0 ? $contentType->nameSchema : $contentType->urlAliasSchema,
            $contentType,
            $content->fields,
            $content->versionInfo->languageCodes
        );
    }
1227416
protected function contentTypeHasFieldDefinition(ContentType $contentType, $fieldIdentifier)
    {
        $existingFieldDefinitions = $contentType->fieldDefinitions;

        foreach ($existingFieldDefinitions as $existingFieldDefinition) {
            if ($fieldIdentifier == $existingFieldDefinition->identifier) {
                return $existingFieldDefinition;
            }
        }

        return null;
    }
1234871
public function withContentType($contentType, $charset = null)
    {
        if (is_null($charset)) {
            return $this->withHeader('Content-Type', $contentType);
        }

        return $this->withHeader('Content-Type', $contentType . '; charset=' . $charset);
    }