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