承接 maximaster/exceptior 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maximaster/exceptior

最新稳定版本:v1.1.1

Composer 安装命令:

composer require maximaster/exceptior

包简介

Functions collection to ease exception handling.

README 文档

README

Functions collection to ease exception handling.

composer require maximaster/exceptior

CASE #1: convert throwing void function into boolean

use Maximaster\Exceptior\Ex;

$noOpeation = function(): void {};
$wouldThrow = fn () => throw new Exception('hello');

Ex::boolize($noOpeation); // === true
Ex::boolize($wouldThrow); // === false

CASE #2: convert throwing function with return into returning value of your choice

use Maximaster\Exceptior\Ex;

$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');

Ex::suppressInto($giveString, 'fail'); // === 'hello'
Ex::suppressInto($wouldThrow, 'fail'); // === 'fail'

CASE #3: convert exception into another exception

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

CASE #4: normalize thrown exception to value provided by callable

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'

CASE #5: return worker value or null if worker throws an exception

$giveString = fn () => 'hello'
$wouldThrow = fn () => throw new Exception('no hello');

Ex::nullize($giveString); // === 'hello'
Ex::nullize($wouldThrow); // === null

Development

Fork → Edit → composer check → PR.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-30