NormalizedException

From mediawiki.org

NormalizedException is a minimal PHP library to facilitate PSR-3-friendly exception handling.

Usage[edit]

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 $context = [] ) {
		$this->getMessageFromNormalizedMessage( $normalizedMessage, $context );
		$this->normalizedMessage = $normalizedMessage;
		$this->context = $context;
	} 
}

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

External links[edit]