Graby\Graby::getMimeActionInfo PHP Method

getMimeActionInfo() private method

Based on content-type http header, decide what to do.
private getMimeActionInfo ( string $headers ) : array
$headers string Content-Type header content
return array With keys: 'mime', 'type', 'subtype', 'action', 'name' e.g. array('mime'=>'image/jpeg', 'type'=>'image', 'subtype'=>'jpeg', 'action'=>'link', 'name'=>'Image')
    private function getMimeActionInfo($headers)
    {
        // check if action defined for returned Content-Type
        $info = array('mime' => '');
        if (preg_match('!\\s*(([-\\w]+)/([-\\w\\+]+))!im', strtolower($headers), $match)) {
            // look for full mime type (e.g. image/jpeg) or just type (e.g. image)
            // match[1] = full mime type, e.g. image/jpeg
            // match[2] = first part, e.g. image
            // match[3] = last part, e.g. jpeg
            $info['mime'] = trim($match[1]);
            $info['type'] = trim($match[2]);
            $info['subtype'] = trim($match[3]);
            foreach (array($info['mime'], $info['type']) as $mime) {
                if (isset($this->config['content_type_exc'][$mime])) {
                    $info['action'] = $this->config['content_type_exc'][$mime]['action'];
                    $info['name'] = $this->config['content_type_exc'][$mime]['name'];
                    break;
                }
            }
        }
        return $info;
    }