-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
IDEA: Fruitcake debugbar helper for production environments #1987
Copy link
Copy link
Open
Description
I opened it as an issue because there's no discussions tab
fruitcake/laravel-debugbar is for debug environments, but there should be an option to leave code as measurements or informational messages.
I'm not sure if I'm misunderstanding the usage. If I accidentally leave debugbar()->startMeasure or any other method and send it to production where vendor laravel-debugbar doesn't exist, it will give me an error.
maybe there should be a package used as a fallback in production(fruitcake/laravel-debugbar-helper, fruitcake/laravel-debugbar-fallback, other name).
PoC example:
// src\LaravelDebugbarHelper.php
namespace Fruitcake\LaravelDebugbarHelper {
if( !class_exists(\Fruitcake\LaravelDebugbar\LaravelDebugbar::class) ) {
// dump helper class
class LaravelDebugbarHelper{
private static $_INSTANCE=null;
public static function instance(){
if(!self::$_INSTANCE)
self::$_INSTANCE=new static();
return self::$_INSTANCE;
}
public function __call($name,$args) {
return static::__callStatic($name,$args);
}
public static function __callStatic($name,$args) {
if($name=='measure' && is_callable($args[1]??null))
$args[1](); // run the closure on measure
return null;
}
}
// alias dump helper class as the real class name
class_alias(\Fruitcake\LaravelDebugbarHelper\LaravelDebugbarHelper::class,\Fruitcake\LaravelDebugbar\LaravelDebugbar::class);
class_alias(\Fruitcake\LaravelDebugbarHelper\LaravelDebugbarHelper::class,\Fruitcake\LaravelDebugbar\Facades\Debugbar::class);
}
}
// src\helpers.php
namespace {
if( class_exists(\Fruitcake\LaravelDebugbarHelper\LaravelDebugbarHelper::class) ) {
if(!function_exists('debugbar')){
function debugbar() : \Fruitcake\LaravelDebugbar\LaravelDebugbar{
return \Fruitcake\LaravelDebugbarHelper\LaravelDebugbarHelper::instance();
}
}
if(!function_exists('debug')){
function debug(): void {}
}
}
}The same could also exist for php-debugbar/php-debugbar
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels