Skip to content

Commit 807c861

Browse files
committed
improve readme
1 parent 7442668 commit 807c861

File tree

1 file changed

+101
-82
lines changed

1 file changed

+101
-82
lines changed

README.md

Lines changed: 101 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<a href="https://xrdebug.com"><img alt="xrDebug" src="xr.svg" width="40%"></a>
44

5-
[![Build](https://img.shields.io/github/actions/workflow/status/xrdebug/php/test.yml?branch=2.0&style=flat-square)](https://github.com/xrdebug/php/actions)
5+
[![Build](https://img.shields.io/github/actions/workflow/status/xrdebug/php/test.yml?branch=3.0&style=flat-square)](https://github.com/xrdebug/php/actions)
66
![Code size](https://img.shields.io/github/languages/code-size/xrdebug/php?style=flat-square)
77
[![Apache-2.0](https://img.shields.io/github/license/xrdebug/php?style=flat-square)](LICENSE)
88
[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-blueviolet?style=flat-square)](https://phpstan.org/)
9-
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fxrdebug%2Fphp%2F2.0)](https://dashboard.stryker-mutator.io/reports/github.com/xrdebug/php/2.0)
9+
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fxrdebug%2Fphp%2F3.0)](https://dashboard.stryker-mutator.io/reports/github.com/xrdebug/php/3.0)
1010

1111
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xrdebug_php&metric=alert_status)](https://sonarcloud.io/dashboard?id=xrdebug_php)
1212
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=xrdebug_php&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=xrdebug_php)
@@ -18,9 +18,7 @@
1818

1919
## Summary
2020

21-
PHP client library for [xrDebug](https://xrdebug.com/). This library provides a set of functions to dump variables, send raw messages, and interact with the inspector.
22-
23-
VarDump functionality is provided by the [VarDump](https://chevere.org/packages/var-dump) package and throwable handling by the [ThrowableHandler](https://chevere.org/packages/throwable-handler) package.
21+
PHP client library for [xrDebug](https://xrdebug.com/). This library provides a set of functions to dump variables, send raw messages, and interact with the inspector from your codebase.
2422

2523
## Quick start
2624

@@ -30,48 +28,102 @@ Install using [Composer](https://packagist.org/packages/xrdebug/php).
3028
composer require --dev xrdebug/php
3129
```
3230

33-
Make sure to load the Composer `autoload.php` file in your project's entry point file, usually at `index.php`.
31+
Use `xr()` directly in your code to dump any variable. For example:
3432

3533
```php
3634
require_once __DIR__ . '/vendor/autoload.php';
35+
36+
// ...
37+
xr('Hello, world!');
3738
```
3839

39-
Use `xr()` directly in your code to dump any variable. For example for a WordPress plugin:
40+
## Configuring
41+
42+
This xrDebug PHP client uses the following default configuration.
43+
44+
> Skip this section if running from the xrDebug binary and on the same machine.
4045
4146
```php
42-
add_action('plugins_loaded', function () {
43-
$userCanManageOptions = current_user_can('manage_options');
44-
xr($userCanManageOptions);
45-
});
47+
[
48+
'isEnabled' => true,
49+
'isHttps' => false,
50+
'host' => 'localhost',
51+
'port' => 27420,
52+
'key' => '',
53+
]
4654
```
4755

48-
## Demo
56+
| Property | Type | Effect |
57+
| --------- | ------ | ----------------------------------------- |
58+
| isEnabled | bool | Controls sending messages to the server |
59+
| isHttps | bool | Controls use of https |
60+
| host | string | The host where xrDebug server is running |
61+
| port | int | The Port to connect to the `host` |
62+
| key | string | Private key (ed25519) for signed requests |
4963

50-
There's a interactive demo of this library in the `./demo` directory. To use the demo execute `xrdebug` server with default settings.
64+
> `host` The hostname or IP. When running xrDebug on Docker use `host.docker.internal`.
5165
52-
Execute the following command to start the demo, it sends messages to the xrDebug server explaining you the debugger user interface.
66+
### File-based config
5367

54-
```php
55-
php demo/welcome.php
56-
```
68+
Configure the client by placing a `xr.php` file in project's root directory. Need to define only the properties that override the default config.
5769

58-
Execute the following command to see how xrDebug [handles errors](#error-handling).
70+
We recommend adding `xr.php` to your `.gitignore`.
5971

60-
```php
61-
php demo/error-handling.php
62-
```
72+
Here some examples of `xr.php`:
73+
74+
- Run with Docker at a `27980` port:
75+
76+
```php
77+
<?php
78+
79+
return [
80+
'host' => 'host.docker.internal',
81+
'port' => 27980,
82+
];
83+
```
84+
85+
- Run with sign verification:
86+
87+
```php
88+
<?php
89+
90+
return [
91+
'key' => file_get_contents('private.key'),
92+
];
93+
```
6394

64-
## Debug Helpers
95+
### Code-based config
96+
97+
Use function `xrConfig()` to configure the xrDebug server connection directly in your logic. Need to define only the properties that override the default config.
98+
99+
Here some examples of `xrConfig()`:
100+
101+
- Run with Docker at a `27980` port:
102+
103+
```php
104+
xrConfig(
105+
host: 'host.docker.internal',
106+
port: 27980,
107+
);
108+
```
109+
110+
- Run with sign verification:
111+
112+
```php
113+
xrConfig(
114+
key: file_get_contents('private.key'),
115+
);
116+
```
117+
118+
## Debug helpers
65119

66120
This xrDebug PHP client provides the following helper functions in the root namespace. Use these anywhere in your code.
67121

68-
| Function | Purpose |
69-
| ----------- | --------------------------------- |
70-
| [xr](#xr) | Dump one or more variables |
71-
| [xrr](#xrr) | Dump raw message |
72-
| [xri](#xri) | Dump inspector (pauses, etc) |
73-
| [vd](#vd) | VarDump to output stream |
74-
| [vdd](#vdd) | VarDump to output stream and die |
122+
| Function | Purpose |
123+
| ----------- | ---------------------------- |
124+
| [xr](#xr) | Dump one or more variables |
125+
| [xrr](#xrr) | Dump raw message |
126+
| [xri](#xri) | Dump inspector (pauses, etc) |
75127

76128
### xr
77129

@@ -95,7 +147,7 @@ xr($var, e: '😎');
95147

96148
Pass bitwise flags to trigger special behavior.
97149

98-
* `f: XR_BACKTRACE` to include debug backtrace.
150+
- `f: XR_BACKTRACE` to include debug backtrace.
99151

100152
```php
101153
xr($var, f: XR_BACKTRACE);
@@ -128,9 +180,18 @@ Use `memory` to send memory usage information.
128180
xri()->memory();
129181
```
130182

183+
### Debug helpers (VarDump)
184+
185+
This xrDebug PHP client also provides the following helper functions provided by the [VarDump](https://chevere.org/packages/var-dump) package.
186+
187+
| Function | Purpose |
188+
| ----------- | --------------------------------- |
189+
| [vd](#vd) | VarDump to output stream |
190+
| [vdd](#vdd) | VarDump to output stream and die |
191+
131192
### vd
132193

133-
Function `vd` is a drop-in replacement for `var_dump`, it is provided by the [VarDump](https://chevere.org/packages/var-dump) package. It prints information about one or more variables to the output stream.
194+
Function `vd` is a drop-in replacement for `var_dump`. It prints information about one or more variables to the output stream.
134195

135196
```php
136197
vd($var1, $var2,);
@@ -146,46 +207,21 @@ vdd($var);
146207
// does exit();
147208
```
148209

149-
## Configuring
150-
151-
### Code-based configuration
152-
153-
Use `xrConfig()` to configure the xrDebug server connection.
154-
155-
```php
156-
xrConfig(
157-
isEnabled: true,
158-
isHttps: false,
159-
host: 'localhost',
160-
port: 27420,
161-
key: file_get_contents('private.key')
162-
);
163-
```
164-
165-
| Property | Type | Effect |
166-
| --------- | ------ | ---------------------------------------- |
167-
| isEnabled | bool | Controls sending messages to the server |
168-
| isHttps | bool | Controls use of https |
169-
| host | string | The host where xrDebug server is running |
170-
| port | int | The Port to connect to the `host` |
171-
| key | string | Private key (signed requests) |
210+
## Exception handling
172211

173-
### File-based configuration
212+
The PHP client provides a throwable handler that can hook or replace existing exception handler logic thanks to the [ThrowableHandler](https://chevere.org/packages/throwable-handler) package.
174213

175-
Configure the client by placing a `xr.php` file in project's root directory.
214+
### Register handler
176215

177-
> We recommend adding `xr.php` to your `.gitignore`.
216+
Use `registerThrowableHandler` to enable xrDebug throwable handling.
178217

179218
```php
180-
<?php
181219

182-
return [
183-
'isEnabled' => true,
184-
'isHttps' => false,
185-
'host' => 'localhost',
186-
'port' => 27420,
187-
'key' => file_get_contents('private.key'),
188-
];
220+
use Chevere\xrDebug\PHP\registerThrowableHandler;
221+
222+
// True append xrDebug to your existing handler
223+
// False use only xrDebug handler
224+
registerThrowableHandler(true);
189225
```
190226

191227
## Error handling
@@ -203,23 +239,6 @@ register_shutdown_function(
203239
);
204240
```
205241

206-
## Exception handling
207-
208-
The PHP client provides a throwable handler that can hook or replace existing exception handler logic thanks to the [ThrowableHandler](https://chevere.org/packages/throwable-handler) package.
209-
210-
### Register handler
211-
212-
Use `registerThrowableHandler` to enable xrDebug throwable handling.
213-
214-
```php
215-
216-
use Chevere\xrDebug\PHP\registerThrowableHandler;
217-
218-
// True append xrDebug to your existing handler
219-
// False use only xrDebug handler
220-
registerThrowableHandler(true);
221-
```
222-
223242
### Triggered handler
224243

225244
Use `throwableHandler` in any existing exception handler logic:

0 commit comments

Comments
 (0)