承接 jaspur/localized-exceptions 相关项目开发

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

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

jaspur/localized-exceptions

最新稳定版本:v1.5.1

Composer 安装命令:

composer require jaspur/localized-exceptions

包简介

A custom exception handler package for Laravel that provides localized error messages for HTTP exceptions.

README 文档

README

A custom exception handler package for Laravel that provides localized error messages for HTTP exceptions.

Requirements 📋

To use this package, you need:

  • PHP: ^8.2
  • Laravel: ^11.0

Ensure you have the correct versions installed to avoid compatibility issues.

Installation 📦

To install the package, use Composer:

composer require jaspur/localized-exceptions

Service Provider ⚙️

After installation, the service provider will automatically be registered. If you need to manually register it, add the following line to the providers array in your config/app.php:

Jaspur\LocalizedExceptions\LocalizedExceptionsServiceProvider::class,

How It Works 🛠️

This package overrides Laravel's default exception handling to provide localized messages for various HTTP exceptions. It does this by mapping common HTTP exceptions to their respective status codes and returning appropriate localized messages.

Exception Mapping

The package maps the following exceptions to their respective HTTP status codes:

  • 401: Authentication Failed
  • 403: Authorization Denied
  • 404: Resource Not Found
  • 405: Method Not Allowed
  • 406: Not Acceptable
  • 409: Conflict
  • 410: Gone
  • 411: Length Required
  • 412: Precondition Failed
  • 428: Precondition Required
  • 422: Unprocessable Entity
  • 423: Locked
  • 429: Too Many Requests
  • 503: Service Unavailable
  • 415: Unsupported Media Type

When an exception occurs, the package checks if it matches one of the mapped exceptions and returns a localized message accordingly.

Validation Errors 📝

The package also handles validation exceptions, returning a list of validation errors along with a localized message.

Localization 🌍

You can customize the error messages by creating language files in the resources/lang/vendor/jaspur directory. The package loads translations from the resources/lang directory.

Publishing Translations 📢

If you want to customize the translation files, you can publish them using:

php artisan vendor:publish --tag=lang

This will copy the language files to resources/lang/vendor/jaspur.

Contributing 🤝

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.

License 📝

This package is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-15