Skip to content

nowo-tech/ConsoleDebugBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Console Debug Bundle

CI Packagist Version Packagist Downloads License PHP Symfony GitHub stars Coverage

Found this useful? Install from Packagist · Give it a star on GitHub so more developers can find it.

Console Debug Bundle — Production-safe browser console debugging with cdbg(), similar in spirit to Symfony's dd() but non-blocking: it collects file, line, and variable data server-side and injects a <script> that prints grouped console.log() output for authorized users only. Tested on Symfony 7.4, 8.0, and 8.1 (also compatible with Symfony 6.x and 7.0–7.3) · PHP 8.1+ (Symfony 8.x requires PHP 8.4+).

FrankenPHP Friendly Worker Mode

This bundle is FrankenPHP worker mode friendly.

Features

  • cdbg() helper — Drop-in debug calls anywhere in PHP; execution continues (no dump-and-die).
  • Role-gated — Only authenticated users with configured roles see output, even in production.
  • Rich context — Captures caller file, line, optional label, and normalized variable payloads.
  • HTML injection — Appends a JSON payload and runner script before </body> on HTML responses.
  • Custom gate service — Replace or extend authorization with route/query-param logic.

Installation

composer require nowo-tech/console-debug-bundle

With Symfony Flex, the recipe registers the bundle and adds config. Without Flex, see docs/INSTALLATION.md.

Manual registration in config/bundles.php:

return [
  // ...
  Nowo\ConsoleDebugBundle\NowoConsoleDebugBundle::class => ['all' => true],
];

Grant a debug role to trusted users:

security:
  role_hierarchy:
    ROLE_CONSOLE_DEBUG: ROLE_USER

Configuration

nowo_console_debug:
  enabled: true
  roles:
    - ROLE_CONSOLE_DEBUG
  console_method: log
  label_prefix: '[cdbg]'
  shorten_paths: true
  query_param: console_debug
  # gate_service: App\ConsoleDebug\AppConsoleDebugGate

Usage

use function Nowo\ConsoleDebugBundle\cdbg;

public function show(Request $request): Response
{
    cdbg('items snapshot', $items, $request->query->all());

    return $this->render('page.html.twig', ['items' => $items]);
}

Open DevTools → Console on the rendered HTML page. Each cdbg() call appears as an expanded group with file, line, and values.

Twig (requires twig/twig)

Same behaviour as Symfony's native dump, but output goes to the browser console:

{# full Twig context (macros/templates excluded), like {% dump %} #}
{% cdbg %}

{# one or more variables, like {{ dump(user) }} #}
{{ cdbg(user) }}
{% cdbg user, items %}

When called empty, the label is twig context and the template name/line is used as the source location.

Documentation

Additional documentation

Requirements

  • PHP >=8.1 (<8.6); Symfony 8.0 and 8.1 require PHP 8.4+
  • Symfony 7.4, 8.0, or 8.1 (minimum supported minors; also works on Symfony 6.x and 7.0–7.3 via composer.json constraints)
  • symfony/security-bundle (or equivalent) in your application for role-based gates

Development

make up
make install
make test
make cs-check
make phpstan
make release-check

Demo

  • demo/symfony7 — Symfony 7.4, host port 8010 by default (PORT in .env)
  • demo/symfony8 — Symfony 8.1 (PHP 8.5), host port 8011 by default

Each demo runs FrankenPHP + Caddy in Docker (FRANKENPHP_MODE=worker by default). Login as debugger / debug and visit /debug to see cdbg() in the browser console. See docs/DEMO-FRANKENPHP.md.

Global demo commands: make -C demo help (e.g. make -C demo up-symfony8).

Tests and coverage

  • Tests: PHPUnit (PHP)
  • PHP: 100%

License and author

MIT · Nowo.tech · Héctor Franco Aceituno

About

Production-safe browser console debugging with cdbg(), similar in spirit to Symfony's dd() but non-blocking: it collects file, line, and variable data server-side and injects a `<script>` that prints grouped `console.log()` output for authorized users only.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages