wernerdweight / enhanced-exception
Generic enhanced exception to be used in other projects
Installs: 5 834
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- thecodingmachine/safe: ^2.4
Requires (Dev)
This package is auto-updated.
Last update: 2024-12-21 21:08:30 UTC
README
Generic enhanced exception to be used in other projects
Instalation
- Download using composer
composer require wernerdweight/enhanced-exception
- Define your exceptions
use WernerDweight\EnhancedException\Exception\AbstractEnhancedException; class MyException extends AbstractEnhancedException { /** @var int */ public const EXCEPTION_SOMETHING_BAG_HAPPENED = 1; /** @var int */ public const EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION = 2; /** @var string[] */ protected static $messages = [ self::EXCEPTION_SOMETHING_BAG_HAPPENED => 'Something bad happened! Helpful, I know.', self::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION => 'Didn\'t expect Spanish inquisition to reach user %s!', ]; }
- Use your exceptions
throw new MyException(MyException::EXCEPTION_DIDNT_EXPECT_SPANISH_INQUISITION, [$user->getUsername()]); // will throw `Didn't expect Spanish inquisition to reach user Ferdinand II!`