Debian Codegraph @

extensions/ConfirmEdit/includes/Store/CaptchaStore.php

raw symbols SCIP
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 * Store the correct answer for a given captcha
11 * @param string $index
12 * @param array $info the captcha result
13 */
14 abstract public function store( $index, $info );
15
16 /**
17 * Retrieve the answer for a given captcha
18 * @param string $index
19 * @return array|false
20 */
21 abstract public function retrieve( $index );
22
23 /**
24 * Delete a result once the captcha has been used, so it cannot be reused
25 * @param string $index
26 */
27 abstract public function clear( $index );
28
29 /**
30 * Whether this type of CaptchaStore needs cookies
31 * @return bool
32 */
33 abstract public function cookiesNeeded();
34
35 /**
36 * The singleton instance
37 * @var CaptchaStore|null
38 */
39 private static $instance;
40
41 /**
42 * Get somewhere to store captcha data that will persist between requests
43 *
44 * @return CaptchaStore
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 * Protected constructor: no creating instances except through the factory method above
67 */
68 protected function __construct() {
69 }
70 }