-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathexample70_guzzle.php
56 lines (40 loc) · 1.43 KB
/
example70_guzzle.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
55
56
<?php
// require composer autoload
require_once __DIR__ . '/bootstrap.php';
use GuzzleHttp\Client;
use Psr\Http\Message\RequestInterface;
class CustomHttpClient implements \Mpdf\Http\ClientInterface
{
/**
* @var \GuzzleHttp\Client
*/
private $http;
public function __construct(Client $http)
{
$this->http = $http;
}
public function sendRequest(RequestInterface $request)
{
// Apply headers and other details from original request
// Can return Guzzle response directly
return $this->http->request($request->getMethod(), $request->getUri());
}
}
class StdErrLogger extends \Psr\Log\AbstractLogger {
public function log($level, $message, array $context = [])
{
// fwrite(STDERR, $level . ': ' . $message . "\n");
}
}
$client = new CustomHttpClient(new Client());
$mpdf = new \Mpdf\Mpdf([], new \Mpdf\Container\SimpleContainer([
'httpClient' => $client,
]));
$mpdf->setLogger(new StdErrLogger());
$mpdf->WriteHtml('
<p>Custom implementation of internal HTTP client using Guzzle HTTP library</p>
<img width="256" src="https://upload.wikimedia.org/wikipedia/commons/2/2f/Neisse_bei_skerbersdorf_640x480.jpg"><br>
<img width="256" src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/9c/14-05-04-pramen-nysa-RalfR-DSC_1050-017.jpg/640px-14-05-04-pramen-nysa-RalfR-DSC_1050-017.jpg"><br>
<img width="256" src="https://upload.wikimedia.org/wikipedia/commons/e/e2/Nei%C3%9Fem%C3%BCndung.JPG">
');
$mpdf->Output();