symfony/symfony — pull request #3706 by jmikola (2012-03-27 18:18:38+00:00)
Title: [HttpKernel] Throw exception if TimeDataCollector has no last event

This fixes an NPE I receive at times when enabling the WDT on production (on rare occasions I need to debug something live). I often find the following errors in the logs whenever the WDT is rendered:

> PHP Fatal error: Call to a member function getOrigin() on a non-object in /data/site/vendor/symfony/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php on line 78

My mistake is enabled profiling and the WDT bundle but forgetting to flip the debugging kernel argument to `true`. This prevents the TraceableEventDispatcher from being used, which in turn means that no events are ever set on the TimeDataCollector. Adding an `isset()` check and throwing an exception with a helpful error message seems helpful here. No we'll get:

> PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The last event is not available. Are you sure that debugging is enabled in the kernel?' in /data/site/vendor/symfony/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php:78

I'm not encouraging anyone to use WDT on production here, but I think we'd do well to avoid any change of NPE's in the code.