Skip to content

Commit

Permalink
fix route tracy.bar not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Mar 13, 2019
1 parent d0a1e5f commit b61c619
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
10 changes: 3 additions & 7 deletions src/DebuggerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,9 @@ protected function renderBuffer(callable $callback)
*/
protected function replacePath($content)
{
static $path;

if (is_null($path) === true) {
$path = is_null($this->urlGenerator) === false
? $this->urlGenerator->route(Arr::get($this->config, 'route.as').'bar')
: null;
}
$path = is_null($this->urlGenerator) === false
? $this->urlGenerator->route(Arr::get($this->config, 'route.as').'bar')
: null;

return is_null($path) === false
? str_replace('?_tracy_bar', $path.'?_tracy_bar', $content)
Expand Down
17 changes: 9 additions & 8 deletions src/LaravelTracyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ class LaravelTracyServiceProvider extends ServiceProvider
*/
public function boot(Kernel $kernel, View $view, Router $router)
{
$view->getEngineResolver()
->resolve('blade')
->getCompiler()
->directive('bdump', function ($expression) {
return "<?php \Tracy\Debugger::barDump({$expression}); ?>";
});
$config = $this->app['config']['tracy'];
$this->handleRoutes($router, Arr::get($config, 'route', []));

if ($this->app->runningInConsole() === true) {
$this->publishes([__DIR__.'/../config/tracy.php' => config_path('tracy.php')], 'config');

return;
}

$config = $this->app['config']['tracy'];
$view->getEngineResolver()
->resolve('blade')
->getCompiler()
->directive('bdump', function ($expression) {
return "<?php \Tracy\Debugger::barDump({$expression}); ?>";
});

$enabled = Arr::get($config, 'enabled', true) === true;
if ($enabled === false) {
return;
Expand All @@ -69,7 +71,6 @@ public function boot(Kernel $kernel, View $view, Router $router)

$showBar = Arr::get($config, 'showBar', true);
if ($showBar === true) {
$this->handleRoutes($router, Arr::get($config, 'route', []));
$kernel->prependMiddleware(RenderBar::class);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/DebuggerManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function testReplacePath()
$urlGenerator = m::mock('Illuminate\Contracts\Routing\UrlGenerator')
);

$urlGenerator->shouldReceive('route')->once()->andReturn($root = 'foo');
$urlGenerator->shouldReceive('route')->twice()->andReturn($root = 'foo');

$bar->shouldReceive('renderLoader')->once()->andReturnUsing(function () {
echo '<script src="?_tracy_bar=foo" async></script>';
Expand Down
20 changes: 10 additions & 10 deletions tests/LaravelTracyServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ public function testBootRunningInConsole()
$app = m::mock('Illuminate\Contracts\Foundation\Application, ArrayAccess')
);

$app->shouldReceive('offsetGet')->once()->with('config')->andReturn($config = [
'tracy' => [
'panels' => [
'terminal' => true,
],
],
]);

$app->shouldReceive('routesAreCached')->once()->andReturn(true);

$app->shouldReceive('runningInConsole')->once()->andReturn(true);

$view = m::mock('Illuminate\Contracts\View\Factory');
$view
->shouldReceive('getEngineResolver')->once()->andReturnSelf()
->shouldReceive('resolve')->once()->with('blade')->andReturnSelf()
->shouldReceive('getCompiler')->once()->andReturnSelf()
->shouldReceive('directive')->once()->with('bdump', m::on(function ($closure) {
$expression = '$foo';
$compiled = $closure($expression);

return $compiled === "<?php \Tracy\Debugger::barDump({$expression}); ?>";
}));

$serviceProvider->boot(
$kernel = m::mock('Illuminate\Contracts\Http\Kernel'),
Expand Down

0 comments on commit b61c619

Please sign in to comment.