承接 raffaelecarelle/php-error-insight-symfony-bundle 相关项目开发

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

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

raffaelecarelle/php-error-insight-symfony-bundle

Composer 安装命令:

composer require raffaelecarelle/php-error-insight-symfony-bundle

包简介

Symfony Bundle for PHP Error Insight - AI-powered error handling for Symfony applications

README 文档

README

A Symfony bundle that integrates PHP Error Insight to provide AI‑assisted explanations and richer error pages for HTTP and Console errors.

Screenshots:

screenview1.png screenview2.png terminal.png

Features

  • 🔍 AI‑assisted error explanations (optional, multiple backends)
  • 🎨 Enhanced HTML/text/JSON rendering provided by the core library
  • ⚡ Seamless Symfony integration for HTTP exceptions and Console errors
  • 🔧 Highly configurable: choose backend, model, output, verbosity and paths

Requirements

  • PHP >= 8.1
  • Symfony >= 5.4
  • Composer

Installation

Install the bundle (typically in dev/test):

composer require --dev raffaelecarelle/php-error-insight-symfony-bundle

Configure Symfony Runtime error handler (required)

To enable the bundle's PHP error handling, you must tell Symfony Runtime to use this bundle's error handler. Add the following to your application's composer.json under the extra.runtime section, then regenerate the autoloader:

{
  "extra": {
    "runtime": {
      "error_handler": "PhpErrorInsightBundle\\Handler\\ErrorHandler"
    }
  }
}

After editing composer.json, run:

composer dump-autoload

Notes:

  • The configuration must live in your application root composer.json (not in a dependency).
  • This requires the symfony/runtime Composer plugin to be allowed in your project (see config.allow-plugins["symfony/runtime"]).

Configuration

The bundle exposes a single configuration root: php_error_insight.

Basic configuration

Create or update config/packages/php_error_insight.yaml:

php_error_insight:
    enabled: true
    backend: 'none'   # or: local, api, openai, anthropic, google, gemini
    language: 'en'
    output: 'auto'    # or: html, text, json

Advanced configuration

php_error_insight:
    enabled: true
    backend: 'local'
    model: 'llama3:instruct'
    api_url: 'http://localhost:11434'
    language: 'en'
    output: 'html'
    verbose: false

    # Absolute path of your project inside the running environment
    # (e.g. "/app" inside a Docker container)
    project_root: '%kernel.project_dir%'

    # Optional: absolute path of the project on the host machine to map
    # container paths to host paths when rendering links
    host_root: '/absolute/path/on/host'

    # Optional: custom HTML template supported by the core library
    template: null

    # Optional: editor URL pattern, e.g. "phpstorm://open?file=%file%&line=%line%"
    editor_url: null

    # API key for external backends (openai, anthropic, google/gemini, custom api)
    api_key: null

Notes:

  • backend supports: none, local, api, openai, anthropic, google, gemini.
  • When using local backends (e.g. Ollama), set api_url to your local endpoint.
  • Use project_root and optionally host_root to make editor links and paths resolve correctly across containers/hosts.
  • editor_url placeholders supported by the core renderer are typically %file% and %line%.

Environment variables

You can configure via environment variables as well (e.g. in .env.local):

PHP_ERROR_INSIGHT_ENABLED=true
PHP_ERROR_INSIGHT_BACKEND=local
PHP_ERROR_INSIGHT_MODEL=llama3:instruct
PHP_ERROR_INSIGHT_API_URL=http://localhost:11434
PHP_ERROR_INSIGHT_LANG=en
PHP_ERROR_INSIGHT_OUTPUT=html
PHP_ERROR_INSIGHT_VERBOSE=false
PHP_ERROR_INSIGHT_PROJECT_ROOT=/app
PHP_ERROR_INSIGHT_HOST_ROOT=/Users/you/Projects/acme
PHP_ERROR_INSIGHT_EDITOR="phpstorm://open?file=%file%&line=%line%"
PHP_ERROR_INSIGHT_API_KEY=your-key-if-needed

Backend configuration examples

1) Local AI (Ollama)

php_error_insight:
    backend: 'local'
    model: 'llama3:instruct'
    api_url: 'http://localhost:11434'

2) OpenAI

php_error_insight:
    backend: 'openai'
    model: 'gpt-4o-mini'
    api_key: 'sk-your-openai-api-key'

3) Anthropic Claude

php_error_insight:
    backend: 'anthropic'
    model: 'claude-3-5-sonnet-20240620'
    api_key: 'your-anthropic-api-key'

4) Google (Generative AI)

php_error_insight:
    backend: 'google'
    model: 'gemini-1.5-flash'
    api_key: 'your-google-api-key'

5) Gemini (alias backend)

php_error_insight:
    backend: 'gemini'
    model: 'gemini-1.5-flash'
    api_key: 'your-google-api-key'

Usage

HTTP exceptions

The bundle registers a high‑priority listener for kernel.exception. When enabled is true, exceptions are rendered using PHP Error Insight’s renderer. If rendering fails or produces empty output, Symfony’s default error handling is used.

Console errors

A console event subscriber listens to ConsoleEvents::ERROR and, when enabled, prints the rendered output to the console. If rendering fails or produces empty output, normal console error output is preserved.

Programmatic usage

You can call the service directly:

use PhpErrorInsightBundle\Service\ErrorInsightService;

final class YourController
{
    public function __construct(private ErrorInsightService $errorInsightService) {}

    public function someAction(): Response
    {
        try {
            // ... your code
        } catch (\Throwable $e) {
            if ($this->errorInsightService->isEnabled()) {
                $html = $this->errorInsightService->renderException($e);
                // do something with $html (log, email, custom response, ...)
            }

            throw $e; // keep default handling flow
        }
    }
}

Service IDs:

  • PhpErrorInsightBundle\Service\ErrorInsightService (autowired)
  • Alias: php_error_insight.service

How it works

  1. Exception interception (HTTP) via kernel.exception listener
  2. Error interception (Console) via ConsoleEvents::ERROR subscriber
  3. The bundle builds a Config and delegates rendering to the core library
  4. Graceful fallback to Symfony’s default error handling when needed

Environment considerations

It’s recommended to enable the bundle only in dev and/or test. You control this through:

  • config/bundles.php (register the bundle for specific environments)
  • php_error_insight.enabled setting per environment config

Customization

  • template: path to a custom HTML template supported by the core renderer
  • editor_url: URL pattern to open files in your editor (e.g. PhpStorm)
  • project_root / host_root: map paths correctly between container and host

Troubleshooting

  • Ensure the bundle is registered for the environment you’re using
  • Verify php_error_insight.enabled is true for that environment
  • For local backends, ensure your local service (e.g. Ollama) is running
  • For API backends, verify api_key and reachability of api_url if applicable
  • Check your logs for errors from the renderer or backend

Development

Run tests:

composer install
composer test

Quality tools:

composer quality
composer fix-all

License

This bundle is licensed under the GPL-3.0-or-later license. See LICENSE for details.

Related

raffaelecarelle/php-error-insight-symfony-bundle 适用场景与选型建议

raffaelecarelle/php-error-insight-symfony-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 698 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 raffaelecarelle/php-error-insight-symfony-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-09-19