MediaWiki
REL1_22
|
00001 <?php 00031 class MockFileBackend extends FileBackendStore { 00032 00033 protected $mocked = array(); 00034 00036 protected function debug( $msg = '' ) { 00037 wfDebug( wfGetCaller() . "$msg\n" ); 00038 } 00039 00040 public function isPathUsableInternal( $storagePath ) { 00041 return true; 00042 } 00043 00044 protected function doCreateInternal( array $params ) { 00045 if ( isset( $params['content'] ) ) { 00046 $content = $params['content']; 00047 } else { 00048 $content = 'Default mocked file content'; 00049 } 00050 $this->debug( serialize( $params ) ); 00051 $dst = $params['dst']; 00052 $this->mocked[$dst] = $content; 00053 return Status::newGood(); 00054 } 00055 00056 protected function doStoreInternal( array $params ) { 00057 $this->debug( serialize( $params ) ); 00058 return $this->doCreateInternal( $params ); 00059 } 00060 00061 protected function doCopyInternal( array $params ) { 00062 $this->debug( serialize( $params ) ); 00063 $src = $params['src']; 00064 $dst = $params['dst']; 00065 $this->mocked[$dst] = $this->mocked[$src]; 00066 return Status::newGood(); 00067 } 00068 00069 protected function doDeleteInternal( array $params ) { 00070 $this->debug( serialize( $params ) ); 00071 $src = $params['src']; 00072 unset( $this->mocked[$src] ); 00073 return Status::newGood(); 00074 } 00075 00076 protected function doGetFileStat( array $params ) { 00077 $src = $params['src']; 00078 if ( array_key_exists( $src, $this->mocked ) ) { 00079 $this->debug( "('$src') found" ); 00080 return array( 00081 'mtime' => wfTimestamp( TS_MW ), 00082 'size' => strlen( $this->mocked[$src] ), 00083 # No sha1, stat does not need it. 00084 ); 00085 } else { 00086 $this->debug( "('$src') not found" ); 00087 return false; 00088 } 00089 } 00090 00091 protected function doGetLocalCopyMulti( array $params ) { 00092 $tmpFiles = array(); // (path => MockFSFile) 00093 00094 $this->debug( '(' . serialize( $params ) . ')' ); 00095 foreach ( $params['srcs'] as $src ) { 00096 $tmpFiles[$src] = new MockFSFile( 00097 wfTempDir() . '/' . wfRandomString( 32 ) 00098 ); 00099 } 00100 return $tmpFiles; 00101 } 00102 00103 protected function doDirectoryExists( $container, $dir, array $params ) { 00104 $this->debug(); 00105 return true; 00106 } 00107 00108 public function getDirectoryListInternal( $container, $dir, array $params ) { 00109 $this->debug(); 00110 return array(); 00111 } 00112 00113 public function getFileListInternal( $container, $dir, array $params ) { 00114 $this->debug(); 00115 return array(); 00116 } 00117 00118 protected function directoriesAreVirtual() { 00119 $this->debug(); 00120 return true; 00121 } 00122 }