wikimedia/normalized-exception

A helper for making exceptions play nice with PSR-3 logging

v1.0.1 2021-07-01 07:36 UTC

This package is auto-updated.

Last update: 2021-09-20 13:29:29 UTC


README

Latest Stable Version License

NormalizedException

A minimal library to facilitate PSR-3-friendly exception handling.

Additional documentation about the library can be found on MediaWiki.org.

Usage

use Wikimedia\NormalizedException\INormalizedException;
use Wikimedia\NormalizedException\NormalizedExceptionTrait;

class MyException extends SomeException implements INormalizedException {
	use NormalizedExceptionTrait;

	private $normalizedMessage;
	private $context;

	public function __construct( string $normalizedMessage, array $context = [] ) {
		$this->getMessageFromNormalizedMessage( $normalizedMessage, $context );
		$this->normalizedMessage = $normalizedMessage;
		$this->context = $context;
	}
}
throw new MyException( 'Invalid value: {value}', [ 'value' => $value ] );

Running tests

composer install --dev
composer test

History

This library was split out of MediaWiki changeset 670465 during the MediaWiki 1.37 development cycle.