ommua / solid-domain
A PHP library that wraps and handle the errors in one place following the SOLID principle
Installs: 2 365
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- 00f100/phpdbug: *
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2025-01-29 06:32:10 UTC
README
A PHP library that wraps and handle the errors in one place following the SOLID principle
How to install
Composer:
$ composer require ommua/solid-domain
or add in composer.json
{ "require": { "ommua/solid-domain": "*" } }
How to use
Note: required implement "final protected function invokeDomain()" in your new Object Domain
EXAMPLE: <?php use Ommua\FailureResponse; use Ommua\SuccessResponse; use Ommua\SolidDomain; use Ommua\Interfaces\EitherFailureOrSuccess; class ConvertStringToInteger extends SolidDomain { /** * * @param String $stringNumber * @return EitherFailureOrSuccess */ final protected function invokeDomain(String $stringNumber) { if (is_numeric($stringNumber)) return new SuccessResponse(intval($stringNumber)); else return new FailureResponse(["Error cast string {$stringNumber}"]); } } $convertStringToInteger = new ConvertStringToInteger(); $failureOrSuccess = $convertStringToInteger("5"); $result= $failureOrSuccess->fold(function($error){ return $error; }, function ($success){ return $success; }); // Print: 5 echo $result; $failureOrSuccess = $convertStringToInteger("five"); $result= $failureOrSuccess->fold(function($error){ return $error; }, function ($success){ return $success; }); // Print: ["Error cast string five"] echo $result;