PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / php-http / message / src / Formatter / FullHttpMessageFormatter.php
ameliabooking / vendor / php-http / message / src / Formatter Last commit date
CurlCommandFormatter.php 6 months ago FullHttpMessageFormatter.php 6 months ago SimpleFormatter.php 6 months ago
FullHttpMessageFormatter.php
92 lines
1 <?php
2
3 namespace AmeliaHttp\Message\Formatter;
4
5 use AmeliaHttp\Message\Formatter;
6 use AmeliaVendor\Psr\Http\Message\MessageInterface;
7 use AmeliaVendor\Psr\Http\Message\RequestInterface;
8 use AmeliaVendor\Psr\Http\Message\ResponseInterface;
9
10 /**
11 * A formatter that prints the complete HTTP message.
12 *
13 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
14 */
15 class FullHttpMessageFormatter implements Formatter
16 {
17 /**
18 * The maximum length of the body.
19 *
20 * @var int
21 */
22 private $maxBodyLength;
23
24 /**
25 * @param int $maxBodyLength
26 */
27 public function __construct($maxBodyLength = 1000)
28 {
29 $this->maxBodyLength = $maxBodyLength;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public function formatRequest(RequestInterface $request)
36 {
37 $message = sprintf(
38 "%s %s HTTP/%s\n",
39 $request->getMethod(),
40 $request->getRequestTarget(),
41 $request->getProtocolVersion()
42 );
43
44 foreach ($request->getHeaders() as $name => $values) {
45 $message .= $name.': '.implode(', ', $values)."\n";
46 }
47
48 return $this->addBody($request, $message);
49 }
50
51 /**
52 * {@inheritdoc}
53 */
54 public function formatResponse(ResponseInterface $response)
55 {
56 $message = sprintf(
57 "HTTP/%s %s %s\n",
58 $response->getProtocolVersion(),
59 $response->getStatusCode(),
60 $response->getReasonPhrase()
61 );
62
63 foreach ($response->getHeaders() as $name => $values) {
64 $message .= $name.': '.implode(', ', $values)."\n";
65 }
66
67 return $this->addBody($response, $message);
68 }
69
70 /**
71 * Add the message body if the stream is seekable.
72 *
73 * @param MessageInterface $request
74 * @param string $message
75 *
76 * @return string
77 */
78 private function addBody(MessageInterface $request, $message)
79 {
80 $stream = $request->getBody();
81 if (!$stream->isSeekable() || 0 === $this->maxBodyLength) {
82 // Do not read the stream
83 $message .= "\n";
84 } else {
85 $message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength);
86 $stream->rewind();
87 }
88
89 return $message;
90 }
91 }
92