| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Parser; |
| 4 |
|
| 5 |
use MediaWiki\Extension\AbuseFilter\Parser\Exception\ExceptionBase; |
| 6 |
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleWarning; |
| 7 |
|
| 8 |
class RuleCheckerStatus extends ParserStatus { |
| 9 |
|
| 10 |
private $result; |
| 11 |
|
| 12 |
private $warmCache; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function __construct( |
| 22 |
bool $result, |
| 23 |
bool $warmCache, |
| 24 |
?ExceptionBase $excep, |
| 25 |
array $warnings, |
| 26 |
int $condsUsed |
| 27 |
) { |
| 28 |
parent::__construct( $excep, $warnings, $condsUsed ); |
| 29 |
$this->result = $result; |
| 30 |
$this->warmCache = $warmCache; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function getResult(): bool { |
| 37 |
return $this->result; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function getWarmCache(): bool { |
| 44 |
return $this->warmCache; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function toArray(): array { |
| 52 |
return [ |
| 53 |
'result' => $this->result, |
| 54 |
'warmCache' => $this->warmCache, |
| 55 |
'exception' => $this->excep ? $this->excep->toArray() : null, |
| 56 |
'warnings' => array_map( |
| 57 |
static function ( $warn ) { |
| 58 |
return $warn->toArray(); |
| 59 |
}, |
| 60 |
$this->warnings |
| 61 |
), |
| 62 |
'condsUsed' => $this->condsUsed, |
| 63 |
]; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public static function fromArray( array $value ): self { |
| 72 |
$excClass = $value['exception']['class'] ?? null; |
| 73 |
return new self( |
| 74 |
$value['result'], |
| 75 |
$value['warmCache'], |
| 76 |
$excClass !== null ? call_user_func( [ $excClass, 'fromArray' ], $value['exception'] ) : null, |
| 77 |
array_map( [ UserVisibleWarning::class, 'fromArray' ], $value['warnings'] ), |
| 78 |
$value['condsUsed'] |
| 79 |
); |
| 80 |
} |
| 81 |
} |