diff --git a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php index dc92133..ae816da 100644 --- a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php +++ b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php @@ -18,6 +18,13 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface { protected $mapper; /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs a new ExtensionMimeTypeGuesser. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -57,7 +64,8 @@ public function guess($path) { * Sets the mimetypes/extension mapping to use when guessing mimetype. * * @param array|null $mapping - * Passing a NULL mapping will cause guess() to use self::$defaultMapping. + * Passing a NULL mapping will cause guess() to use the mapping provided + * by the file.mime_type.mapper service. */ public function setMapping(array $mapping = NULL) { $this->getMapper()->setMapping($mapping); @@ -66,6 +74,8 @@ public function setMapping(array $mapping = NULL) { /** * Returns the MIME type mapper service. * + * @todo in D9, properly inject this service. + * * @return \Drupal\Core\File\MimeType\MimeTypeMapperInterface * The MIME type mapper service. */ @@ -76,4 +86,23 @@ protected function getMapper() { return $this->mapper; } + /** + * Returns ::$mapping or ::$defaultMapping from the mapper. + * + * ::$mapping and ::$defaultMapping were removed in 8.3.x., here we are using + * a magic method to return their value from the mapper service. + * + * @todo remove in D9, introduced for BC in D8.3.x. + */ + public function __get($name) { + switch ($name) { + case 'mapping': + return $this->getMapper()->_getMapping(); + + case 'defaultMapping': + return $this->getMapper()->_getDefaultMapping(); + + } + } + } diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php index db7966f..b528cb0 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php @@ -10,6 +10,16 @@ class MimeTypeMapper implements MimeTypeMapperInterface { /** + * Default MIME extension mapping. + * + * @todo remove in D9, introduced for BC in D8.3.x. + * + * @var array + * Array of mimetypes correlated to the extensions that relate to them. + */ + protected $defaultMapping; + + /** * MIME extension mapping. * * @var array @@ -866,6 +876,51 @@ class MimeTypeMapper implements MimeTypeMapperInterface { protected $isMappingAltered = FALSE; /** + * Constructs a new MimeTypeMapper object. + * + * @todo remove in D9, introduced for BC in D8.3.x. + */ + public function __construct() { + $this->defaultMapping = $this->mapping; + } + + /** + * Returns the ALTERED mapping from extensions to MIME types. + * + * @return array + * An array consisting of two arrays: + * - mimetypes: MIME types, keyed by a unique number. + * - extensions: an associative array with the MIME type key numbers as + * values. The keys are file extensions, in lower case and without any + * preceding dot. + * + * @todo remove in D9, introduced for BC in D8.3.x. + * + * @internal + */ + public function _getMapping() { + return $this->mapping; + } + + /** + * Returns the DEFAULT mapping from extensions to MIME types, before alter. + * + * @return array + * An array consisting of two arrays: + * - mimetypes: MIME types, keyed by a unique number. + * - extensions: an associative array with the MIME type key numbers as + * values. The keys are file extensions, in lower case and without any + * preceding dot. + * + * @todo remove in D9, introduced for BC in D8.3.x. + * + * @internal + */ + public function _getDefaultMapping() { + return $this->defaultMapping; + } + + /** * {@inheritdoc} */ public function alterMapping(ModuleHandlerInterface $module_handler) {