artex/exceptions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

artex/exceptions

Composer 安装命令:

composer require artex/exceptions

包简介

Artex Software's standard PHP exception library for consistent error handling.

README 文档

README

Artex Agency Logo
ARTEX EXCEPTIONS
Custom PHP Exceptions Library

A simple, consistent library for creating and managing exceptions in PHP projects.

The Artex Standard Exceptions Library provides a basic, flexible way to handle exceptions in your PHP applications. Built to align with good practices, it simplifies exception management and adds a touch of consistency to your projects.

While this library isn't aiming to reinvent the wheel, it serves as a standard tool for PHP projects under the Artex Software ecosystem, ensuring reliability and clarity for developers.

 

Key Features

  • Custom Exceptions: Extendable exceptions for common use cases (e.g., runtime errors, validation errors, database errors).
  • PSR-4 Compliant: Easy integration into modern PHP projects.
  • Contextual Data: Include optional context information for better debugging.
  • Extensibility: Provides a foundation to build project-specific exceptions.

 

 

Installation

composer "require artex/exceptions"

 

Usage

Basic Example

use Artex\Exceptions\ArtexRuntimeException;

try {
    throw new ArtexRuntimeException("Something went wrong!", 500);
} catch (ArtexRuntimeException $e) {
    echo $e->getMessage();
}

Adding Context to Exceptions

use Artex\Exceptions\ArtexException;

try {
    throw new ArtexException(
        "Validation failed!",
        422,
        ['field' => 'email', 'error' => 'Invalid format']
    );
} catch (ArtexException $e) {
    // Access additional context
    var_dump($e->getContext());
}

Extending Exceptions

You can easily extend any Artex exception to create project-specific exceptions:

namespace MyApp\Exceptions;

use Artex\Exceptions\ArtexRuntimeException;

class CustomException extends ArtexRuntimeException
{
    public function __construct(string $message = "", int $code = 0, array $context = [])
    {
        parent::__construct($message, $code, $context);
    }
}

Logging Exceptions

The library can seamlessly log exceptions if a PSR-3 compatible logger is available:

use Artex\Exceptions\ArtexRuntimeException;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// Set up a PSR-3 logger
$logger = new Logger('example');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));

// Register the logger
ArtexRuntimeException::registerLogger($logger);

try {
    throw new ArtexRuntimeException("Critical failure", 500);
} catch (ArtexRuntimeException $e) {
    // Exception is automatically logged
    echo "Exception logged: " . $e->getMessage();
}

 

Available Exceptions

The library ships with the following prebuilt exceptions:

Exception Class Description
ArtexException Base exception class for all custom exceptions.
ArtexRuntimeException For runtime errors.
ArtexInvalidArgumentException For invalid arguments passed to functions.
ArtexLogicException For logical errors in the application.
ArtexUnexpectedValueException For unexpected values in operations.
ValidationException For validation-specific errors.
DatabaseException For database-related errors.
FileException For file-related errors.

 

Advanced Usage

Extending Exceptions

You can easily extend any Artex exception to create project-specific exceptions:

namespace MyApp\Exceptions;

use Artex\Exceptions\ArtexRuntimeException;

class CustomException extends ArtexRuntimeException
{
    public function __construct(string $message = "", int $code = 0, array $context = [])
    {
        parent::__construct($message, $code, $context);
    }
}

 

Requirements

  • PHP 8.0 or higher

 

 

Contributing

We welcome contributions to the Artex Standard Exceptions Library! If you have an idea, feature request, or find a bug, please open an issue or submit a pull request.

 

LICENSE

This software is distributed under the Apache 2.0 License, granting you the freedom to use, modify, and distribute the software, provided you adhere to the terms outlined in the license.

See the LICENSE file for details.


FOLLOW US

         

COPYRIGHT © 2025 ARTEX AGENCY INC.

artex/exceptions 适用场景与选型建议

artex/exceptions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「exceptions」 「standard」 「error-handling」 「php-library」 「custom-exceptions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 artex/exceptions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 artex/exceptions 我们能提供哪些服务?
定制开发 / 二次开发

基于 artex/exceptions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-01-26