class ExtensionMimeTypeGuesser in FileField Sources 8
Same name in this branch
- 8 src/File/MimeType/ExtensionMimeTypeGuesser.php \Drupal\filefield_sources\File\MimeType\ExtensionMimeTypeGuesser
- 8 src/ProxyClass/File/MimeType/ExtensionMimeTypeGuesser.php \Drupal\filefield_sources\ProxyClass\File\MimeType\ExtensionMimeTypeGuesser
Add methods to core guesser.
Hierarchy
- class \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser implements \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
- class \Drupal\filefield_sources\File\MimeType\ExtensionMimeTypeGuesser
Expanded class hierarchy of ExtensionMimeTypeGuesser
File
- src/
File/ MimeType/ ExtensionMimeTypeGuesser.php, line 10
Namespace
Drupal\filefield_sources\File\MimeTypeView source
class ExtensionMimeTypeGuesser extends CoreExtensionMimeTypeGuesser {
/**
* Convert mime type to extension.
*
* @param string $mimetype
* Mime type.
*
* @return string|bool
* Return extension if found, FALSE otherwise.
*/
public function convertMimeTypeToExtension($mimetype) {
$this
->checkDefaultMapping();
$mime_key = array_search($mimetype, $this->mapping['mimetypes']);
$extension = array_search($mime_key, $this->mapping['extensions']);
return $extension;
}
/**
* Convert mime type to most common extension.
*
* @param string $mimetype
* Mime type.
*
* @return string|bool
* Return extension if found, FALSE otherwise.
*/
public function convertMimeTypeToMostCommonExtension($mimetype) {
$this
->checkDefaultMapping();
$extension = FALSE;
if (isset($mimetype)) {
// See if this matches a known MIME type.
$mime_key = array_search($mimetype, $this->mapping['mimetypes']);
if ($mime_key !== FALSE) {
// If we have a match, get this list of likely extensions. For some
// reason Drupal lists the "most common" extension last for most file
// types including php, jpg, and doc.
if ($extensions = array_keys($this->mapping['extensions'], $mime_key)) {
$extension = end($extensions);
}
}
}
return $extension;
}
/**
* Check for default mapping.
*/
private function checkDefaultMapping() {
if ($this->mapping === NULL) {
$mapping = $this->defaultMapping;
// Allow modules to alter the default mapping.
$this->moduleHandler
->alter('file_mimetype_mapping', $mapping);
$this->mapping = $mapping;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtensionMimeTypeGuesser:: |
protected | property | Default MIME extension mapping. | |
ExtensionMimeTypeGuesser:: |
protected | property | The MIME types mapping array after going through the module handler. | |
ExtensionMimeTypeGuesser:: |
protected | property | The module handler. | |
ExtensionMimeTypeGuesser:: |
private | function | Check for default mapping. | |
ExtensionMimeTypeGuesser:: |
public | function | Convert mime type to extension. | |
ExtensionMimeTypeGuesser:: |
public | function | Convert mime type to most common extension. | |
ExtensionMimeTypeGuesser:: |
public | function | Guesses the mime type of the file with the given path. | |
ExtensionMimeTypeGuesser:: |
public | function | Sets the mimetypes/extension mapping to use when guessing mimetype. | |
ExtensionMimeTypeGuesser:: |
public | function | Constructs a new ExtensionMimeTypeGuesser. |