16trait RestStatusTrait {
18 private ?
Converter $messageValueConverter =
null;
20 private function getMessageValueConverter():
Converter {
21 if ( !$this->messageValueConverter ) {
22 $this->messageValueConverter =
new Converter();
24 return $this->messageValueConverter;
32 private function convertStatusToMessageValues(
StatusValue $status ): array {
33 $conv = $this->getMessageValueConverter();
34 return array_map(
static function ( $error ) use ( $conv ) {
37 return $conv->convertMessage(
52 private function throwExceptionForStatus(
58 $data += [
'error-keys' => $this->getStatusErrorKeys( $status ) ];
60 if ( is_string( $msg ) ) {
61 $msg = MessageValue::new( $msg )
62 ->semicolonListParams(
63 $this->convertStatusToMessageValues( $status )
70 private function getStatusErrorKeys(
StatusValue $status ) {
73 foreach ( $status->
getErrors() as [
'message' => $msg ] ) {
74 if ( is_string( $msg ) ) {
76 } elseif ( is_array( $msg ) ) {
79 $keys[] = $msg->getKey();
83 return array_unique( $keys );
86 private function logStatusError(
StatusValue $status,
string $message,
string $channel ) {
87 LoggerFactory::getInstance( $channel )->error(
89 [
'reason' => $this->getStatusErrorKeys( $status ) ]
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrors()
Get the list of errors.