Dependency inject $wgTmpDirectory into FileBackend classes
[lhc/web/wiklou.git] / includes / filebackend / MemoryFileBackend.php
index 2879ddd..44fe2cb 100644 (file)
@@ -33,7 +33,7 @@
  */
 class MemoryFileBackend extends FileBackendStore {
        /** @var array Map of (file path => (data,mtime) */
-       protected $files = array();
+       protected $files = [];
 
        public function getFeatures() {
                return self::ATTR_UNICODE_PATHS;
@@ -44,7 +44,7 @@ class MemoryFileBackend extends FileBackendStore {
        }
 
        protected function doCreateInternal( array $params ) {
-               $status = Status::newGood();
+               $status = $this->newStatus();
 
                $dst = $this->resolveHashKey( $params['dst'] );
                if ( $dst === null ) {
@@ -53,16 +53,16 @@ class MemoryFileBackend extends FileBackendStore {
                        return $status;
                }
 
-               $this->files[$dst] = array(
+               $this->files[$dst] = [
                        'data' => $params['content'],
                        'mtime' => wfTimestamp( TS_MW, time() )
-               );
+               ];
 
                return $status;
        }
 
        protected function doStoreInternal( array $params ) {
-               $status = Status::newGood();
+               $status = $this->newStatus();
 
                $dst = $this->resolveHashKey( $params['dst'] );
                if ( $dst === null ) {
@@ -80,16 +80,16 @@ class MemoryFileBackend extends FileBackendStore {
                        return $status;
                }
 
-               $this->files[$dst] = array(
+               $this->files[$dst] = [
                        'data' => $data,
                        'mtime' => wfTimestamp( TS_MW, time() )
-               );
+               ];
 
                return $status;
        }
 
        protected function doCopyInternal( array $params ) {
-               $status = Status::newGood();
+               $status = $this->newStatus();
 
                $src = $this->resolveHashKey( $params['src'] );
                if ( $src === null ) {
@@ -113,16 +113,16 @@ class MemoryFileBackend extends FileBackendStore {
                        return $status;
                }
 
-               $this->files[$dst] = array(
+               $this->files[$dst] = [
                        'data' => $this->files[$src]['data'],
                        'mtime' => wfTimestamp( TS_MW, time() )
-               );
+               ];
 
                return $status;
        }
 
        protected function doDeleteInternal( array $params ) {
-               $status = Status::newGood();
+               $status = $this->newStatus();
 
                $src = $this->resolveHashKey( $params['src'] );
                if ( $src === null ) {
@@ -151,17 +151,17 @@ class MemoryFileBackend extends FileBackendStore {
                }
 
                if ( isset( $this->files[$src] ) ) {
-                       return array(
+                       return [
                                'mtime' => $this->files[$src]['mtime'],
                                'size' => strlen( $this->files[$src]['data'] ),
-                       );
+                       ];
                }
 
                return false;
        }
 
        protected function doGetLocalCopyMulti( array $params ) {
-               $tmpFiles = array(); // (path => TempFSFile)
+               $tmpFiles = []; // (path => TempFSFile)
                foreach ( $params['srcs'] as $srcPath ) {
                        $src = $this->resolveHashKey( $srcPath );
                        if ( $src === null || !isset( $this->files[$src] ) ) {
@@ -169,7 +169,7 @@ class MemoryFileBackend extends FileBackendStore {
                        } else {
                                // Create a new temporary file with the same extension...
                                $ext = FileBackend::extensionFromPath( $src );
-                               $fsFile = TempFSFile::factory( 'localcopy_', $ext );
+                               $fsFile = TempFSFile::factory( 'localcopy_', $ext, $this->tmpDirectory );
                                if ( $fsFile ) {
                                        $bytes = file_put_contents( $fsFile->getPath(), $this->files[$src]['data'] );
                                        if ( $bytes !== strlen( $this->files[$src]['data'] ) ) {
@@ -183,21 +183,6 @@ class MemoryFileBackend extends FileBackendStore {
                return $tmpFiles;
        }
 
-       protected function doStreamFile( array $params ) {
-               $status = Status::newGood();
-
-               $src = $this->resolveHashKey( $params['src'] );
-               if ( $src === null || !isset( $this->files[$src] ) ) {
-                       $status->fatal( 'backend-fail-stream', $params['src'] );
-
-                       return $status;
-               }
-
-               print $this->files[$src]['data'];
-
-               return $status;
-       }
-
        protected function doDirectoryExists( $container, $dir, array $params ) {
                $prefix = rtrim( "$container/$dir", '/' ) . '/';
                foreach ( $this->files as $path => $data ) {
@@ -210,7 +195,7 @@ class MemoryFileBackend extends FileBackendStore {
        }
 
        public function getDirectoryListInternal( $container, $dir, array $params ) {
-               $dirs = array();
+               $dirs = [];
                $prefix = rtrim( "$container/$dir", '/' ) . '/';
                $prefixLen = strlen( $prefix );
                foreach ( $this->files as $path => $data ) {
@@ -239,7 +224,7 @@ class MemoryFileBackend extends FileBackendStore {
        }
 
        public function getFileListInternal( $container, $dir, array $params ) {
-               $files = array();
+               $files = [];
                $prefix = rtrim( "$container/$dir", '/' ) . '/';
                $prefixLen = strlen( $prefix );
                foreach ( $this->files as $path => $data ) {