Return the content type based on an array of content-type provided

@param string[] $contentType Array fo content-type

@return string Content-Type (e.g. application/json)
511426
private function selectContentTypeHeader($contentType)
    {
        if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
            return 'application/json';
        } elseif (preg_grep("/application\/json/i", $contentType)) {
            return 'application/json';
        } else {
            return implode(',', $contentType);
        }
    }
564040
public function getChangedFields(array $contentType)
    {
        $changedFields = [];

        if (empty($this->diff)) {
            return $changedFields;
        }

        // Get the ContentType that we're dealing with
        $fields = $contentType['fields'];

        $hash = [
            'html'        => 'fieldText',
            'markdown'    => 'fieldText',
            'textarea'    => 'fieldText',
            'filelist'    => 'fieldList',
            'imagelist'   => 'fieldList',
            'geolocation' => 'fieldGeolocation',
            'image'       => 'fieldImage',
            'embed'       => 'fieldVideo',
            'select'      => 'fieldSelect',
            'video'       => 'fieldVideo',
        ];

        foreach ($this->diff as $key => $value) {
            if (!isset($fields[$key])) {
                continue;
            }

            $type = $fields[$key]['type'];
            $changedFields[$key] = [
                'type'   => $type,
                'label'  => empty($fields[$key]['label']) ? $key : $fields[$key]['label'],
                'before' => [
                    'raw'    => $value[0],
                    'render' => $value[0],
                ],
                'after'  => [
                    'raw'    => $value[1],
                    'render' => $value[1],
                ],
            ];

            /** @var string $type */
            $type = $fields[$key]['type'];
            if (isset($hash[$type])) {
                $func = $hash[$type];
                $changedFields[$key] = array_merge($changedFields[$key], $this->{$func}($key, $value, $fields));
            }
        }

        return $changedFields;
    }
571835
public function encode(array $data, string $contentType): string
    {
        if (isset($this->encoderTypes[$contentType])) {
            return $this->encoderTypes[$contentType]->encode($data);
        }

        throw SerializerLogicException::createMissingContentType($contentType);
    }
256040
public function getContentArray($type = DOC_TYPE_ARRAY)
  {
    if ($type == DOC_TYPE_SIMPLEXML) {
      $cpsChildren = $this->_simpleXml->children('www.clusterpoint.com');
      if (isset($cpsChildren->content)) {
        return $cpsChildren->content;
      } else {
        return NULL;
      }
    } else if ($type == DOC_TYPE_ARRAY) {
      return $this->_contentArray;
    }
  }
711078
public static function parseContentType(string $content_type)
    {
        $directives = array_map('trim', explode(';', $content_type));

        $result = [
            'mime' => array_shift($directives)
        ];

        if (empty($directives)) {
            return $result['mime'];
        }

        foreach ($directives as $directive) {
            $parts = explode('=', $directive);
            $result[$parts[0]] = $parts[1];
        }

        return $result;
    }
72709
public function get(ContentType $contentType, array $templateFields)
    {
        $select = new ArrayObject();

        $this->build($select, $contentType->getFields());
        $this->build($select, $templateFields, 'templatefields');

        return iterator_to_array($select) ?: null;
    }
1208526
public function getPart(string $contentType)
    {
        if (! isset($this->parts[$contentType])) {
            return null;
        }

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

        return [];
    }
477884
public function getWebResourceClassName($contentType)
    {
        return ($this->hasMappedWebResourceClassName($contentType))
            ? $this->contentTypeWebResourceMap[(string)$contentType]
            : self::DEFAULT_WEB_RESOURCE_MODEL;
    }
1277073
private function prepareFields(ApiContentType $contentType, $fields = null)
    {
        if ($fields !== null) {
            if (strpos($fields, ',') !== false) {
                return explode(',', $fields);
            }

            return array($fields);
        }

        $fields = array();
        $contentFields = $contentType->getFieldDefinitions();

        foreach ($contentFields as $field) {
            $fields[] = $field->identifier;
        }

        return $fields;
    }
159762
public function getRelation($contentType = null)
    {
        if (!$this->relation instanceof Collection\Relations) {
            $this->relation = new Collection\Relations();
        }

        if ($contentType !== null) {
            return $this->relation[$contentType];
        }

        return $this->relation;
    }
1316415
public function getRolesByContentTypePermission($permissionName, $contenttype)
    {
        // Here's how it works:
        // - if a permission is granted through 'contenttype-all', it is effectively granted
        // - if a permission is granted through 'contenttypes/$contenttype', it is effectively granted
        // - if 'contenttypes/$contenttype/$permissionName' is not set, *and* the permission is granted through 'contenttype-default', it is effectively granted
        // - otherwise, the permission is denied
        $overrideRoles = $this->app['config']->get("permissions/contenttype-all/$permissionName");
        if (!is_array($overrideRoles)) {
            $overrideRoles = [];
        }
        $contenttypeRoles = $this->app['config']->get("permissions/contenttypes/$contenttype/$permissionName");
        if (!is_array($contenttypeRoles)) {
            $contenttypeRoles = $this->app['config']->get("permissions/contenttype-default/$permissionName");
        }
        if (!is_array($contenttypeRoles)) {
            $contenttypeRoles = [];
        }
        $effectiveRoles = array_unique(array_merge($overrideRoles, $contenttypeRoles));

        return $effectiveRoles;
    }
636141
static public function getMimeType($contentType, $filename=null)
    {
        if ($contentType = strtolower($contentType)) {
            if (strpos($contentType, '/') !== false) {
                $mimeTypes = array_keys(self::$mime_types, $contentType);
                $ext = $filename ? pathinfo($filename, PATHINFO_EXTENSION) : null;
                
                if (count($mimeTypes) === 1) {
                    return $mimeTypes[0];
                } elseif (count($mimeTypes) > 1) {
                    return $ext && in_array($ext, $mimeTypes) ? $ext : $mimeTypes[0];
                } else {
                    return $ext ? static::getMimeType($ext) : null;
                }
            } else {
                $ext = pathinfo($contentType, PATHINFO_EXTENSION);
                if (isset(static::$mime_types[$ext])) {
                    return $ext;
                }
            }
        } elseif ($filename) {
            return static::getMimeType($filename);
        }
        
        return null;
    }
778415
private function getContentIdentifier($contentId)
    {
        $contentType = $this->contentTypeService->loadContentType(
            $this->contentService
                ->loadContent($contentId)
                ->contentInfo
                ->contentTypeId
        );

        return $contentType->identifier;
    }
933210
public function getContent(string $contentType = null): string
    {
/*
        if(null == $contentType)
            $contentType = $this->contentType;
*/
        switch($contentType) {
            case 'application/vnd.transitive.document+json':
                return $this->route->getDocument();
            break;
            case 'application/vnd.transitive.document+xml':
                return $this->route->getDocument()->asXML('document');
            break;
            case 'application/vnd.transitive.document+yaml':
                return $this->route->getDocument()->asYAML();
            break;
            case 'application/vnd.transitive.head+json':
                return $this->route->getHead()->asJson();
            break;
            case 'application/vnd.transitive.head+xml':
                return $this->route->getHead()->asXML('head');
            break;
            case 'application/vnd.transitive.head+yaml':
                return $this->route->getHead()->asYAML();
            break;
            case 'application/vnd.transitive.content+xhtml': case 'application/vnd.transitive.content+html':
                return $this->route->getContent();
            break;
            case 'application/vnd.transitive.content+json':
                return $this->route->getContent()->asJson();
            break;
            case 'application/vnd.transitive.content+xml':
                return $this->route->getContent()->asXML('content');
            break;
            case 'application/vnd.transitive.content+yaml':
                return $this->route->getContent()->asYAML();
            break;

            case 'text/plain':
                return $this->layout->getContent()->asString();
            break;

            case 'application/json':
                if($this->route->hasContent('application/json'))
                    return $this->route->getContentByType('application/json')->asJson();
                elseif(404 != http_response_code()) {
                    http_response_code(404);
                    $_SERVER['REDIRECT_STATUS'] = 404;

                    return '';
                }
            break;
            case 'application/xml':
                if($this->route->hasContent('application/xml'))
                    return $this->route->getContentByType('application/xml')->asJson();
                elseif(404 != http_response_code()) {
                    http_response_code(404);
                    $_SERVER['REDIRECT_STATUS'] = 404;

                    return '';
                }

            break;

            default:
                return $this->layout->getView();
        }
    }
1061179
protected function getContentObject(array $contenttype, array $values)
    {
        if (empty($contenttype['class'])) {
            return new Content($this->app, $contenttype, $values);
        }

        if (class_exists($contenttype['class'])) {
            $content = new $contenttype['class']($this->app, $contenttype, $values);

            if (!($content instanceof Content)) {
                throw new StorageException($contenttype['class'] . ' does not extend \\Bolt\\Content.');
            }

            return $content;
        }

        $msg = sprintf('The ContentType %s has an invalid class specified "%s". Unable to log the changes to its records', $contenttype['slug'], $contenttype['class']);
        $this->app['logger.system']->error($msg, ['event' => 'content']);

        throw new StorageException($msg);
    }
1059923
private function getContentTypesNumbers(array $contentTypes): array
    {
        $contentTypesNumbers = array_column($contentTypes, 'id');

        return array_combine($contentTypesNumbers, array_fill_keys($contentTypesNumbers, false));
    }