Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
* text=auto eol=lf

/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php-cs-fixer.php export-ignore
phpcs.xml export-ignore
phpunit.xml export-ignore
.phpstan.neon export-ignore
5 changes: 1 addition & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

Expand Down Expand Up @@ -71,6 +71,3 @@ jobs:

- name: Tests
run: composer test

- name: Tests coverage
run: composer coverage
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ vendor
composer.lock
coverage
*.cache
.idea
kit
10 changes: 10 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return My\PhpCsFixerConfig::create()
->setFinder(
PhpCsFixer\Finder::create()
->files()
->name('*.php')
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
);
6 changes: 6 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
- tests
inferPrivatePropertyTypeFromConstructor: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.2.0] - 2025-03-22
### Added
- Improve support for PHP 8.4 and typying.

## [2.1.2] - 2025-03-18
### Fixed
- Compatibility with PHP 8.4
Expand Down Expand Up @@ -88,6 +92,7 @@ First version
[#12]: https://github.com/middlewares/debugbar/issues/12
[#17]: https://github.com/middlewares/debugbar/issues/17

[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.2...v2.2.0
[2.1.2]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/middlewares/debugbar/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/middlewares/debugbar/compare/v2.0.1...v2.1.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019
Copyright (c) 2019-2025

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ $debugbar = (new Middlewares\Debugbar())->inline();

Use this option to pass render options to the debugbar as an array. A list of available options can be found at https://github.com/php-debugbar/php-debugbar/blob/master/src/DebugBar/JavascriptRenderer.php#L132

An example usage would be to pass a new location for the ``base_url`` so that you can rewrite the location of the files needed to render the debug bar. This can be used with symlinks, .htaccess or routes to the files to ensure the debugbar files are accessible.
An example usage would be to pass a new location for the `base_url` so that you can rewrite the location of the files needed to render the debug bar. This can be used with symlinks, .htaccess or routes to the files to ensure the debugbar files are accessible.

```php
$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar/"));
$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar"));
```
---

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
},
"require": {
"php": "^7.2 || ^8.0",
"middlewares/utils": "^3.0 || ^4.0",
"php-debugbar/php-debugbar": "^1.13",
"psr/http-server-middleware": "^1.0"
"php-debugbar/php-debugbar": "^1 || ^2",
"middlewares/utils": "^2 || ^3 || ^4",
"psr/http-server-middleware": "^1"
},
"require-dev": {
"phpunit/phpunit": "^8|^9",
"friendsofphp/php-cs-fixer": "^3.0",
"squizlabs/php_codesniffer": "^3.0",
"oscarotero/php-cs-fixer-config": "^1 || ^2",
"phpunit/phpunit": "^8 || ^9",
"friendsofphp/php-cs-fixer": "^3",
"squizlabs/php_codesniffer": "^3",
"oscarotero/php-cs-fixer-config": "^2",
"phpstan/phpstan": "^1 || ^2",
"laminas/laminas-diactoros": "^2 || ^3"
},
Expand Down
16 changes: 16 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<ruleset name="Middlewares coding standard">
<description>Middlewares coding standard</description>

<!-- display progress -->
<arg value="p"/>
<arg name="report" value="full"/>
<arg name="colors"/>

<!-- coding standard -->
<rule ref="PSR2"/>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
33 changes: 33 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
failOnWarning="true">
<testsuites>
<testsuite name="Debugbar test suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory>./src</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
28 changes: 15 additions & 13 deletions src/Debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

class Debugbar implements MiddlewareInterface
{
/**
* @var array<string,string>
*/
private static $mimes = [
'css' => 'text/css',
'js' => 'text/javascript',
];

/**
* @var Bar|null The debugbar
* The debugbar
*/
private $debugbar;

Expand All @@ -36,27 +39,25 @@ class Debugbar implements MiddlewareInterface
private $inline = false;

/**
* @var array A rewrite of the root path for the loaded files
* @var array<string,string>|null A rewrite of the root path for the loaded files
*/
private $renderOptions = null;

/**
* @var ResponseFactoryInterface
*/
private $responseFactory;

/**
* @var StreamFactoryInterface
*/
private $streamFactory;

/**
* Set the debug bar.
*
* @param Bar|null $debugbar
* @param ResponseFactoryInterface|null $responseFactory
* @param StreamFactoryInterface|null $streamFactory
*/
public function __construct(
Bar $debugbar = null,
ResponseFactoryInterface $responseFactory = null,
StreamFactoryInterface $streamFactory = null
?Bar $debugbar = null,
?ResponseFactoryInterface $responseFactory = null,
?StreamFactoryInterface $streamFactory = null
) {
$this->debugbar = $debugbar ?: new StandardDebugBar();
$this->responseFactory = $responseFactory ?: Factory::getResponseFactory();
Expand All @@ -65,8 +66,10 @@ public function __construct(

/**
* Set the roo path variable
*
* @param array<string,string> $renderOptions
*/
public function renderOptions(array $renderOptions = null): self
public function renderOptions(?array $renderOptions = null): self
{
$this->renderOptions = $renderOptions;

Expand Down Expand Up @@ -98,7 +101,6 @@ public function inline(bool $inline = true): self
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{

$renderer = $this->debugbar->getJavascriptRenderer();
if ($this->renderOptions) {
$renderer->setOptions($this->renderOptions);
Expand Down
14 changes: 9 additions & 5 deletions tests/DebugbarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class DebugbarTest extends TestCase
{
/**
* @return array<array<mixed>>
*/
public function debugBarProvider(): array
{
return [
Expand All @@ -23,8 +26,9 @@ public function debugBarProvider(): array

/**
* @dataProvider debugBarProvider
* @param array<string,string> $headers
*/
public function testDebugbar(string $contentType, array $headers, bool $expectedBody, bool $expectedHeader)
public function testDebugbar(string $contentType, array $headers, bool $expectedBody, bool $expectedHeader): void
{
$request = Factory::createServerRequest('GET', '/');

Expand Down Expand Up @@ -55,7 +59,7 @@ function () use ($contentType) {
}
}

public function testInline()
public function testInline(): void
{
$response = Dispatcher::run([
(new Debugbar())->inline(),
Expand All @@ -73,7 +77,7 @@ function () {
$this->assertNotFalse(strpos($body, '</style>'));
}

public function testAsset()
public function testAsset(): void
{
$debugbar = new StandardDebugBar();
$renderer = $debugbar->getJavascriptRenderer();
Expand All @@ -98,7 +102,7 @@ function () {
/**
* @runInSeparateProcess
*/
public function testRedirection()
public function testRedirection(): void
{
session_start();

Expand All @@ -118,7 +122,7 @@ function () {
$this->assertEquals(302, $response->getStatusCode());
}

public function testRenderOptions()
public function testRenderOptions(): void
{
$response = Dispatcher::run(
[
Expand Down