diff --git a/composer.json b/composer.json index a3afeedc..da045a8a 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,11 @@ "require": { "php": ">=7.0", "maximebf/debugbar": "~1.14.0", - "illuminate/support": "5.5.*", - "symfony/debug": "~3.3", - "symfony/finder": "~3.3" + "illuminate/support": "5.5.x", + "illuminate/session": "5.5.x", + "symfony/debug": "^3.3", + "symfony/finder": "^3.3", + "illuminate/routing": "5.5.x" }, "autoload": { "psr-4": { diff --git a/config/debugbar.php b/config/debugbar.php index 0fb450fd..caaa646b 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -12,7 +12,7 @@ | */ - 'enabled' => env('DEBUGBAR_ENABLED', null), + 'enabled' => env('DEBUGBAR_ENABLED', env('APP_DEBUG', false)), /* |-------------------------------------------------------------------------- diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php deleted file mode 100644 index 84479d15..00000000 --- a/src/Console/PublishCommand.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @deprecated No longer needed because of the AssetController - */ -class PublishCommand extends Command -{ - /** - * The console command name. - * - * @var string - */ - protected $name = 'debugbar:publish'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Publish the Debugbar assets'; - - /** - * Execute the console command. - * - * @return void - */ - public function fire() - { - $this->info( - 'NOTICE: Since laravel-debugbar 1.7.x, publishing assets is no longer necessary. The assets in public/packages/barryvdh/laravel-debugbar and maximebf/php-debugbar can be safely removed.' - ); - } -} diff --git a/src/DataCollector/AuthCollector.php b/src/DataCollector/AuthCollector.php deleted file mode 100644 index 9f98160e..00000000 --- a/src/DataCollector/AuthCollector.php +++ /dev/null @@ -1,115 +0,0 @@ -auth = $auth; - } - - /** - * Set to show the users name/email - * @param bool $showName - */ - public function setShowName($showName) - { - $this->showName = (bool) $showName; - } - - /** - * @{inheritDoc} - */ - public function collect() - { - try { - $user = $this->auth->user(); - } catch (\Exception $e) { - $user = null; - } - return $this->getUserInformation($user); - } - - /** - * Get displayed user information - * @param \Illuminate\Auth\UserInterface $user - * @return array - */ - protected function getUserInformation($user = null) - { - // Defaults - if (is_null($user)) { - return [ - 'name' => 'Guest', - 'user' => ['guest' => true], - ]; - } - - // The default auth identifer is the ID number, which isn't all that - // useful. Try username and email. - $identifier = $user->getAuthIdentifier(); - if (is_numeric($identifier)) { - try { - if ($user->username) { - $identifier = $user->username; - } elseif ($user->email) { - $identifier = $user->email; - } - } catch (\Exception $e) { - } - } - - return [ - 'name' => $identifier, - 'user' => $user instanceof Arrayable ? $user->toArray() : $user, - ]; - } - - /** - * @{inheritDoc} - */ - public function getName() - { - return 'auth'; - } - - /** - * @{inheritDoc} - */ - public function getWidgets() - { - $widgets = [ - 'auth' => [ - 'icon' => 'lock', - 'widget' => 'PhpDebugBar.Widgets.VariableListWidget', - 'map' => 'auth.user', - 'default' => '{}' - ] - ]; - if ($this->showName) { - $widgets['auth.name'] = [ - 'icon' => 'user', - 'tooltip' => 'Auth status', - 'map' => 'auth.name', - 'default' => '', - ]; - } - return $widgets; - } -} diff --git a/src/DataCollector/EventCollector.php b/src/DataCollector/EventCollector.php index 75326b6d..757cd7ff 100644 --- a/src/DataCollector/EventCollector.php +++ b/src/DataCollector/EventCollector.php @@ -23,14 +23,6 @@ public function __construct($requestStartTime = null) public function onWildcardEvent($name = null, $data = []) { - // Pre-Laravel 5.4, using 'firing' to get the current event name. - if (method_exists($this->events, 'firing')) { - $name = $this->events->firing(); - - // Get the arguments passed to the event - $data = func_get_args(); - } - $params = $this->prepareParams($data); $time = microtime(true); diff --git a/src/DataCollector/GateCollector.php b/src/DataCollector/GateCollector.php index 8ed4bb59..529b8be9 100644 --- a/src/DataCollector/GateCollector.php +++ b/src/DataCollector/GateCollector.php @@ -22,9 +22,7 @@ public function __construct(Gate $gate) parent::__construct('gate'); $this->exporter = new ValueExporter(); - if (method_exists($gate, 'after')) { - $gate->after([$this, 'addCheck']); - } + $gate->after([$this, 'addCheck']); } public function addCheck(Authenticatable $user, $ability, $result, $arguments = []) diff --git a/src/DataCollector/MultiAuthCollector.php b/src/DataCollector/MultiAuthCollector.php index c25d7ba1..59722c76 100644 --- a/src/DataCollector/MultiAuthCollector.php +++ b/src/DataCollector/MultiAuthCollector.php @@ -2,28 +2,45 @@ namespace Barryvdh\Debugbar\DataCollector; +use DebugBar\DataCollector\DataCollector; +use DebugBar\DataCollector\Renderable; use Illuminate\Auth\SessionGuard; use Illuminate\Contracts\Auth\Guard; use Illuminate\Support\Str; +use Illuminate\Contracts\Support\Arrayable; + /** * Collector for Laravel's Auth provider */ -class MultiAuthCollector extends AuthCollector +class MultiAuthCollector extends DataCollector implements Renderable { /** @var array $guards */ protected $guards; + /** @var \Illuminate\Auth\AuthManager */ + protected $auth; + /** @var bool */ + protected $showName = false; + /** * @param \Illuminate\Auth\AuthManager $auth * @param array $guards */ public function __construct($auth, $guards) { - parent::__construct($auth); + $this->auth = $auth; $this->guards = $guards; } + /** + * Set to show the users name/email + * @param bool $showName + */ + public function setShowName($showName) + { + $this->showName = (bool) $showName; + } /** * @{inheritDoc} @@ -77,6 +94,49 @@ private function resolveUser(Guard $guard) return $guard->user(); } + /** + * Get displayed user information + * @param \Illuminate\Auth\UserInterface $user + * @return array + */ + protected function getUserInformation($user = null) + { + // Defaults + if (is_null($user)) { + return [ + 'name' => 'Guest', + 'user' => ['guest' => true], + ]; + } + + // The default auth identifer is the ID number, which isn't all that + // useful. Try username and email. + $identifier = $user->getAuthIdentifier(); + if (is_numeric($identifier)) { + try { + if ($user->username) { + $identifier = $user->username; + } elseif ($user->email) { + $identifier = $user->email; + } + } catch (\Exception $e) { + } + } + + return [ + 'name' => $identifier, + 'user' => $user instanceof Arrayable ? $user->toArray() : $user, + ]; + } + + /** + * @{inheritDoc} + */ + public function getName() + { + return 'auth'; + } + /** * @{inheritDoc} */ @@ -102,4 +162,5 @@ public function getWidgets() return $widgets; } + } diff --git a/src/Facade.php b/src/Facade.php index 678a2b3f..d2bbcf5e 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -7,6 +7,6 @@ class Facade extends \Illuminate\Support\Facades\Facade */ protected static function getFacadeAccessor() { - return 'debugbar'; + return LaravelDebugbar::class; } } diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index 1295abdc..1cdabc78 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -436,13 +436,8 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($ if ($this->shouldCollect('auth', false)) { try { - if($this->checkVersion('5.2')) { - // fix for compatibility with Laravel 5.2.* - $guards = array_keys($this->app['config']->get('auth.guards')); - $authCollector = new MultiAuthCollector($app['auth'], $guards); - } else { - $authCollector = new AuthCollector($app['auth']); - } + $guards = array_keys($this->app['config']->get('auth.guards')); + $authCollector = new MultiAuthCollector($app['auth'], $guards); $authCollector->setShowName( $this->app['config']->get('debugbar.options.auth.show_name') diff --git a/src/LumenServiceProvider.php b/src/LumenServiceProvider.php index c0e0c059..d28a4d2b 100644 --- a/src/LumenServiceProvider.php +++ b/src/LumenServiceProvider.php @@ -37,14 +37,6 @@ protected function registerMiddleware($middleware) $this->app->middleware([$middleware]); } - /** - * Check the App Debug status - */ - protected function checkAppDebug() - { - return env('APP_DEBUG'); - } - /** * Get the services provided by the provider. * diff --git a/src/Middleware/Debugbar.php b/src/Middleware/InjectDebugbar.php similarity index 99% rename from src/Middleware/Debugbar.php rename to src/Middleware/InjectDebugbar.php index edbc1277..5c3a8eff 100644 --- a/src/Middleware/Debugbar.php +++ b/src/Middleware/InjectDebugbar.php @@ -9,7 +9,7 @@ use Illuminate\Contracts\Debug\ExceptionHandler; use Symfony\Component\Debug\Exception\FatalThrowableError; -class Debugbar +class InjectDebugbar { /** * The App container diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0fabc7e3..185461c5 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -1,5 +1,9 @@ mergeConfigFrom($configPath, 'debugbar'); $this->app->alias( - 'DebugBar\DataFormatter\DataFormatter', - 'DebugBar\DataFormatter\DataFormatterInterface' + DataFormatter::class, + DataFormatterInterface::class ); - $this->app->singleton('debugbar', function ($app) { - $debugbar = new LaravelDebugbar($app); + $this->app->singleton(LaravelDebugbar::class, function () { + $debugbar = new LaravelDebugbar($this->app); - if ($app->bound(SessionManager::class)) { - $sessionManager = $app->make(SessionManager::class); + if ($this->app->bound(SessionManager::class)) { + $sessionManager = $this->app->make(SessionManager::class); $httpDriver = new SymfonyHttpDriver($sessionManager); $debugbar->setHttpDriver($httpDriver); } @@ -40,7 +44,7 @@ public function register() } ); - $this->app->alias('debugbar', 'Barryvdh\Debugbar\LaravelDebugbar'); + $this->app->alias(LaravelDebugbar::class, 'debugbar'); $this->app->singleton('command.debugbar.clear', function ($app) { @@ -63,12 +67,7 @@ public function boot() $configPath = __DIR__ . '/../config/debugbar.php'; $this->publishes([$configPath => $this->getConfigPath()], 'config'); - // If enabled is null, set from the app.debug value - $enabled = $this->app['config']->get('debugbar.enabled'); - - if (is_null($enabled)) { - $enabled = $this->checkAppDebug(); - } + $enabled = (bool) $this->app['config']->get('debugbar.enabled'); if (! $enabled) { return; @@ -111,7 +110,7 @@ public function boot() $debugbar->enable(); $debugbar->boot(); - $this->registerMiddleware('Barryvdh\Debugbar\Middleware\Debugbar'); + $this->registerMiddleware(InjectDebugbar::class); } /** @@ -151,18 +150,10 @@ protected function publishConfig($configPath) */ protected function registerMiddleware($middleware) { - $kernel = $this->app['Illuminate\Contracts\Http\Kernel']; + $kernel = $this->app[Kernel::class]; $kernel->pushMiddleware($middleware); } - /** - * Check the App Debug status - */ - protected function checkAppDebug() - { - return $this->app['config']->get('app.debug'); - } - /** * Get the services provided by the provider. * @@ -170,6 +161,6 @@ protected function checkAppDebug() */ public function provides() { - return ['debugbar', 'command.debugbar.clear']; + return ['debugbar', 'command.debugbar.clear', DataFormatterInterface::class, LaravelDebugbar::class]; } } diff --git a/src/SymfonyHttpDriver.php b/src/SymfonyHttpDriver.php index f1761996..088a5ab9 100644 --- a/src/SymfonyHttpDriver.php +++ b/src/SymfonyHttpDriver.php @@ -11,8 +11,9 @@ */ class SymfonyHttpDriver implements HttpDriverInterface { - /** @var \Symfony\Component\HttpFoundation\Session\Session|\Illuminate\Contracts\Session\Session|\Illuminate\Session\SessionManager */ + /** @var \Illuminate\Contracts\Session\Session|\Illuminate\Session\SessionManager */ protected $session; + /** @var \Symfony\Component\HttpFoundation\Response */ protected $response; @@ -40,6 +41,7 @@ public function isSessionStarted() if (!$this->session->isStarted()) { $this->session->start(); } + return $this->session->isStarted(); } @@ -48,14 +50,7 @@ public function isSessionStarted() */ public function setSessionValue($name, $value) { - // In Laravel 5.4 the session changed to use their own custom implementation - // instead of the one from Symfony. One of the changes was the set method - // that was changed to put. Here we check if we are using the new one. - if (method_exists($this->session, 'driver') && $this->session->driver() instanceof \Illuminate\Contracts\Session\Session) { - $this->session->put($name, $value); - return; - } - $this->session->set($name, $value); + $this->session->put($name, $value); } /** diff --git a/src/helpers.php b/src/helpers.php index 39636016..0cd00444 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -8,7 +8,7 @@ */ function debugbar() { - return app('debugbar'); + return app(\Barryvdh\Debugbar\LaravelDebugbar::class); } } @@ -21,7 +21,7 @@ function debugbar() */ function debug($value) { - $debugbar = app('debugbar'); + $debugbar = debugbar(); foreach (func_get_args() as $value) { $debugbar->addMessage($value, 'debug'); } @@ -37,7 +37,7 @@ function debug($value) */ function start_measure($name, $label = null) { - app('debugbar')->startMeasure($name, $label); + debugbar()->startMeasure($name, $label); } } @@ -49,7 +49,7 @@ function start_measure($name, $label = null) */ function stop_measure($name) { - app('debugbar')->stopMeasure($name); + debugbar()->stopMeasure($name); } } @@ -63,7 +63,7 @@ function stop_measure($name) */ function add_measure($label, $start, $end) { - app('debugbar')->addMeasure($label, $start, $end); + debugbar()->addMeasure($label, $start, $end); } } @@ -76,6 +76,6 @@ function add_measure($label, $start, $end) */ function measure($label, \Closure $closure) { - app('debugbar')->measure($label, $closure); + debugbar()->measure($label, $closure); } }