定制 szczyglis/extended-dump-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

szczyglis/extended-dump-bundle

Composer 安装命令:

composer require szczyglis/extended-dump-bundle

包简介

An extension that enhances the debugging capabilities of Symfony 4, 5, and 6 frameworks.

README 文档

README

Release: 1.2.2 | build: 2024.08.26 | PHP: ^7.2.5|^8.0

Supported Versions of Symfony:

4.4+, 5.x, 6.x

Extended Dump Bundle

The Extended Dump Bundle is an extension for the Symfony framework. It enhances the dump function of the framework with new features. It attaches a new dockable window to the application that displays debug information collected from all dumps made using the new method. This centralized view allows quick access to dumped objects, variables, and system-related information. The bundle introduces a new global function, xdump, enabling you to use Extended Dump anywhere in your application code.

How to install

composer require szczyglis/extended-dump-bundle

Features

  • New Configurable Window: Groups dumped objects in an organized manner.
  • New Global Function (xdump): Facilitates quick debugging.
  • Centralized Dumped Objects: Consolidates all dumped objects in one easily accessible place.
  • Comprehensive Information Display: Shows useful debug information such as the current user, request and response objects, variables from $_GET, $_POST, $_SESSION, $_COOKIE, $_ENV, and $_SERVER, as well as information about PHP and its modules. It also includes lists of Doctrine entities and repositories with their properties and methods, parameters, and more.
  • Event Extensibility: Extend functionality using events.
  • Customizable Layout: Modify the appearance using Twig.
  • Fully Configurable: Adjust settings to fit your needs.

How it works

Appearance After Installation

After installation, a small icon will appear in the lower right corner of the page. Clicking this icon will open the debugger window.

trigger _cornerpng

The debug window is divided into three sections:

  • app: This section contains all variables collected using the xdump function.
  • event: Displays debug information added using your own Event Subscriber.
  • system: Shows the most useful and handy system information.

divide

The New xdump Global Function

The extension adds a new global function to the framework called xdump. This function allows you to use Extended Dump from anywhere in your code. It works similarly to the standard dump function, but the debugged objects are collectively sent to the Extended Dump window.

Example of use:

    /**
     * @Route("/", name="index")
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $foo1 = 'bar1';
        $foo2 = 'bar2';
        $foo3 = 'bar3';

        xdump($foo1, $foo2, $foo3);

        return $this->render('index.html.twig');
    }

Adding the above code anywhere in the application, whether in controllers or services, will include the app section in the debugger and display the dumped object (or objects) there.

Example of use:

<?php
// src/Controller/IndexController.php

namespace App\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

/**
 * Class IndexController
 * @package App\Controller
 */
class IndexController extends AbstractController
{
    /**
     * @Route("/", name="index")
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $foo1 = 'bar1';
        $foo2 = 'bar2';

        xdump($foo1, $foo2); // you can put one or multiple arguments

        return $this->render('index.html.twig');
    }
}

Result of the action:

vars

Extension for Twig

You can use Extended Dump in Twig templates thanks to the included Twig extension. To utilize it in a template, simply use the xdump function within the Twig template:

# templates/template.html.twig

{% set foo = "I'm in Twig!" %}
{% set bar = "I'm in Twig too!" %}

{{ xdump(foo, bar) }} # you can dump multiple objects at once also in Twig

Result of the action:

twig

Extending Extended Dump with EventSubscriber or EventListener

You can enhance the debugger window with your own elements that will be permanently displayed. This allows you to, for example, quickly preview the status of selected objects in the application. To achieve this, create a new EventSubscriber or EventListener and handle the Szczyglis\ExtendedDumpBundle\Event\RenderEvent.

Example of use:

<?php
// src/EventSubscriber/CustomDumpSubscriber.php

namespace App\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Szczyglis\ExtendedDumpBundle\Event\ExtendedDumpEvents;
use Szczyglis\ExtendedDumpBundle\Event\RenderEvent;

class CustomDumpSubscriber implements EventSubscriberInterface
{
    /**
     * @param RenderEvent $event
     */
    public function onRender(RenderEvent $event)
    {  
        $foo = "I want to be dumped every time!";

        $event->add($foo, "I'm Event object");
    }

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            ExtendedDumpEvents::RENDER => 'onRender',
        ];
    }
}

The above code will add a new section to the debugger window, displaying the following elements:

event

You can add multiple items:

class CustomDumpSubscriber implements EventSubscriberInterface
{
    /**
     * @param RenderEvent $event
     */
    public function onRender(RenderEvent $event)
    {  
        $foo1 = "bar1";
        $foo2 = "bar2";

        $event->add($foo1, "Optional label to display");
        $event->add($foo2);
    }   

Customizing Extended Dump

You can fully customize the window's appearance, CSS, and JS by overriding the templates located in ./src/Resources/views within your own templates directory.

Built-in system components

Request / Response Component

This section displays the current Request and Response objects:

sys_request

Doctrine Component

This section displays a list of all entities used in the application, including the names and types of defined fields, methods from the class of the given Entity, and methods available in the repositories:

sys_doctrine

Request Variables Component

This section displays the contents of $_GET, $_POST, $_SESSION, and $_COOKIE:

sys_vars

User Component

This section displays the object representing the currently logged-in user:

sys_user

Server Component

This section displays useful information about the server, such as the PHP version, the versions of loaded modules, and the contents of $_ENV and $_SERVER:

sys_server

Parameters Component

This section displays the values of all parameters defined in the application:

sys_params

Configuration

In config/packages/extended_dump.yaml, you can define configuration settings and modify how sections are displayed.

The default appearance of extended_dump.yaml:

# config/packages/extended_dump.yaml
extended_dump:
  env: [dev] # Array with enabled environments, if empty then only DEV environment will be enabled

  display:
    enabled: true # Enable/disable Xdump dockable window
    dump:
        max_depth: 1 # Var Dumper max depth config value
        max_string_depth: 160 # Var Dumper max max string depth config value
        max_items: -1 # Var Cloner max items config value
    sections:
      app: 
        enabled: true # Enable/disable App section
        collapsed: false # Collapse App section at start
      event: 
        enabled: true # Enable/disable Event section
        collapsed: false # Collapse Event section at start
      system: 
        enabled: true # Enable/disable System section
        collapsed: false # Collapse System section at start
        items:
            request: true # Enable/disable Request dump
            response: true # Enable/disable Response dump
            session: true # Enable/disable Session dump
            get: true # Enable/disable $_GET dump
            post: true # Enable/disable $_POST dump
            cookies: true # Enable/disable Cookies dump
            user: true # Enable/disable User dump
            server: true # Enable/disable Server dump
            doctrine: true # Enable/disable Doctrine dump
            parameters: true # Enable/disable Parameters dump

An example config template is included in the package: ./src/Resources/config/extended_dump.yaml.

Bundle Compatibility

This bundle works with the following versions of the Symfony framework:

Symfony 4.4+:

symfony4

Symfony 5.x:

symfony5

Symfony 6.x:

symfony6

Changelog

1.0.13 - Published first release. (2022-04-25)

1.0.36 - Added support for multiple arguments in xdump(), moved user debug to the bottom of the debugger window, added version info, added counters for dumped items, and some other features. (2022-04-29)

1.1.8 - Added Doctrine entities and repositories debugger, added parameters dumper, increased configuration options, and made other small improvements. (2022-04-29)

1.2.0 - Added session existence check, added Content Security Policy nonce append. (2023-11-05)

1.2.1 - Added style nonce append. (2023-11-21)

1.2.2 - Improved documentation. (2024-08-26)

Extended Dump is free to use, but if you like it, you can support my work by buying me a coffee ;)

https://www.buymeacoffee.com/szczyglis

Enjoy!

MIT License | 2022 Marcin 'szczyglis' Szczygliński

https://github.com/szczyglis-dev/extended-dump-bundle

https://szczyglis.dev

Contact: szczyglis@protonmail.com

szczyglis/extended-dump-bundle 适用场景与选型建议

szczyglis/extended-dump-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.74k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 szczyglis/extended-dump-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-25