-
Notifications
You must be signed in to change notification settings - Fork 0
/
plain.php
54 lines (40 loc) · 1.39 KB
/
plain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
//init tracy
Tracy\Debugger::enable();
//here we will store our transfer logs
$storage = new \Slepic\Http\Transfer\Log\ArrayStorage();
//prepare http message panel
$panel = \Slepic\Tracy\Bar\PsrHttpMessagePanel\Factory::create($storage);
//register the panel
$tracy = \Tracy\Debugger::getBar()->addPanel($panel);
//now create history observer that will observe all http transfers and push logs to the storage
$observer = new \Slepic\Http\Transfer\History\HistoryObserver($storage);
//let's use a guzzle http client to generate some transfers
$client = new \GuzzleHttp\Client();
//we can use prepared observer adapter for guzzle client
$middleware = new \Slepic\Guzzle\Http\ObservingMiddleware\ObservingMiddleware($observer);
//register the middleware
$client->getConfig('handler')
->unshift($middleware);
//make some example calls to fill the storage with logs
try {
$client->get('http://www.example.com/e404');
} catch (\Exception $e) {
}
try {
$client->get('http://google.com/?q=psr-http-message-tracy-panel');
} catch (\Exception $e) {
}
try {
$client->post('http://www.google.com', ['body' => 'q=search']);
} catch (\Exception $e) {
}
try {
$client->get('http://www.example.com');
} catch (\Exception $e) {
}
//display this script source code
echo "<pre>";
echo htmlspecialchars(file_get_contents(__FILE__));
echo "</pre>";