Skip to content

Commit 469c32f

Browse files
author
Martin Brecht-Precht
committed
Extended exception handling.
Updated readme.
1 parent c3188e7 commit 469c32f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,20 @@ $request->addAuthentication($clientCertificateAuthentication);
308308
If using the `BasicHttpClient` the response object is returned by the termination methods listed above. If directly using the Request instance, you can get the Response object via a getter.
309309

310310
```{php}
311-
// Getting the response BasicHttpClient\Response\ResponseInterface implementing object
311+
// Getting the response BasicHttpClient\Response\Response object
312312
$response = $request->getResponse();
313313
314314
// Reading the HTTP status code as integer; will return `200`
315-
echo print_r($response->getStatusCode(), true).PHP_EOL;
315+
echo print_r($response->getStatusCode(), true) . PHP_EOL;
316316
317317
// Reading the HTTP status text as string; will return `HTTP/1.1 200 OK`
318-
echo print_r($response->getStatusText(), true).PHP_EOL;
318+
echo print_r($response->getStatusText(), true) . PHP_EOL;
319319
320320
// Reading the HTTP response headers as array of BasicHttpClient\Response\Header\Header objects
321-
echo print_r($response->getHeaders(), true).PHP_EOL;
321+
echo print_r($response->getHeaders(), true) . PHP_EOL;
322322
323323
// Reading the HTTP response body as string
324-
echo print_r($response->getBody(), true).PHP_EOL;
324+
echo print_r($response->getBody(), true) . PHP_EOL;
325325
```
326326

327327
---

src/Request/Authentication/ClientCertificateAuthentication.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use BasicHttpClient\Exception\HttpRequestAuthenticationException;
66
use BasicHttpClient\Request\RequestInterface;
77
use BasicHttpClient\Request\Transport\HttpsTransport;
8+
use CommonException\IoException\FileNotFoundException;
89
use CommonException\IoException\FileReadableException;
910

1011
/**
@@ -55,11 +56,15 @@ public function getCaCertPath()
5556
/**
5657
* @param mixed $caCertPath
5758
* @return $this
59+
* @throws FileNotFoundException
5860
* @throws FileReadableException
5961
*/
6062
public function setCaCertPath($caCertPath)
6163
{
6264
if (!is_file($caCertPath)) {
65+
throw new FileNotFoundException('CA certificate file not found.');
66+
}
67+
if (!is_readable($caCertPath)) {
6368
throw new FileReadableException('CA certificate file not readable.');
6469
}
6570
$this->caCertPath = $caCertPath;
@@ -77,11 +82,15 @@ public function getClientCertPath()
7782
/**
7883
* @param mixed $clientCertPath
7984
* @return $this
85+
* @throws FileNotFoundException
8086
* @throws FileReadableException
8187
*/
8288
public function setClientCertPath($clientCertPath)
8389
{
8490
if (!is_file($clientCertPath)) {
91+
throw new FileNotFoundException('Client certificate file not found.');
92+
}
93+
if (!is_readable($clientCertPath)) {
8594
throw new FileReadableException('Client certificate file not readable.');
8695
}
8796
$this->clientCertPath = $clientCertPath;
@@ -113,7 +122,7 @@ public function setClientCertPassword($clientCertPassword)
113122
*/
114123
public function validate(RequestInterface $request)
115124
{
116-
if(!$request->getTransport() instanceof HttpsTransport){
125+
if (!$request->getTransport() instanceof HttpsTransport) {
117126
throw new HttpRequestAuthenticationException(
118127
'To perform a ClientCertificateAuthentication a HttpsTransport is required.'
119128
);

0 commit comments

Comments
 (0)