14trait RestStatusTrait {
16 private ?
Converter $messageValueConverter =
null;
18 private function getMessageValueConverter():
Converter {
19 if ( !$this->messageValueConverter ) {
20 $this->messageValueConverter =
new Converter();
22 return $this->messageValueConverter;
30 private function convertStatusToMessageValues(
StatusValue $status ): array {
31 $conv = $this->getMessageValueConverter();
32 return array_map(
static function ( $msg ) use ( $conv ) {
35 return $conv->convertMessage( $msg );
48 private function throwExceptionForStatus(
54 $data += [
'error-keys' => $this->getStatusErrorKeys( $status ) ];
56 if ( is_string( $msg ) ) {
57 $msg = MessageValue::new( $msg )
58 ->semicolonListParams(
59 $this->convertStatusToMessageValues( $status )
66 private function getStatusErrorKeys(
StatusValue $status ) {
70 $keys[] = $msg->getKey();
73 return array_unique( $keys );
76 private function logStatusError(
StatusValue $status,
string $message,
string $channel ) {
77 LoggerFactory::getInstance( $channel )->error(
79 [
'reason' => $this->getStatusErrorKeys( $status ) ]
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getMessages(?string $type=null)
Returns a list of error messages, optionally only those of the given type.