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: 2024-11-03 13:09:10 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 the standard implementation:

use Wikimedia\NormalizedException\NormalizedException;

throw new NormalizedException( 'Invalid value: {value}', [ 'value' => $value ] );

Integrate into another framework or library:

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

class MyException extends SomeException implements INormalizedException {
	use NormalizedExceptionTrait;

	public function __construct( string $normalizedMessage, array $messageContext = [] ) {
		$this->normalizedMessage = $normalizedMessage;
		$this->messageContext = $messageContext;
		parent::__construct(
			self::getMessageFromNormalizedMessage( $normalizedMessage, $messageContext )
		);
	}
}
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.