diff --git a/config/zfsnapphpdebugbar.config.php b/config/zfsnapphpdebugbar.config.php index 73797dd..97c094b 100644 --- a/config/zfsnapphpdebugbar.config.php +++ b/config/zfsnapphpdebugbar.config.php @@ -4,6 +4,8 @@ 'php-debug-bar' => [ 'view' => [ 'custom-style-path' => 'zf-snap-php-debug-bar.css', + 'debugbar-resources' => __DIR__.'/../../../maximebf/debugbar/src/DebugBar/Resources/', + 'custom-resources' => __DIR__.'/../assets/', ], 'enabled' => true, 'auto-append-assets' => true, @@ -26,8 +28,8 @@ ], ], 'controllers' => [ - 'invokables' => [ - ZfSnapPhpDebugBar\Controller\Resources::class => ZfSnapPhpDebugBar\Controller\Resources::class, + 'factories' => [ + ZfSnapPhpDebugBar\Controller\Resources::class => ZfSnapPhpDebugBar\Controller\ResourcesFactory::class, ], ], 'view_helpers' => [ @@ -51,8 +53,8 @@ 'phpdebugbar-custom-resource' => [ 'type' => 'regex', 'options' => [ - 'regex' => '/ZfSnapPhpDebugBar/Resources/(?[a-zA-Z0-9_.\-/]+)', - 'spec' => '/ZfSnapPhpDebugBar/Resources/%resource%', + 'regex' => '/zfsnapphpdebugbar/resources/(?[a-zA-Z0-9_.\-/]+)', + 'spec' => '/zfsnapphpdebugbar/resources/%resource%', 'defaults' => [ 'controller' => ZfSnapPhpDebugBar\Controller\Resources::class, 'action' => 'custom', diff --git a/src/Controller/Resources.php b/src/Controller/Resources.php index 36beaf8..083a803 100644 --- a/src/Controller/Resources.php +++ b/src/Controller/Resources.php @@ -14,14 +14,23 @@ class Resources extends AbstractActionController 'js' => 'text/javascript; charset=UTF-8', ]; + private $debugbarResourcesPath; + private $customResourcesPath; + + public function __construct($debugbarResourcesPath, $customResourcesPath) + { + $this->debugbarResourcesPath = $debugbarResourcesPath; + $this->customResourcesPath = $customResourcesPath; + } + public function indexAction() { - return $this->prepareAssetResponse(__DIR__.'/../../../../../maximebf/debugbar/src/DebugBar/Resources/'); + return $this->prepareAssetResponse($this->debugbarResourcesPath); } public function customAction() { - return $this->prepareAssetResponse(__DIR__.'/../../../assets/'); + return $this->prepareAssetResponse($this->customResourcesPath); } protected function prepareAssetResponse($path) diff --git a/src/Controller/ResourcesFactory.php b/src/Controller/ResourcesFactory.php new file mode 100644 index 0000000..cbed25a --- /dev/null +++ b/src/Controller/ResourcesFactory.php @@ -0,0 +1,20 @@ +getServiceLocator(); + } + + $config = $container->get('config')['php-debug-bar']['view']; + + return new Resources($config['debugbar-resources'], $config['custom-resources']); + } +} diff --git a/src/Listener/RenderOnShutdownListener.php b/src/Listener/RenderOnShutdownListener.php index 909c993..69189ca 100644 --- a/src/Listener/RenderOnShutdownListener.php +++ b/src/Listener/RenderOnShutdownListener.php @@ -43,7 +43,6 @@ public function renderOnShutdown(MvcEvent $event) return; } - $renderer = $debugbar->getJavascriptRenderer(); - $renderer->renderOnShutdown(false); + $this->javascriptRenderer->renderOnShutdown(false); } } diff --git a/src/Log/Writer/PhpDebugBarFactory.php b/src/Log/Writer/PhpDebugBarFactory.php index 13b7f90..a729cf2 100644 --- a/src/Log/Writer/PhpDebugBarFactory.php +++ b/src/Log/Writer/PhpDebugBarFactory.php @@ -23,7 +23,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) /** * @return PhpDebugBar */ - public function __invoke(ContainerInterface $container, $requestedName, mixed $options = null) + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { /* @var $debugbar DebugBar */ $debugbar = $container->get('debugbar'); diff --git a/tests/Functional/DebugBarTest.php b/tests/Functional/DebugBarTest.php index 71cf146..8c4e38c 100644 --- a/tests/Functional/DebugBarTest.php +++ b/tests/Functional/DebugBarTest.php @@ -9,7 +9,6 @@ */ class DebugBarTest extends AbstractHttpControllerTestCase { - protected function setUp() { $this->traceError = false; @@ -66,6 +65,36 @@ public function testContainExceptionMessage() $this->assertResponseContains(DummyController::EXCEPTION_MESSAGE); } + public function testContainsUriToDebugBarResource() + { + $this->dispatch('/'); + + $this->assertResponseContains('/DebugBar/Resources/debugbar.js'); + } + + public function testContainsUriToCustomResource() + { + $this->dispatch('/'); + + $this->assertResponseContains('/zfsnapphpdebugbar/resources/zf-snap-php-debug-bar.css'); + } + + public function testGetStaticResourceFromDebugBar() + { + $this->dispatch('/DebugBar/Resources/debugbar.js'); + + $this->assertResponseStatusCode(200); + $this->assertResponseHeaderContains('Content-Type', 'text/javascript; charset=UTF-8'); + } + + public function testGetStaticCustomResource() + { + $this->dispatch('/zfsnapphpdebugbar/resources/zf-snap-php-debug-bar.css'); + + $this->assertResponseStatusCode(200); + $this->assertResponseHeaderContains('Content-Type', 'text/css; charset=UTF-8'); + } + private function assertResponseContains($string) { $this->assertContains($string, $this->getResponse()->getContent()); diff --git a/tests/assets/global.config.php b/tests/assets/global.config.php index 78cf451..4e0be9a 100644 --- a/tests/assets/global.config.php +++ b/tests/assets/global.config.php @@ -8,6 +8,9 @@ 'php-debug-bar' => [ 'auto-append-assets' => true, 'render-on-shutdown' => false, + 'view' => [ + 'debugbar-resources' => __DIR__.'/../../vendor/maximebf/debugbar/src/DebugBar/Resources/', + ], ], 'router' => [ 'routes' => [