Merge "Add method parameter type documentation"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendStore.php
index e976a7a..8ff383b 100644 (file)
 abstract class FileBackendStore extends FileBackend {
        /** @var BagOStuff */
        protected $memCache;
-       /** @var ProcessCacheLRU */
-       protected $cheapCache; // Map of paths to small (RAM/disk) cache items
-       /** @var ProcessCacheLRU */
-       protected $expensiveCache; // Map of paths to large (RAM/disk) cache items
+       /** @var ProcessCacheLRU Map of paths to small (RAM/disk) cache items */
+       protected $cheapCache;
+       /** @var ProcessCacheLRU Map of paths to large (RAM/disk) cache items */
+       protected $expensiveCache;
 
-       /** @var Array Map of container names to sharding settings */
-       protected $shardViaHashLevels = array(); // (container name => config array)
+       /** @var Array Map of container names to sharding config */
+       protected $shardViaHashLevels = array();
+
+       /** @var callback Method to get the MIME type of files */
+       protected $mimeCallback;
 
        protected $maxFileSize = 4294967296; // integer bytes (4GiB)
 
@@ -54,11 +57,21 @@ abstract class FileBackendStore extends FileBackend {
 
        /**
         * @see FileBackend::__construct()
+        * Additional $config params include:
+        *   - mimeCallback : Callback that takes (storage path, content, file system path) and
+        *                    returns the MIME type of the file or 'unknown/unknown'. The file
+        *                    system path parameter should be used if the content one is null.
         *
         * @param array $config
         */
        public function __construct( array $config ) {
                parent::__construct( $config );
+               $this->mimeCallback = isset( $config['mimeCallback'] )
+                       ? $config['mimeCallback']
+                       : function( $storagePath, $content, $fsPath ) {
+                               // @TODO: handle the case of extension-less files using the contents
+                               return StreamFile::contentTypeFromPath( $storagePath ) ?: 'unknown/unknown';
+                       };
                $this->memCache = new EmptyBagOStuff(); // disabled by default
                $this->cheapCache = new ProcessCacheLRU( self::CACHE_CHEAP_SIZE );
                $this->expensiveCache = new ProcessCacheLRU( self::CACHE_EXPENSIVE_SIZE );
@@ -1583,6 +1596,18 @@ abstract class FileBackendStore extends FileBackend {
                }
                return $opts;
        }
+
+       /**
+        * Get the content type to use in HEAD/GET requests for a file
+        *
+        * @param string $storagePath
+        * @param string|null $content File data
+        * @param string|null $fsPath File system path
+        * @return MIME type
+        */
+       protected function getContentType( $storagePath, $content, $fsPath ) {
+               return call_user_func_array( $this->mimeCallback, func_get_args() );
+       }
 }
 
 /**