While this package is Symfony-specific, Laravel developers using Symfony components (e.g., via symfony/doctrine-bundle in hybrid setups) can adapt it. Here’s how to start:
Install the Bundle:
composer require sidus/doctrine-debug-bundle "~1.0"
Enable in config/bundles.php (Symfony 4+):
return [
// ...
Sidus\DoctrineDebugBundle\SidusDoctrineDebugBundle::class => ['dev' => true, 'test' => true],
];
Clear Cache:
php bin/console cache:clear
Trigger a Query:
/_profiler/ in your browser (Symfony Profiler must be enabled).Inspect the Profiler:
Note: This package is Symfony-only. For Laravel, consider alternatives like:
doctrine:query-log).Debugging N+1 Queries:
UserRepository::findWithPosts() reveals the culprit.Legacy Code Audits:
User::getOrders() method triggering 20+ queries).OrderController::index() → OrderService::fetchAll() → EntityManager::createQuery().Performance Profiling:
CheckoutController::process() as the bottleneck.CI/CD Debugging:
test environments to debug failing test queries (e.g., php bin/console test --env=test).WHERE clause becomes obvious via the stack trace.Symfony Flex Projects:
symfony/profiler-pack is installed (required for the Profiler UI).config/packages/dev/_profiler.php if not auto-loaded.Doctrine Event Listeners:
onQuery event. If you have custom listeners, ensure they don’t interfere with stack trace collection.Hybrid Laravel/Symfony Apps:
spatie/laravel-symfony-components), enable the bundle in a microkernel or separate Symfony app.Customizing Stack Traces:
SidusDoctrineDebugBundle\DataCollector\DoctrineDebugDataCollector and redefining collect().User::findByRole() query./_profiler/ → Doctrine tab.UserController::show() → UserRepository::findByRole() → EntityManager::createQuery()
UserRepository::findByRole() (e.g., add DISTINCT, use a join, or cache results).Profiler Not Enabled:
WebProfilerBundle is installed and enabled in dev/test environments.
composer require symfony/profiler-pack
Doctrine DBAL vs. ORM:
doctrine:query-log for DBAL.Xdebug Dependency (Pre-v1.0.2):
~1.0 (Xdebug is no longer required).Symfony Version Mismatch:
~0.9 (if available) or fork the bundle.Performance in CI:
test environments by setting:
# config/packages/sidus_doctrine_debug.yaml
sidus_doctrine_debug:
enabled: false
Check Bundle Loading:
php bin/console debug:container sidus_doctrine_debug
bundles.php or AppKernel.php.Enable Verbose Logging:
php bin/console debug:config sidus_doctrine_debug
var/log/dev.log.Inspect Profiler Data:
doctrine collector. Use:
$profiler = $this->get('profiler');
$data = $profiler->load('doctrine')->getData();
Custom Stack Trace Formatting:
DoctrineDebugDataCollector to modify how stack traces are displayed:
// src/EventListener/CustomDoctrineDebugListener.php
use Sidus\DoctrineDebugBundle\DataCollector\DoctrineDebugDataCollector;
class CustomDoctrineDebugListener extends DoctrineDebugDataCollector
{
public function collect()
{
$traces = parent::collect();
// Modify $traces['queries'] here (e.g., truncate, highlight files).
return $traces;
}
}
Filtering Queries:
isQueryRelevant() method in the collector.Adding Metadata:
QueryData class.No Runtime Config:
Environment-Specific Enforcement:
prod, but explicitly set:
# config/packages/dev/sidus_doctrine_debug.yaml
sidus_doctrine_debug:
enabled: true
# config/packages/prod/sidus_doctrine_debug.yaml
sidus_doctrine_debug:
enabled: false
Query Annotations:
// SLOW QUERY above the triggering method).Automated Query Audits:
Integration with Blackfire:
Note: For Laravel, consider forking this bundle to adapt it for Laravel’s ecosystem (e.g., using Laravel Debugbar instead of Symfony Profiler). Alternatively, use Doctrine’s built-in logging or Telescope for similar functionality.
How can I help you explore Laravel packages today?