xsga / bbphp-exception
A PHP exception library
v1.0.0
2026-09-25 05:36 UTC
Requires
- php: ^8.4
Requires (Dev)
- php-parallel-lint/php-console-highlighter: ^1.0
- php-parallel-lint/php-parallel-lint: ^1.4
- phpmd/phpmd: ^2.15
- squizlabs/php_codesniffer: ^4.0
- vimeo/psalm: ^6.14
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-25 05:41:55 UTC
README
A lightweight PHP library that provides a reusable base exception class with support for structured context parameters.
Features
- Strict typing and modern PHP support.
- Custom exception class:
Xsga\BBPHP\Exception\GenericException. - Optional context parameters via
getParams(). - PSR-4 autoloading ready for Composer projects.
Requirements
- PHP 8.4+
Installation
Install with Composer:
composer require xsga/bbphp-exception
Usage
<?php declare(strict_types=1); use Xsga\BBPHP\Exception\GenericException; try { throw new GenericException( message: 'Validation failed', code: 422, params: ['field' => 'email', 'reason' => 'invalid_format'] ); } catch (GenericException $e) { echo $e->getMessage(); // Validation failed print_r($e->getParams()); }
API
GenericException
Constructor:
public function __construct( string $message = '', int $code = 0, protected array $params = [], ?Throwable $previous = null )
Methods:
getParams(): arrayReturns the context parameters passed to the exception.
Development
Useful Composer scripts:
composer lintRun parallel PHP lint.composer styleCheck PSR-12 style.composer style-fixAuto-fix style issues.composer analyze-errorsRun Psalm (errors only).composer analyze-infoRun Psalm (with info).composer analyze-mdRun PHPMD checks.
License
MIT License. See LICENSE.