Merge "FileRepo: Use Late Static Binding in File static constructors"
This commit is contained in:
commit
7bfec54fa5
5 changed files with 34 additions and 43 deletions
|
|
@ -31,31 +31,6 @@ use Wikimedia\Rdbms\DBUnexpectedError;
|
|||
* @ingroup FileAbstraction
|
||||
*/
|
||||
class ForeignDBFile extends LocalFile {
|
||||
/**
|
||||
* @param Title $title
|
||||
* @param FileRepo $repo
|
||||
* @param null $unused
|
||||
* @return ForeignDBFile
|
||||
*/
|
||||
static function newFromTitle( $title, $repo, $unused = null ) {
|
||||
return new self( $title, $repo );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ForeignDBFile from a title
|
||||
* Do not call this except from inside a repo class.
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @param FileRepo $repo
|
||||
* @return ForeignDBFile
|
||||
*/
|
||||
static function newFromRow( $row, $repo ) {
|
||||
$title = Title::makeTitle( NS_FILE, $row->img_name );
|
||||
$file = new self( $title, $repo );
|
||||
$file->loadFromRow( $row );
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $srcPath
|
||||
|
|
|
|||
|
|
@ -150,10 +150,10 @@ class LocalFile extends File {
|
|||
* @param FileRepo $repo
|
||||
* @param null $unused
|
||||
*
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
static function newFromTitle( $title, $repo, $unused = null ) {
|
||||
return new self( $title, $repo );
|
||||
return new static( $title, $repo );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -163,11 +163,11 @@ class LocalFile extends File {
|
|||
* @param stdClass $row
|
||||
* @param FileRepo $repo
|
||||
*
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
static function newFromRow( $row, $repo ) {
|
||||
$title = Title::makeTitle( NS_FILE, $row->img_name );
|
||||
$file = new self( $title, $repo );
|
||||
$file = new static( $title, $repo );
|
||||
$file->loadFromRow( $row );
|
||||
|
||||
return $file;
|
||||
|
|
@ -190,12 +190,12 @@ class LocalFile extends File {
|
|||
$conds['img_timestamp'] = $dbr->timestamp( $timestamp );
|
||||
}
|
||||
|
||||
$fileQuery = self::getQueryInfo();
|
||||
$fileQuery = static::getQueryInfo();
|
||||
$row = $dbr->selectRow(
|
||||
$fileQuery['tables'], $fileQuery['fields'], $conds, __METHOD__, [], $fileQuery['joins']
|
||||
);
|
||||
if ( $row ) {
|
||||
return self::newFromRow( $row, $repo );
|
||||
return static::newFromRow( $row, $repo );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class OldLocalFile extends LocalFile {
|
|||
* @param Title $title
|
||||
* @param FileRepo $repo
|
||||
* @param string|int|null $time
|
||||
* @return self
|
||||
* @return static
|
||||
* @throws MWException
|
||||
*/
|
||||
static function newFromTitle( $title, $repo, $time = null ) {
|
||||
|
|
@ -51,27 +51,27 @@ class OldLocalFile extends LocalFile {
|
|||
throw new MWException( __METHOD__ . ' got null for $time parameter' );
|
||||
}
|
||||
|
||||
return new self( $title, $repo, $time, null );
|
||||
return new static( $title, $repo, $time, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Title $title
|
||||
* @param FileRepo $repo
|
||||
* @param string $archiveName
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
static function newFromArchiveName( $title, $repo, $archiveName ) {
|
||||
return new self( $title, $repo, null, $archiveName );
|
||||
return new static( $title, $repo, null, $archiveName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $row
|
||||
* @param FileRepo $repo
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
static function newFromRow( $row, $repo ) {
|
||||
$title = Title::makeTitle( NS_FILE, $row->oi_name );
|
||||
$file = new self( $title, $repo, null, $row->oi_archive_name );
|
||||
$file = new static( $title, $repo, null, $row->oi_archive_name );
|
||||
$file->loadFromRow( $row, 'oi_' );
|
||||
|
||||
return $file;
|
||||
|
|
@ -95,12 +95,12 @@ class OldLocalFile extends LocalFile {
|
|||
$conds['oi_timestamp'] = $dbr->timestamp( $timestamp );
|
||||
}
|
||||
|
||||
$fileQuery = self::getQueryInfo();
|
||||
$fileQuery = static::getQueryInfo();
|
||||
$row = $dbr->selectRow(
|
||||
$fileQuery['tables'], $fileQuery['fields'], $conds, __METHOD__, [], $fileQuery['joins']
|
||||
);
|
||||
if ( $row ) {
|
||||
return self::newFromRow( $row, $repo );
|
||||
return static::newFromRow( $row, $repo );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,19 +55,19 @@ class UnregisteredLocalFile extends File {
|
|||
/**
|
||||
* @param string $path Storage path
|
||||
* @param string $mime
|
||||
* @return UnregisteredLocalFile
|
||||
* @return static
|
||||
*/
|
||||
static function newFromPath( $path, $mime ) {
|
||||
return new self( false, false, $path, $mime );
|
||||
return new static( false, false, $path, $mime );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Title $title
|
||||
* @param FileRepo $repo
|
||||
* @return UnregisteredLocalFile
|
||||
* @return static
|
||||
*/
|
||||
static function newFromTitle( $title, $repo ) {
|
||||
return new self( $title, $repo, false, false );
|
||||
return new static( $title, $repo, false, false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
16
tests/phpunit/includes/filerepo/file/ForeignDBFileTest.php
Normal file
16
tests/phpunit/includes/filerepo/file/ForeignDBFileTest.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/** @covers ForeignDBFile */
|
||||
class ForeignDBFileTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
use PHPUnit4And6Compat;
|
||||
|
||||
public function testShouldConstructCorrectInstanceFromTitle() {
|
||||
$title = Title::makeTitle( NS_FILE, 'Awesome_file' );
|
||||
$repoMock = $this->createMock( LocalRepo::class );
|
||||
|
||||
$file = ForeignDBFile::newFromTitle( $title, $repoMock );
|
||||
|
||||
$this->assertInstanceOf( ForeignDBFile::class, $file );
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue