Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VarDumper collector docs #234

Merged
merged 6 commits into from
Jan 6, 2024
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
50 changes: 50 additions & 0 deletions docs/en/collector/event-dispatcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# [EventDispatcher collector](./../../../src/Collector/EventCollector.php)

`EventCollector` collects all events dispatched by [`\Psr\EventDispatcher\EventDispatcherInterface`](https://github.com/php-fig/event-dispatcher/blob/master/src/EventDispatcherInterface.php).

It uses [`\Yiisoft\Yii\Debug\Collector\EventDispatcherInterfaceProxy`](./../../../src/Collector/EventDispatcherInterfaceProxy.php) proxy to wrap the original PSR-14 event dispatcher and proxy all calls to the collector.

## Collected data

### Common

Example:

```php
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}

public function index(EventDispatcherInterface $dispatcher): ResponseInterface
{
$dispatcher->dispatch(new \stdClass());
return $this->viewRenderer->render('index');
}
}

```

Output:

```json
[
{
"name": "stdClass",
"event": "object@stdClass#7742",
"file": false,
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:20",
"time": 1704545249.06457
}
]
```

### Summary

```json
{
"total": 1
}
```
58 changes: 58 additions & 0 deletions docs/en/collector/http-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# [HttpClient collector](./../../../src/Collector/HttpClientCollector.php)

`HttpClientCollector` collects all requests sent by [`Psr\Http\Client\ClientInterface`](https://github.com/php-fig/http-client/blob/master/src/ClientInterface.php).

It uses [`\Yiisoft\Yii\Debug\Collector\HttpClientInterfaceProxy`](./../../../src/Collector/HttpClientInterfaceProxy.php) proxy to wrap the original PSR-18 client and proxy all calls to the collector.

## Collected data

### Common

Example:

```php
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}

public function index(): ResponseInterface
{
d(['test'], 1, new stdClass());
return $this->viewRenderer->render('index');
}
}
```

Output:

```json
[
{
"startTime": 1704545634.973538,
"endTime": 1704545635.120111,
"totalTime": 0.14657306671142578,
"method": "GET",
"uri": "https:\/\/google.com",
"headers": {
"Host": [
"google.com"
]
},
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:22",
"responseRaw": "HTTP\/1.1 301 Moved Permanently\r\nLocation: https:\/\/www.google.com\/\r\nContent-Type: text\/html; charset=UTF-8\r\nContent-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-1jfBaOK8wM3oVDi7ClviDg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https:\/\/csp.withgoogle.com\/csp\/gws\/other-hp\r\nDate: Sat, 06 Jan 2024 12:53:55 GMT\r\nExpires: Mon, 05 Feb 2024 12:53:55 GMT\r\nCache-Control: public, max-age=2592000\r\nServer: gws\r\nContent-Length: 220\r\nX-XSS-Protection: 0\r\nX-Frame-Options: SAMEORIGIN\r\nAlt-Svc: h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000\r\n\r\n<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text\/html;charset=utf-8\">\n<TITLE>301 Moved<\/TITLE><\/HEAD><BODY>\n<H1>301 Moved<\/H1>\nThe document has moved\n<A HREF=\"https:\/\/www.google.com\/\">here<\/A>.\r\n<\/BODY><\/HTML>\r\n",
"responseStatus": 301
}
]
```

### Summary

```json
{
"count": 1,
"totalTime": 0.14657306671142578
}
```
62 changes: 62 additions & 0 deletions docs/en/collector/logger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# [Log collector](./../../../src/Collector/LogCollector.php)

`LogCollector` collects all data logged by [`\Psr\Log\LoggerInterface`](https://github.com/php-fig/log/blob/master/src/LoggerInterface.php).

It uses [`\Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy`](./../../../src/Collector/LoggerInterfaceProxy.php) proxy to wrap the original PSR-3 logger and proxy all calls to the collector.

## Collected data

### Common

Example:

```php
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}

public function index(LoggerInterface $logger): ResponseInterface
{
$logger->debug('Hello, world!', ['category' => 'debug']);
$logger->info('Hello, world!', ['category' => 'info']);
return $this->viewRenderer->render('index');
}
}

```

Output:

```json
[
{
"time": 1704544908.712395,
"level": "debug",
"message": "Hello, world!",
"context": {
"category": "debug"
},
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:21"
},
{
"time": 1704544908.712417,
"level": "info",
"message": "Hello, world!",
"context": {
"category": "info"
},
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:22"
}
]
```

### Summary

```json
{
"total": 2
}
```
58 changes: 58 additions & 0 deletions docs/en/collector/var-dumper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# [VarDumper collector](./../../../src/Collector/VarDumperCollector.php)

`VarDumperCollector` collects all data dumped
by [`\Yiisoft\Yii\Debug\VarDumper\VarDumper`](https://github.com/yiisoft/var-dumper/blob/master/src/VarDumper.php) or
its shortcut functions `dump()`, `d()`, and `dd()`.

It uses [`\Yiisoft\Yii\Debug\Collector\VarDumperHandlerInterfaceProxy`](./../../../src/Collector/VarDumperHandlerInterfaceProxy.php) proxy to wrap the original VarDumper's [`HandlerInterface`](https://github.com/yiisoft/var-dumper/blob/master/src/HandlerInterface.php) and proxy all calls to the collector.

## Collected data

### Common

Example:

```php
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}

public function index(): ResponseInterface
{
d(['test'], 1, new stdClass());
return $this->viewRenderer->render('index');
}
}
```

Output:

```json
[
{
"variable": [
"test"
],
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:20"
},
{
"variable": 1,
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:20"
},
{
"variable": "object@stdClass#7735",
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:20"
}
]
```

### Summary

```json
{
"total": 3
}
```
4 changes: 4 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- [Main concept](./collector.md)
- [Summary collectors](./collector/summary.md)
- [Service Collector](./collector/service.md)
- [VarDumper Collector](./collector/var-dumper.md)
- [Log Collector](./collector/logger.md)
- [Event Collector](./collector/event-dispatcher.md)
- [HttpClient Collector](./collector/http-client.md)

## Console commands
- [`debug:reset`](./command-reset.md)
Expand Down