fab2s/context-exception
Composer 安装命令:
composer require fab2s/context-exception
包简介
A context exception interface and implementation
关键字:
README 文档
README
Exception logging proves particularly useful to monitor application failure, but as it is, cannot provide with contextual data that could help out when processing those exception logs.
This Exception interface and implementation is just a step towards providing context to exceptions allowing you to interact with such exception and log them together with the extra information you would have provided.
It goes particularly well with Monolog and global exception handling where you can directly and globally add exception context to your log (when available) which may be of virtually any nature (monolog has a lot of handler and you can add more yourself to suite your need).
In your exception handler (or just a try{}catch{}:
if ($exception instanceof ContextExceptionInterface) { $context = $exception->getContext(); // now you can add this data to your monolog's context }
Setting context can be achieved in several ways :
// arguable way throw (new ContextException('Message'))->setContext($contextData); // or more conventional throw new ContextException('Message', 0, null, $contextData); // or step by step (also arguable) $exception = new ContextException; $exception->setContext($contextData); throw $exception;
IMHO, the arguability of some of the way to provide context to exceptions does not match the usefulness they provide IRL. I'm not saying that the conventional way to throw should not be in principle preferred, but I definitely find IRL use for things like :
} catch (ContextException $e) { // access context $context = $e->getContext(); // set context in case there is none $e->setContext($context); }
And from there, you get mutability so ...
Installation
ContextException can be installed using composer:
composer require "fab2s/context-exception"
V3.x introduces a breaking change in the
ContextExceptionInterfacewhich no more includes a signature for the constructor or even a merge function. It introduce and handyContextExceptionTraityou can use to implement your own implementation ofContextExceptionInterfacewithout having to inheritContextException
If you want to stick to the previous interface :
composer require "fab2s/context-exception" ^2
If you want to specifically install the php >=7.1.0 version, use:
composer require "fab2s/context-exception" ^1
If you want to specifically install the php 5.6/7.0 version, use:
composer require "fab2s/context-exception" ^0
Requirements
ContextException is tested against php 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2
License
ContextException is open-sourced software licensed under the MIT license.
fab2s/context-exception 适用场景与选型建议
fab2s/context-exception 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 646.99k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「exception」 「Context」 「interface」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fab2s/context-exception 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fab2s/context-exception 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fab2s/context-exception 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat Context for testing Symfony Api
Context support (request, session and application scope) for n2n framework.
Standalone CLI that generates codebase context (JSON + Markdown) for AI agents.
A library providing abstract implementations of various persistence layers based on JSON API relational resource concepts.
Error and Exception override and observers.
Error handler based on Booboo with HTML and JSON support
统计信息
- 总下载量: 646.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-30