Skip to content

Commit d53ac81

Browse files
committedMar 22, 2015
Added code comments and phpdoc.dist.xml file
1 parent adebdf0 commit d53ac81

10 files changed

+143
-13
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ docs/api/
44
docs/code-coverage/
55
vendor/
66
composer.lock
7+
phpdoc.xml

‎phpdoc.dist.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpdoc>
3+
<title>API Documentation</title>
4+
<parser>
5+
<target>docs/api/</target>
6+
</parser>
7+
<transformer>
8+
<target>docs/api/</target>
9+
</transformer>
10+
<files>
11+
<directory>src/</directory>
12+
</files>
13+
<logging>
14+
<paths>
15+
<default>build/logs/phpdoc.log</default>
16+
<errors>build/logs/phpdoc.err</errors>
17+
</paths>
18+
</logging>
19+
</phpdoc>

‎src/Command/Command.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ class Command implements CommandInterface
2828
protected $id;
2929

3030
/**
31+
* Creates a new Command object
32+
*
3133
* @since 2.0.0
32-
* @param string $method
33-
* @param array $parameters
34-
* @param string $id
34+
* @param string $method
35+
* @param array|null $parameters
36+
* @param string $id
3537
*/
36-
public function __construct($method = null, array $parameters = array(), $id = null)
38+
public function __construct($method = null, $parameters = null, $id = null)
3739
{
38-
$this->method = $method;
39-
$this->parameters = $parameters;
40-
$this->id = $id;
40+
if (null !== $method) {
41+
$this->withMethod($method);
42+
}
43+
44+
if (null !== $parameters) {
45+
$this->withParameters($parameters);
46+
}
47+
48+
if (null !== $id) {
49+
$this->withId($id);
50+
}
4151
}
4252

4353
/**

‎src/Http/Client.php

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class Client implements ClientInterface
3636
protected $driver;
3737

3838
/**
39+
* Creates a new Client object
40+
*
41+
* Currently you MUST pass in a DSN so the client knows where to send
42+
* commands to.
43+
*
44+
* ```php
45+
* $client = new \Nbobtc\Http\Client('https://username:password@localhost:18332');
46+
* ```
47+
*
3948
* @since 2.0.0
4049
* @param string $dsn Data Source Name
4150
*/
@@ -60,12 +69,15 @@ public function sendCommand(CommandInterface $command)
6069
)
6170
));
6271

72+
/** @var \Psr\Http\Message\ResponseInterface */
6373
$this->response = $this->driver->execute($this->request);
6474

6575
return $this->response;
6676
}
6777

6878
/**
79+
* Configures the Client to use a specific driver
80+
*
6981
* @since 2.0.0
7082
* @param \Nbobtc\Http\Driver\DriverInterface $driver
7183
* @return self
@@ -78,6 +90,8 @@ public function withDriver(DriverInterface $driver)
7890
}
7991

8092
/**
93+
* Return the current Request object
94+
*
8195
* @since 2.0.0
8296
* @return \Psr\Http\Message\RequestInterface
8397
*/
@@ -87,6 +101,8 @@ public function getRequest()
87101
}
88102

89103
/**
104+
* Returns the current Response object
105+
*
90106
* @since 2.0.0
91107
* @return \Psr\Http\Message\ResponseInterface
92108
*/

‎src/Http/ClientInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@
1010
use Nbobtc\Command\CommandInterface;
1111

1212
/**
13+
* Client used to send commands to bitcoin servers/nodes
14+
*
15+
* Client is used to send commands to bitcoin servers and receives the
16+
* responses back from those servers. The client does little to no processing
17+
* or minipulation of the Command, Request, and Response objects.
18+
*
1319
* @since 2.0.0
1420
*/
1521
interface ClientInterface
1622
{
1723
/**
24+
* Send Command to configured server
25+
*
26+
* Sends a command to a server and returns a Response object. If there was
27+
* an error it will throw an Exception.
28+
*
29+
* @since 2.0.0
1830
* @params \Nbobtc\Command\CommandInterface $command
1931
* @return \Psr\Http\Message\ResponseInterface
2032
* @throws \Exception

‎src/Http/Driver/CurlDriver.php

+23-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Nbobtc\Http\Message\Response;
1313

1414
/**
15+
* Uses cURL to send Requests
16+
*
1517
* @since 2.0.0
1618
*/
1719
class CurlDriver implements DriverInterface
@@ -27,6 +29,7 @@ class CurlDriver implements DriverInterface
2729
protected $curlOptions = array();
2830

2931
/**
32+
* @since 2.0.0
3033
*/
3134
public function __destruct()
3235
{
@@ -36,13 +39,15 @@ public function __destruct()
3639
}
3740

3841
/**
42+
* @since 2.0.0
3943
* {@inheritDoc}
4044
*/
4145
public function execute(RequestInterface $request)
4246
{
4347
if (null === self::$ch) {
4448
self::$ch = curl_init();
4549
}
50+
4651
$uri = $request->getUri();
4752
curl_setopt(self::$ch, CURLOPT_URL, sprintf('%s://%s@%s', $uri->getScheme(), $uri->getUserInfo(), $uri->getHost()));
4853
curl_setopt(self::$ch, CURLOPT_PORT, $uri->getPort());
@@ -52,12 +57,21 @@ public function execute(RequestInterface $request)
5257
$headers[] = $header.': '.implode(', ', $values);
5358
}
5459
curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);
55-
curl_setopt_array(self::$ch, array_merge($this->getDefaultCurlOptions(), $this->curlOptions));
5660
curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $request->getBody()->getContents());
5761

62+
// Allows user to override any option, may cause errors
63+
curl_setopt_array(self::$ch, array_merge($this->getDefaultCurlOptions(), $this->curlOptions));
64+
65+
/** @var string|false */
5866
$result = curl_exec(self::$ch);
59-
$info = curl_getinfo(self::$ch);
60-
$error = curl_error(self::$ch);
67+
/** @var array|false */
68+
$info = curl_getinfo(self::$ch);
69+
/** @var string */
70+
$error = curl_error(self::$ch);
71+
72+
if (!empty($error)) {
73+
throw new \Exception($error);
74+
}
6175

6276
$response = new Response();
6377
$response->withStatus($info['http_code']);
@@ -67,6 +81,9 @@ public function execute(RequestInterface $request)
6781
}
6882

6983
/**
84+
* Add options to use for cURL requests
85+
*
86+
* @since 2.0.0
7087
* @param integer $option
7188
* @param mixed $value
7289
*/
@@ -78,6 +95,9 @@ public function addCurlOption($option, $value)
7895
}
7996

8097
/**
98+
* Returns an array of cURL options
99+
*
100+
* @since 2.0.0
81101
* @return array
82102
*/
83103
protected function getDefaultCurlOptions()

‎src/Http/Driver/DriverInterface.php

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
interface DriverInterface
1616
{
1717
/**
18+
* Sends Request to server and returns a response.
19+
*
20+
* This will throw an Exception if there was an error
21+
*
22+
* @since 2.0.0
1823
* @param \Psr\Http\Message\RequestInterface $request
1924
* @return \Psr\Http\Message\ResponseInterface;
2025
* @throws \Exception

‎src/Http/Message/Message.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ class Message implements MessageInterface
1919
/**
2020
* @var string
2121
*/
22-
protected $version;
22+
protected $version = '1.1';
2323

2424
/**
2525
* @var array
2626
*/
2727
protected $headers = array();
2828

2929
/**
30-
* @var string
30+
* @var \Psr\Http\Message\StreamableInterface
3131
*/
3232
protected $body;
3333

3434
/**
35+
* @since 2.0.0
3536
* {@inheritDoc}
3637
*/
3738
public function getProtocolVersion()
@@ -40,6 +41,7 @@ public function getProtocolVersion()
4041
}
4142

4243
/**
44+
* @since 2.0.0
4345
* {@inheritDoc}
4446
*/
4547
public function withProtocolVersion($version)
@@ -50,6 +52,7 @@ public function withProtocolVersion($version)
5052
}
5153

5254
/**
55+
* @since 2.0.0
5356
* {@inheritDoc}
5457
*/
5558
public function getHeaders()
@@ -58,6 +61,7 @@ public function getHeaders()
5861
}
5962

6063
/**
64+
* @since 2.0.0
6165
* {@inheritDoc}
6266
*/
6367
public function hasHeader($name)
@@ -72,6 +76,7 @@ public function hasHeader($name)
7276
}
7377

7478
/**
79+
* @since 2.0.0
7580
* {@inheritDoc}
7681
*/
7782
public function getHeader($name)
@@ -86,6 +91,7 @@ public function getHeader($name)
8691
}
8792

8893
/**
94+
* @since 2.0.0
8995
* {@inheritDoc}
9096
*/
9197
public function getHeaderLines($name)
@@ -98,6 +104,7 @@ public function getHeaderLines($name)
98104
}
99105

100106
/**
107+
* @since 2.0.0
101108
* {@inheritDoc}
102109
*/
103110
public function withHeader($name, $value)
@@ -112,6 +119,7 @@ public function withHeader($name, $value)
112119
}
113120

114121
/**
122+
* @since 2.0.0
115123
* {@inheritDoc}
116124
*/
117125
public function withAddedHeader($name, $value)
@@ -122,6 +130,7 @@ public function withAddedHeader($name, $value)
122130
}
123131

124132
/**
133+
* @since 2.0.0
125134
* {@inheritDoc}
126135
*/
127136
public function withoutHeader($name)
@@ -136,6 +145,7 @@ public function withoutHeader($name)
136145
}
137146

138147
/**
148+
* @since 2.0.0
139149
* {@inheritDoc}
140150
*/
141151
public function getBody()
@@ -148,6 +158,7 @@ public function getBody()
148158
}
149159

150160
/**
161+
* @since 2.0.0
151162
* {@inheritDoc}
152163
*/
153164
public function withBody(StreamableInterface $body)

‎src/Http/Message/Request.php

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
class Request extends Message implements RequestInterface
1818
{
1919
/**
20+
* HTTP Methods
21+
*
2022
* @var string
2123
*/
2224
const HTTP_POST = 'POST';
@@ -35,6 +37,12 @@ class Request extends Message implements RequestInterface
3537
*/
3638
protected $uri;
3739

40+
/**
41+
* @since 2.0.0
42+
* @param UriInterface|null $uri
43+
* @param string $method
44+
* @throws \InvalidArgumentException
45+
*/
3846
public function __construct($uri = null, $method = self::HTTP_POST)
3947
{
4048
if ($uri instanceof \Psr\Http\Message\UriInterface) {
@@ -47,6 +55,7 @@ public function __construct($uri = null, $method = self::HTTP_POST)
4755
}
4856

4957
/**
58+
* @since 2.0.0
5059
* {@inheritDoc}
5160
*/
5261
public function getRequestTarget()
@@ -55,6 +64,7 @@ public function getRequestTarget()
5564
}
5665

5766
/**
67+
* @since 2.0.0
5868
* {@inheritDoc}
5969
*/
6070
public function withRequestTarget($requestTarget)
@@ -65,6 +75,7 @@ public function withRequestTarget($requestTarget)
6575
}
6676

6777
/**
78+
* @since 2.0.0
6879
* {@inheritDoc}
6980
*/
7081
public function getMethod()
@@ -73,6 +84,7 @@ public function getMethod()
7384
}
7485

7586
/**
87+
* @since 2.0.0
7688
* {@inheritDoc}
7789
*/
7890
public function withMethod($method)
@@ -83,6 +95,7 @@ public function withMethod($method)
8395
}
8496

8597
/**
98+
* @since 2.0.0
8699
* {@inheritDoc}
87100
*/
88101
public function getUri()
@@ -91,6 +104,7 @@ public function getUri()
91104
}
92105

93106
/**
107+
* @since 2.0.0
94108
* {@inheritDoc}
95109
*/
96110
public function withUri(UriInterface $uri)

‎src/Http/Message/Uri.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Uri implements UriInterface
6060
protected $fragment;
6161

6262
/**
63+
* @since 2.0.0
6364
* @param string $dsn
6465
*/
6566
public function __construct($dsn = null)
@@ -70,6 +71,7 @@ public function __construct($dsn = null)
7071
}
7172

7273
/**
74+
* @since 2.0.0
7375
* {@inheritDoc}
7476
*/
7577
public function __toString()
@@ -85,6 +87,7 @@ public function __toString()
8587
}
8688

8789
/**
90+
* @since 2.0.0
8891
* {@inheritDoc}
8992
*/
9093
public function getScheme()
@@ -93,6 +96,7 @@ public function getScheme()
9396
}
9497

9598
/**
99+
* @since 2.0.0
96100
* {@inheritDoc}
97101
*/
98102
public function getAuthority()
@@ -101,6 +105,7 @@ public function getAuthority()
101105
}
102106

103107
/**
108+
* @since 2.0.0
104109
* {@inheritDoc}
105110
*/
106111
public function getUserInfo()
@@ -109,6 +114,7 @@ public function getUserInfo()
109114
}
110115

111116
/**
117+
* @since 2.0.0
112118
* {@inheritDoc}
113119
*/
114120
public function getHost()
@@ -117,6 +123,7 @@ public function getHost()
117123
}
118124

119125
/**
126+
* @since 2.0.0
120127
* {@inheritDoc}
121128
*/
122129
public function getPort()
@@ -125,6 +132,7 @@ public function getPort()
125132
}
126133

127134
/**
135+
* @since 2.0.0
128136
* {@inheritDoc}
129137
*/
130138
public function getPath()
@@ -133,6 +141,7 @@ public function getPath()
133141
}
134142

135143
/**
144+
* @since 2.0.0
136145
* {@inheritDoc}
137146
*/
138147
public function getQuery()
@@ -141,6 +150,7 @@ public function getQuery()
141150
}
142151

143152
/**
153+
* @since 2.0.0
144154
* {@inheritDoc}
145155
*/
146156
public function getFragment()
@@ -149,6 +159,7 @@ public function getFragment()
149159
}
150160

151161
/**
162+
* @since 2.0.0
152163
* {@inheritDoc}
153164
*/
154165
public function withScheme($scheme)
@@ -159,6 +170,7 @@ public function withScheme($scheme)
159170
}
160171

161172
/**
173+
* @since 2.0.0
162174
* {@inheritDoc}
163175
*/
164176
public function withUserInfo($user, $password = null)
@@ -170,6 +182,7 @@ public function withUserInfo($user, $password = null)
170182
}
171183

172184
/**
185+
* @since 2.0.0
173186
* {@inheritDoc}
174187
*/
175188
public function withHost($host)
@@ -180,6 +193,7 @@ public function withHost($host)
180193
}
181194

182195
/**
196+
* @since 2.0.0
183197
* {@inheritDoc}
184198
*/
185199
public function withPort($port)
@@ -190,6 +204,7 @@ public function withPort($port)
190204
}
191205

192206
/**
207+
* @since 2.0.0
193208
* {@inheritDoc}
194209
*/
195210
public function withPath($path)
@@ -200,6 +215,7 @@ public function withPath($path)
200215
}
201216

202217
/**
218+
* @since 2.0.0
203219
* {@inheritDoc}
204220
*/
205221
public function withQuery($query)
@@ -210,6 +226,7 @@ public function withQuery($query)
210226
}
211227

212228
/**
229+
* @since 2.0.0
213230
* {@inheritDoc}
214231
*/
215232
public function withFragment($fragment)
@@ -220,10 +237,15 @@ public function withFragment($fragment)
220237
}
221238

222239
/**
240+
* Parse DSN
241+
*
242+
* @since 2.0.0
243+
* @internal
223244
* @param string $dsn
224245
*/
225-
public function parseDsn($dsn)
246+
protected function parseDsn($dsn)
226247
{
248+
/** @var array */
227249
$components = parse_url($dsn);
228250

229251
$this->withScheme($components['scheme']);

0 commit comments

Comments
 (0)
Please sign in to comment.