| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\ConfirmEdit\Store; |
| 4 |
|
| 5 |
use BadMethodCallException; |
| 6 |
use MediaWiki\Config\ConfigException; |
| 7 |
|
| 8 |
abstract class CaptchaStore { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
abstract public function store( $index, $info ); |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
abstract public function retrieve( $index ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
abstract public function clear( $index ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
abstract public function cookiesNeeded(); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
private static $instance; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
final public static function get() { |
| 47 |
global $wgCaptchaStorageClass; |
| 48 |
if ( !self::$instance instanceof self ) { |
| 49 |
if ( in_array( self::class, class_parents( $wgCaptchaStorageClass ) ) ) { |
| 50 |
self::$instance = new $wgCaptchaStorageClass; |
| 51 |
} else { |
| 52 |
throw new ConfigException( "Invalid CaptchaStore class $wgCaptchaStorageClass" ); |
| 53 |
} |
| 54 |
} |
| 55 |
return self::$instance; |
| 56 |
} |
| 57 |
|
| 58 |
final public static function unsetInstanceForTests() { |
| 59 |
if ( !defined( 'MW_PHPUNIT_TEST' ) ) { |
| 60 |
throw new BadMethodCallException( 'Cannot unset ' . __CLASS__ . ' instance in operation.' ); |
| 61 |
} |
| 62 |
self::$instance = null; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
protected function __construct() { |
| 69 |
} |
| 70 |
} |