mitsuki / contracts
Core interfaces and abstractions for the Mitsuki framework.
README
Mitsuki Contracts is a set of core interfaces and abstractions for the Mitsuki framework. By using these contracts, you can build decoupled, testable, and interchangeable components.
🚀 Features
- Decoupling: Depend on abstractions, not implementations (Dependency Inversion Principle).
- Standardization: Unified error handling and validation flow.
- Lightweight: Zero external dependencies (only PHP 8.1+).
📦 Installation
You can install the package via Composer:
composer require mitsuki/contracts
🛠Usage
Validation Contract
To create a request that supports self-validation, implement the ValidatableRequestInterface. This ensures your application remains consistent by forcing a validateOrFail flow.
use Mitsuki\Contracts\Validation\ValidatableRequestInterface; use Mitsuki\Contracts\Validation\Exceptions\ValidationException; class RegisterRequest implements ValidatableRequestInterface { public function validateOrFail(): void { // Your logic: if validation fails... // throw new MyValidationException("Invalid data"); } public function getErrors(): array { return ['email' => ['The email field is required.']]; } }
Exception Handling
All framework-specific exceptions implement the ExceptionInterface, allowing for clean global catching:
try { $request->validateOrFail(); } catch (\Mitsuki\Contracts\Exceptions\ExceptionInterface $e) { // Catch any Mitsuki related exception }
👤 Author
- Zgenius Matondo - zgeniuscoders@gmail.com
📄 License
The MIT License (MIT). Please see License File for more information.
Message de Commit
docs: create professional README with installation and usage guides
Souhaitez-vous que je génère également le fichier LICENSE (MIT) avec votre nom pour compléter le dépôt ?