Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Guzzle4Driver.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient;
8
9 use GuzzleHttp\Client;
10 use GuzzleHttp\Stream\Stream;
11 use GuzzleHttp\Exception\RequestException;
12
13 class Guzzle4Driver extends GuzzleDriver
14 {
18 public function __construct()
19 {
20 $this->client = new Client();
21 }
22
30 public function getHeaders()
31 {
32 $headers = [];
33 foreach ((array)$this->getResponse()->getHeaders() as $header => $headerObject) {
34 $headers[strtolower($header)] = implode(';', $headerObject);
35 }
36
37 return $headers;
38 }
39
47 public function getBody()
48 {
49 return (string)$this->getResponse()->getBody();
50 }
51
57 public function setBody($body)
58 {
59 $this->body = empty($body) ?
60 null :
61 Stream::factory($body);
62 }
63
67 public function send()
68 {
69 $this->request = $this->client->createRequest(
70 $this->method,
71 $this->host . $this->resource
72 );
73
74 // set headers
75 foreach ($this->headers as $header => $value) {
76 $this->request->setHeader($header, $value);
77 }
78
79 // set body
80 if (!empty($this->body)) {
81 $this->request->setBody($this->body);
82 }
83
84 try {
85 // finally send the request
86 $this->response = $this->client->send($this->request);
87 } catch (RequestException $e) {
88 // if the response is an 40x or a 50x then it will throw an exception
89 // we catch and get the response stored on the request object
90 $this->response = $e->getResponse();
91 }
92
93 $this->sent = true;
94 }
95 }
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver
Definition: Guzzle4Driver.php:14
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver\getBody
getBody()
Get response body.
Definition: Guzzle4Driver.php:47
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver\getHeaders
getHeaders()
Get all response headers.
Definition: Guzzle4Driver.php:30
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver\__construct
__construct()
Initialize client.
Definition: Guzzle4Driver.php:18
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver\setBody
setBody($body)
Set request body.
Definition: Guzzle4Driver.php:57
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\Guzzle4Driver\send
send()
Send the request.
Definition: Guzzle4Driver.php:67
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\GuzzleDriver
Definition: GuzzleDriver.php:14
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\GuzzleDriver\$headers
$headers
Definition: GuzzleDriver.php:39
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\GuzzleDriver\$body
$body
Definition: GuzzleDriver.php:42
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient\GuzzleDriver\getResponse
getResponse()
Get reponse.
Definition: GuzzleDriver.php:59
eZ\Bundle\EzPublishRestBundle\Features\Context\RestClient
Definition: BuzzDriver.php:7
host-p
Returns the Data Source Name as a structure containing the various parts of the DSN.
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.