MediaWiki master
RestStatusTrait.php
Go to the documentation of this file.
1<?php
2
4
9
13trait RestStatusTrait {
14
24 private function throwExceptionForStatus(
25 StatusValue $status,
26 $msg,
27 int $code,
28 array $data = []
29 ) {
30 $data += [ 'error-keys' => $this->getStatusErrorKeys( $status ) ];
31
32 if ( is_string( $msg ) ) {
33 $msg = MessageValue::new( $msg )
34 ->semicolonListParams( $status->getMessages() );
35 }
36
37 throw new LocalizedHttpException( $msg, $code, $data );
38 }
39
40 private function getStatusErrorKeys( StatusValue $status ) {
41 $keys = [];
42
43 foreach ( $status->getMessages() as $msg ) {
44 $keys[] = $msg->getKey();
45 }
46
47 return array_unique( $keys );
48 }
49
50 private function logStatusError( StatusValue $status, string $message, string $channel ) {
51 LoggerFactory::getInstance( $channel )->error(
52 $message,
53 [ 'reason' => $this->getStatusErrorKeys( $status ) ]
54 );
55 }
56
57}
Create PSR-3 logger objects.
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.
Value object representing a message for i18n.
semicolonListParams(... $values)
Chainable mutator which adds semicolon lists (ListType::SEMICOLON).
Copyright (C) 2011-2020 Wikimedia Foundation and others.