From: saper Date: Tue, 26 Aug 2014 20:10:16 +0000 (+0200) Subject: Provide Status::__toString() X-Git-Tag: 1.31.0-rc.0~13323^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=110d5ccea0f70629e8caec7b04bc3310d196923b;p=lhc%2Fweb%2Fwiklou.git Provide Status::__toString() maintenance/eval.php is much easier to use now, you can just print $statusInstance; Change-Id: I068b0f54b16d618a1f6115133632885e8e45e897 --- diff --git a/includes/Status.php b/includes/Status.php index 0a8062c2a3..265eae1711 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -369,14 +369,14 @@ class Status { } /** - * Returns a list of status messages of the given type + * Returns a list of status messages of the given type (or all if false) * @param string $type * @return array */ - protected function getStatusArray( $type ) { + protected function getStatusArray( $type = false ) { $result = array(); foreach ( $this->errors as $error ) { - if ( $error['type'] === $type ) { + if ( $type === false || $error['type'] === $type ) { if ( $error['message'] instanceof Message ) { $result[] = array_merge( array( $error['message']->getKey() ), @@ -462,4 +462,45 @@ class Status { public function getValue() { return $this->value; } + + /** + * @return string + */ + public function __toString() { + $status = $this->isOK() ? "OK" : "Error"; + if ( count( $this->errors ) ) { + $errorcount = "collected " . ( count($this->errors) ) . " error(s) on the way"; + } else { + $errorcount = "no errors detected"; + } + if ( isset( $this->value ) ) { + $valstr = gettype( $this->value ) . " value set"; + if ( is_object( $this->value ) ) { + $valstr .= "\"" . get_class( $this->value ) . "\" instance"; + } + } else { + $valstr = "no value set"; + } + $out = sprintf( "<%s, %s, %s>", + $status, + $errorcount, + $valstr + ); + if ( count ($this->errors ) > 0 ) { + $hdr = sprintf( "+-%'-4s-+-%'-25s-+-%'-40s-+\n", "", "", "" ); + $i = 1; + $out .= "\n"; + $out .= $hdr; + foreach( $this->getStatusArray() as $stat ) { + $out .= sprintf( "| %4d | %-25.25s | %-40.40s |\n", + $i, + $stat[0], + implode(" ", array_slice( $stat, 1 ) ) + ); + $i += 1; + } + $out .= $hdr; + }; + return $out; + } }