PHP code example of maximaster / exceptior
1. Go to this page and download the library: Download maximaster/exceptior library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maximaster / exceptior example snippets
use Maximaster\Exceptior\Ex;
$noOpeation = function(): void {};
$wouldThrow = fn () => throw new Exception('hello');
Ex::boolize($noOpeation); // === true
Ex::boolize($wouldThrow); // === false
use Maximaster\Exceptior\Ex;
$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');
Ex::suppressInto($giveString, 'fail'); // === 'hello'
Ex::suppressInto($wouldThrow, 'fail'); // === 'fail'
use Maximaster\Exceptior\Ex;
$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');
$converter = fn (Throwable $thrown) => new RuntimeException($thrown->getMessage());
Ex::convert($giveString, $converter); // === 'hello'
Ex::convert($wouldThrow, $converter); // throws RuntimeException
use Maximaster\Exceptior\Ex;
$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');
$normaizeToMessage = fn (Throwable $throwable) => $throwable->getMessage();
Ex::normalize($giveString, $normaizeToMessage); // === 'hello'
Ex::normalize($wouldThrow, $normaizeToMessage); // === 'no hello'
$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');
Ex::nullize($giveString); // === 'hello'
Ex::nullize($wouldThrow); // === null