Skip to content

Commit

Permalink
Merge branch 'master' into config
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz authored Jun 21, 2024
2 parents 18e0b92 + 9e86aa5 commit dcf5e1e
Show file tree
Hide file tree
Showing 26 changed files with 651 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Yii debug API Change Log
# Yii Debug API Change Log

## 1.0.0 under development

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
Copyright © 2008 by Yii Software (<https://www.yiiframework.com/>)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://github.com/yiisoft.png" height="100px">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
</a>
<h1 align="center">Yii debug API</h1>
<h1 align="center">Yii Debug API</h1>
<br>
</p>

Expand All @@ -22,7 +22,7 @@ This extension provides an API for [Yii Debug](https://github.com/yiisoft/yii-de

## Installation

Add the package to your application:
The package could be installed with [Composer](https://getcomposer.org):

```shell
composer require yiisoft/yii-debug-api
Expand All @@ -33,35 +33,28 @@ composer require yiisoft/yii-debug-api
Routes will be registered automatically within Yii application router.
You can check if everything is OK by going to `/debug` URL.

## Testing
## Documentation

### Unit testing
- [Internals](docs/internals.md)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```shell
./vendor/bin/phpunit
```

### Mutation testing

The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:

```shell
./vendor/bin/infection
```

### Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```shell
./vendor/bin/psalm
```
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).

## License

The Yii Debug API is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).

## Support the project

[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

## Follow updates

[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)
1 change: 1 addition & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Yiisoft\\Assets\\AssetManager",
"Yiisoft\\Assets\\AssetPublisherInterface",
"Yiisoft\\Yii\\View\\ViewRenderer",
"Yiisoft\\Yii\\Http\\Application",
"Codeception\\Event\\FailEvent",
"Codeception\\Event\\PrintResultEvent",
"Codeception\\Event\\TestEvent",
Expand Down
24 changes: 19 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii-debug-api/issues?state=open",
"source": "https://github.com/yiisoft/yii-debug-api",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"chat": "https://t.me/yii3en",
"source": "https://github.com/yiisoft/yii-debug-api"
"irc": "ircs://irc.libera.chat:6697/yii",
"chat": "https://t.me/yii3en"
},
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/yiisoft"
},
{
"type": "github",
"url": "https://github.com/sponsors/yiisoft"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
Expand All @@ -27,9 +37,10 @@
"gitonomy/gitlib": "^1.3",
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/psr7": "^2.4",
"httpsoft/http-message": "^1.1",
"psr/container": "^2.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"psr/http-message": "^1.0|^2.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"psr/simple-cache": "^2.0|^3.0",
Expand All @@ -40,6 +51,7 @@
"yiisoft/di": "^1.0",
"yiisoft/friendly-exception": "^1.1",
"yiisoft/http": "^1.2",
"yiisoft/middleware-dispatcher": "^5.2",
"yiisoft/router": "^3.0",
"yiisoft/translator": "^3.0",
"yiisoft/var-dumper": "^1.4",
Expand All @@ -55,12 +67,14 @@
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.22",
"yiisoft/active-record": "3.0.x-dev",
"yiisoft/active-record": "dev-master",
"yiisoft/assets": "^4.0",
"yiisoft/csrf": "^2.0",
"yiisoft/db": "1.2 as dev-master",
"yiisoft/db-sqlite": "^1.0",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/router-fastroute": "^3.0",
"yiisoft/test-support": "^3.0",
"yiisoft/yii-cycle": "dev-master",
"yiisoft/yii-view": "^6.0"
},
Expand Down
12 changes: 12 additions & 0 deletions config/di-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Cycle\Database\DatabaseProviderInterface;
use Psr\Container\ContainerInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Yii\Debug\Api\Debug\Http\HttpApplicationWrapper;
use Yiisoft\Yii\Debug\Api\Debug\Http\RouteCollectorWrapper;
use Yiisoft\Yii\Debug\Api\Debug\Repository\CollectorRepository;
use Yiisoft\Yii\Debug\Api\Debug\Repository\CollectorRepositoryInterface;
use Yiisoft\Yii\Debug\Api\Inspector\Database\Cycle\CycleSchemaProvider;
Expand Down Expand Up @@ -34,4 +36,14 @@
)
);
},
HttpApplicationWrapper::class => [
'__construct()' => [
'middlewareDefinitions' => $params['yiisoft/yii-debug-api']['middlewares'],
],
],
RouteCollectorWrapper::class => [
'__construct()' => [
'middlewareDefinitions' => $params['yiisoft/yii-debug-api']['middlewares'],
],
],
];
4 changes: 4 additions & 0 deletions config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Codeception\Extension;
use Yiisoft\Yii\Debug\Api\Debug\Middleware\DebugHeaders;
use Yiisoft\Yii\Debug\Api\Inspector\Command\CodeceptionCommand;
use Yiisoft\Yii\Debug\Api\Inspector\Command\PHPUnitCommand;
use Yiisoft\Yii\Debug\Api\Inspector\Command\PsalmCommand;
Expand All @@ -26,6 +27,9 @@
'enabled' => true,
'allowedIPs' => ['127.0.0.1', '::1'],
'allowedHosts' => [],
'middlewares' => [
DebugHeaders::class,
],
'inspector' => [
'commandMap' => [
'tests' => $testCommands,
Expand Down
44 changes: 44 additions & 0 deletions docs/internals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Internals

## Unit testing

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```shell
./vendor/bin/phpunit
```

## Mutation testing

The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:

```shell
./vendor/bin/roave-infection-static-analysis-plugin
```

## Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```shell
./vendor/bin/psalm
```

## Code style

Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
use either newest or any specific version of PHP:

```shell
./vendor/bin/rector
```

## Dependencies

This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if
all dependencies are correctly defined in `composer.json`. To run the checker, execute the following command:

```shell
./vendor/bin/composer-require-checker
```
37 changes: 37 additions & 0 deletions src/Debug/Http/HttpApplicationWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Debug\Http;

use Closure;
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher;
use Yiisoft\Yii\Debug\Api\Debug\Middleware\MiddlewareDispatcherMiddleware;
use Yiisoft\Yii\Http\Application;

final readonly class HttpApplicationWrapper
{
public function __construct(
private MiddlewareDispatcher $middlewareDispatcher,
private array $middlewareDefinitions,
) {
}

public function wrap(Application $application): void

Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

UndefinedClass

src/Debug/Http/HttpApplicationWrapper.php:20:26: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

UndefinedClass

src/Debug/Http/HttpApplicationWrapper.php:20:26: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 20 in src/Debug/Http/HttpApplicationWrapper.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

UndefinedClass

src/Debug/Http/HttpApplicationWrapper.php:20:26: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)
{
$middlewareDispatcher = $this->middlewareDispatcher;
$middlewareDefinitions = $this->middlewareDefinitions;

$closure = Closure::bind(static function (Application $application) use (
$middlewareDispatcher,
$middlewareDefinitions,
) {
$application->dispatcher = $middlewareDispatcher->withMiddlewares([
...$middlewareDefinitions,
['class' => MiddlewareDispatcherMiddleware::class, '$middlewareDispatcher' => $application->dispatcher],
]);;
}, null, $application);

$closure($application);
}
}
20 changes: 20 additions & 0 deletions src/Debug/Http/RouteCollectorWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Debug\Http;

use Yiisoft\Router\RouteCollectorInterface;

final class RouteCollectorWrapper
{
public function __construct(
private array $middlewareDefinitions,
) {
}

public function wrap(RouteCollectorInterface $routeCollector): void
{
$routeCollector->prependMiddleware(...$this->middlewareDefinitions);
}
}
24 changes: 24 additions & 0 deletions src/Debug/Middleware/MiddlewareDispatcherMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Debug\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher;

final class MiddlewareDispatcherMiddleware implements MiddlewareInterface
{
public function __construct(
public MiddlewareDispatcher $middlewareDispatcher
) {
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
return $this->middlewareDispatcher->dispatch($request, $handler);
}
}
22 changes: 19 additions & 3 deletions src/Debug/Provider/DebugApiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Psr\Container\ContainerInterface;
use Yiisoft\Di\ServiceProviderInterface;
use Yiisoft\Router\RouteCollectorInterface;
use Yiisoft\Yii\Debug\Api\Debug\Middleware\DebugHeaders;
use Yiisoft\Yii\Debug\Api\Debug\Http\HttpApplicationWrapper;
use Yiisoft\Yii\Debug\Api\Debug\Http\RouteCollectorWrapper;
use Yiisoft\Yii\Http\Application;

final class DebugApiProvider implements ServiceProviderInterface
{
Expand All @@ -22,10 +24,24 @@ public function getDefinitions(): array
public function getExtensions(): array
{
return [
RouteCollectorInterface::class => static function (ContainerInterface $container, RouteCollectorInterface $routeCollector) {
$routeCollector->prependMiddleware(DebugHeaders::class);
RouteCollectorInterface::class => static function (
ContainerInterface $container,
RouteCollectorInterface $routeCollector
) {
/**
* Register debug middlewares twice because a `Subfolder` middleware may rewrite base URL
*/
$routerCollectionWrapper = $container->get(RouteCollectorWrapper::class);
$routerCollectionWrapper->wrap($routeCollector);

return $routeCollector;
},
Application::class => static function (ContainerInterface $container, Application $application) {

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:13: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:83: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:13: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:83: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:13: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)

Check failure on line 39 in src/Debug/Provider/DebugApiProvider.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

UndefinedClass

src/Debug/Provider/DebugApiProvider.php:39:83: UndefinedClass: Class, interface or enum named Yiisoft\Yii\Http\Application does not exist (see https://psalm.dev/019)
$applicationWrapper = $container->get(HttpApplicationWrapper::class);
$applicationWrapper->wrap($application);

return $application;
},
];
}
}
2 changes: 1 addition & 1 deletion src/Debug/Repository/CollectorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getObject(string $id, string $objectId): array|null
$dump = $this->loadData(StorageInterface::TYPE_OBJECTS, $id);

foreach ($dump as $name => $value) {
if (($pos = strrpos($name, "#$objectId")) !== false) {
if (($pos = strrpos((string)$name, "#$objectId")) !== false) {
return [substr($name, 0, $pos), $value];
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Inspector/ApplicationState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace Yiisoft\Yii\Debug\Api\Inspector;

class ApplicationState
/**
* @internal
*/
final class ApplicationState
{
public static $params;
public static array $params = [];
}
2 changes: 1 addition & 1 deletion src/Inspector/Command/BashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function run(): CommandResponse
->setTimeout(null)
->run();

$processOutput = $process->getOutput();
$processOutput = rtrim($process->getOutput());

if (!$process->getExitCode() > 1) {
return new CommandResponse(
Expand Down
Loading

0 comments on commit dcf5e1e

Please sign in to comment.