Skip to content

Commit 82e1a45

Browse files
committed
Merge pull request #13 from php-http/configurable
Introduces configurable logic
2 parents dfc9df2 + c5fd938 commit 82e1a45

File tree

6 files changed

+299
-7
lines changed

6 files changed

+299
-7
lines changed

src/Configurable.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter;
13+
14+
/**
15+
* Allows to modify configuration
16+
*
17+
* @author Márk Sági-Kazár [email protected]>
18+
*/
19+
interface Configurable extends HasConfiguration
20+
{
21+
/**
22+
* Sets an option
23+
*
24+
* @param string $name
25+
* @param mixed $option
26+
*/
27+
public function setOption($name, $option);
28+
29+
/**
30+
* Sets all options
31+
*
32+
* @param array $options
33+
*/
34+
public function setOptions(array $options);
35+
}

src/ConfigurableHttpAdapter.php

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter;
13+
14+
use Psr\Http\Message\StreamInterface;
15+
use Psr\Http\Message\UriInterface;
16+
use Psr\Http\Message\ResponseInterface;
17+
18+
/**
19+
* Allows request level configurations
20+
*
21+
* @author Márk Sági-Kazár [email protected]>
22+
*/
23+
interface ConfigurableHttpAdapter extends HttpAdapter
24+
{
25+
/**
26+
* Sends a GET request
27+
*
28+
* @param string|UriInterface $uri
29+
* @param string[] $headers
30+
* @param array $options
31+
*
32+
* @throws \InvalidArgumentException
33+
* @throws HttpAdapterException
34+
*
35+
* @return ResponseInterface
36+
*/
37+
public function get($uri, array $headers = [], array $options = []);
38+
39+
/**
40+
* Sends an HEAD request
41+
*
42+
* @param string|UriInterface $uri
43+
* @param string[] $headers
44+
* @param array $options
45+
*
46+
* @throws \InvalidArgumentException
47+
* @throws HttpAdapterException
48+
*
49+
* @return ResponseInterface
50+
*/
51+
public function head($uri, array $headers = [], array $options = []);
52+
53+
/**
54+
* Sends a TRACE request
55+
*
56+
* @param string|UriInterface $uri
57+
* @param string[] $headers
58+
* @param array $options
59+
*
60+
* @throws \InvalidArgumentException
61+
* @throws HttpAdapterException
62+
*
63+
* @return ResponseInterface
64+
*/
65+
public function trace($uri, array $headers = [], array $options = []);
66+
67+
/**
68+
* Sends a POST request
69+
*
70+
* @param string|UriInterface $uri
71+
* @param string[] $headers
72+
* @param array|string|StreamInterface $data
73+
* @param array $files
74+
* @param array $options
75+
*
76+
* @throws \InvalidArgumentException
77+
* @throws HttpAdapterException
78+
*
79+
* @return ResponseInterface
80+
*/
81+
public function post($uri, array $headers = [], $data = [], array $files = [], array $options = []);
82+
83+
/**
84+
* Sends a PUT request
85+
*
86+
* @param string|UriInterface $uri
87+
* @param string[] $headers
88+
* @param array|string|StreamInterface $data
89+
* @param array $files
90+
* @param array $options
91+
*
92+
* @throws \InvalidArgumentException
93+
* @throws HttpAdapterException
94+
*
95+
* @return ResponseInterface
96+
*/
97+
public function put($uri, array $headers = [], $data = [], array $files = [], array $options = []);
98+
99+
/**
100+
* Sends a PATCH request
101+
*
102+
* @param string|UriInterface $uri
103+
* @param string[] $headers
104+
* @param array|string|StreamInterface $data
105+
* @param array $files
106+
* @param array $options
107+
*
108+
* @throws \InvalidArgumentException
109+
* @throws HttpAdapterException
110+
*
111+
* @return ResponseInterface
112+
*/
113+
public function patch($uri, array $headers = [], $data = [], array $files = [], array $options = []);
114+
115+
/**
116+
* Sends a DELETE request
117+
*
118+
* @param string|UriInterface $uri
119+
* @param string[] $headers
120+
* @param array|string|StreamInterface $data
121+
* @param array $files
122+
* @param array $options
123+
*
124+
* @throws \InvalidArgumentException
125+
* @throws HttpAdapterException
126+
*
127+
* @return ResponseInterface
128+
*/
129+
public function delete($uri, array $headers = [], $data = [], array $files = [], array $options = []);
130+
131+
/**
132+
* Sends an OPTIONS request
133+
*
134+
* @param string|UriInterface $uri
135+
* @param string[] $headers
136+
* @param array|string|StreamInterface $data
137+
* @param array $files
138+
* @param array $options
139+
*
140+
* @throws \InvalidArgumentException
141+
* @throws HttpAdapterException
142+
*
143+
* @return ResponseInterface
144+
*/
145+
public function options($uri, array $headers = [], $data = [], array $files = [], array $options = []);
146+
147+
/**
148+
* Sends a request
149+
*
150+
* @param string $method
151+
* @param string|UriInterface $uri
152+
* @param string[] $headers
153+
* @param array|string|StreamInterface $data
154+
* @param array $files
155+
* @param array $options
156+
*
157+
* @throws \InvalidArgumentException
158+
* @throws HttpAdapterException
159+
*
160+
* @return ResponseInterface
161+
*/
162+
public function send($method, $uri, array $headers = [], $data = [], array $files = [], array $options = []);
163+
}

src/HasConfiguration.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter;
13+
14+
/**
15+
* Allows global configurations
16+
*
17+
* This interface does not allow modifying options
18+
*
19+
* @author Márk Sági-Kazár [email protected]>
20+
*/
21+
interface HasConfiguration
22+
{
23+
/**
24+
* Returns an option by name
25+
*
26+
* @param string $name
27+
*
28+
* @return mixed
29+
*/
30+
public function getOption($name);
31+
32+
/**
33+
* Returns all options
34+
*
35+
* @return array
36+
*/
37+
public function getOptions();
38+
39+
/**
40+
* Checks if an option exists
41+
*
42+
* @param string $name
43+
*
44+
* @return boolean
45+
*/
46+
public function hasOption($name);
47+
48+
/**
49+
* Checks if any option exists
50+
*
51+
* @return boolean
52+
*/
53+
public function hasOptions();
54+
}

src/Message/ConfigurableRequest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Adapter package.
5+
*
6+
* (c) Eric GELOEN <[email protected]>
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Adapter\Message;
13+
14+
use Psr\Http\Message\RequestInterface;
15+
use Psr\Http\HasConfiguration;
16+
17+
/**
18+
* Allows to modify configuration in a request an immutable way
19+
*
20+
* @author Márk Sági-Kazár [email protected]>
21+
*/
22+
interface ConfigurableRequest extends RequestInterface, HasConfiguration
23+
{
24+
/**
25+
* Sets an option
26+
*
27+
* @param string $name
28+
* @param mixed $option
29+
*
30+
* @return self
31+
*/
32+
public function withOption($name, $option);
33+
34+
/**
35+
* Removes an option
36+
*
37+
* @param string $name
38+
*
39+
* @return self
40+
*/
41+
public function withoutOption($name);
42+
}

src/Message/InternalRequest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Http\Adapter\Message;
1313

14-
use Psr\Http\Message\RequestInterface;
15-
1614
/**
1715
* @author GeLo <[email protected]>
1816
*/
19-
interface InternalRequest extends RequestInterface, ParameterableMessage
17+
interface InternalRequest extends ConfigurableRequest, ParameterableMessage
2018
{
2119
/**
2220
* Returns some data by name
@@ -89,14 +87,14 @@ public function withoutData($name);
8987
public function getFile($name);
9088

9189
/**
92-
* Returns the files
90+
* Returns all files
9391
*
9492
* @return array
9593
*/
9694
public function getFiles();
9795

9896
/**
99-
* Checks if the file exists
97+
* Checks if a file exists
10098
*
10199
* @param string $name
102100
*

src/Message/ParameterableMessage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ interface ParameterableMessage
2828
public function getParameter($name);
2929

3030
/**
31-
* Returns the parameters
31+
* Returns all parameters
3232
*
3333
* @return array
3434
*/
3535
public function getParameters();
3636

3737
/**
38-
* Checks if the parameter exists
38+
* Checks if a parameter exists
3939
*
4040
* @param string $name
4141
*

0 commit comments

Comments
 (0)