| 1 |
[![Latest Stable Version]](https://packagist.org/packages/wikimedia/normalized-exception) [![License]](https://packagist.org/packages/wikimedia/normalized-exception) |
| 2 |
|
| 3 |
NormalizedException |
| 4 |
===================== |
| 5 |
|
| 6 |
A minimal library to facilitate [PSR-3][]-friendly exception handling. |
| 7 |
|
| 8 |
Additional documentation about the library can be found on |
| 9 |
[MediaWiki.org](https://www.mediawiki.org/wiki/NormalizedException). |
| 10 |
|
| 11 |
|
| 12 |
Usage |
| 13 |
----- |
| 14 |
|
| 15 |
Use the standard implementation: |
| 16 |
|
| 17 |
```php |
| 18 |
use Wikimedia\NormalizedException\NormalizedException; |
| 19 |
|
| 20 |
throw new NormalizedException( 'Invalid value: {value}', [ 'value' => $value ] ); |
| 21 |
``` |
| 22 |
|
| 23 |
Integrate into another framework or library: |
| 24 |
|
| 25 |
```php |
| 26 |
use Wikimedia\NormalizedException\INormalizedException; |
| 27 |
use Wikimedia\NormalizedException\NormalizedExceptionTrait; |
| 28 |
|
| 29 |
class MyException extends SomeException implements INormalizedException { |
| 30 |
use NormalizedExceptionTrait; |
| 31 |
|
| 32 |
public function __construct( string $normalizedMessage, array $messageContext = [] ) { |
| 33 |
$this->normalizedMessage = $normalizedMessage; |
| 34 |
$this->messageContext = $messageContext; |
| 35 |
parent::__construct( |
| 36 |
self::getMessageFromNormalizedMessage( $normalizedMessage, $messageContext ) |
| 37 |
); |
| 38 |
} |
| 39 |
} |
| 40 |
``` |
| 41 |
|
| 42 |
```php |
| 43 |
throw new MyException( 'Invalid value: {value}', [ 'value' => $value ] ); |
| 44 |
``` |
| 45 |
|
| 46 |
Running tests |
| 47 |
------------- |
| 48 |
|
| 49 |
``` |
| 50 |
composer install --dev |
| 51 |
composer test |
| 52 |
``` |
| 53 |
|
| 54 |
History |
| 55 |
------- |
| 56 |
|
| 57 |
This library was split out of [MediaWiki][] changeset [670465][] during the |
| 58 |
MediaWiki 1.37 development cycle. |
| 59 |
|
| 60 |
|
| 61 |
--- |
| 62 |
[PSR-3]: https://www.php-fig.org/psr/psr-3/ |
| 63 |
[MediaWiki]: https://www.mediawiki.org/wiki/MediaWiki |
| 64 |
[670465]: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/670465 |
| 65 |
[Latest Stable Version]: https://poser.pugx.org/wikimedia/normalized-exception/v/stable.svg |
| 66 |
[License]: https://poser.pugx.org/wikimedia/normalized-exception/license.svg |