PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / mailgun / mailgun-php / src / Mailgun / RequestBuilder.php
ameliabooking / vendor / mailgun / mailgun-php / src / Mailgun Last commit date
Api 3 years ago Connection 3 years ago Constants 7 years ago Exception 3 years ago HttpClient 3 years ago Hydrator 3 years ago Lists 7 years ago Message 7 years ago Messages 7 years ago Model 7 years ago Assert.php 7 years ago Exception.php 7 years ago HttpClientConfigurator.php 3 years ago Mailgun.php 3 years ago RequestBuilder.php 3 years ago
RequestBuilder.php
122 lines
1 <?php
2
3 /*
4 * Copyright (C) 2013 Mailgun
5 *
6 * This software may be modified and distributed under the terms
7 * of the MIT license. See the LICENSE file for details.
8 */
9
10 namespace Mailgun;
11
12 use AmeliaHttp\Discovery\MessageFactoryDiscovery;
13 use AmeliaHttp\Message\MultipartStream\MultipartStreamBuilder;
14 use AmeliaHttp\Message\RequestFactory;
15 use AmeliaPsr\Http\Message\RequestInterface;
16
17 /**
18 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
19 */
20 class RequestBuilder
21 {
22 /**
23 * @var RequestFactory
24 */
25 private $requestFactory;
26
27 /**
28 * @var MultipartStreamBuilder
29 */
30 private $multipartStreamBuilder;
31
32 /**
33 * Creates a new PSR-7 request.
34 *
35 * @param string $method
36 * @param string $uri
37 * @param array $headers
38 * @param array|string|null $body Request body. If body is an array we will send a as multipart stream request.
39 * If array, each array *item* MUST look like:
40 * array (
41 * 'content' => string|resource|StreamInterface,
42 * 'name' => string,
43 * 'filename'=> string (optional)
44 * 'headers' => array (optinal) ['header-name' => 'header-value']
45 * )
46 *
47 * @return RequestInterface
48 */
49 public function create($method, $uri, array $headers = [], $body = null)
50 {
51 if (!is_array($body)) {
52 return $this->getRequestFactory()->createRequest($method, $uri, $headers, $body);
53 }
54
55 $builder = $this->getMultipartStreamBuilder();
56 foreach ($body as $item) {
57 $name = $item['name'];
58 $content = $item['content'];
59 unset($item['name']);
60 unset($item['content']);
61
62 $builder->addResource($name, $content, $item);
63 }
64
65 $multipartStream = $builder->build();
66 $boundary = $builder->getBoundary();
67 $builder->reset();
68
69 $headers['Content-Type'] = 'multipart/form-data; boundary="'.$boundary.'"';
70
71 return $this->getRequestFactory()->createRequest($method, $uri, $headers, $multipartStream);
72 }
73
74 /**
75 * @return RequestFactory
76 */
77 private function getRequestFactory()
78 {
79 if (null === $this->requestFactory) {
80 $this->requestFactory = MessageFactoryDiscovery::find();
81 }
82
83 return $this->requestFactory;
84 }
85
86 /**
87 * @param RequestFactory $requestFactory
88 *
89 * @return RequestBuilder
90 */
91 public function setRequestFactory($requestFactory)
92 {
93 $this->requestFactory = $requestFactory;
94
95 return $this;
96 }
97
98 /**
99 * @return MultipartStreamBuilder
100 */
101 private function getMultipartStreamBuilder()
102 {
103 if (null === $this->multipartStreamBuilder) {
104 $this->multipartStreamBuilder = new MultipartStreamBuilder();
105 }
106
107 return $this->multipartStreamBuilder;
108 }
109
110 /**
111 * @param MultipartStreamBuilder $multipartStreamBuilder
112 *
113 * @return RequestBuilder
114 */
115 public function setMultipartStreamBuilder($multipartStreamBuilder)
116 {
117 $this->multipartStreamBuilder = $multipartStreamBuilder;
118
119 return $this;
120 }
121 }
122