Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit f4df2f1

Browse files
committed
Moves exceptions into a sub-namespace
Exceptions were almost fully half of the classes/interfaces/traits in the package, and deserved their own namespace.
1 parent 18df547 commit f4df2f1

12 files changed

+27
-25
lines changed

doc/book/exception.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ details.
77
To facilitate this, we provide an interface, `ProblemDetailsException`:
88

99
```php
10-
namespace ProblemDetails;
10+
namespace ProblemDetails\Exception;
1111

1212
use JsonSerializable;
1313

@@ -50,8 +50,8 @@ transaction problem details, you might do so as follows:
5050

5151
```php
5252
use DomainException;
53-
use ProblemDetails\CommonProblemDetailsException;
54-
use ProblemDetails\ProblemDetailsException;
53+
use ProblemDetails\Exception\CommonProblemDetailsException;
54+
use ProblemDetails\Exception\ProblemDetailsException;
5555

5656
class TransactionException extends DomainException implements ProblemDetailsException
5757
{

doc/book/middleware.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ This middleware does the following:
1919
throwing any errors handled as `ErrorException` instances.
2020
- Wraps a call to the `$delegate` in a `try`/`catch` block; if nothing is
2121
caught, and a response is returned, it returns the response immediately. If a
22-
response is _not_ returned, it raises a `ProblemDetails\MissingResponseException`.
22+
response is _not_ returned, it raises a
23+
`ProblemDetails\Exception\MissingResponseException`.
2324
- For all caught throwables, it passes the throwable to
2425
`ProblemDetailsResponseFactory::createResponseFromThrowable()` to generate a
2526
Problem Details response.

doc/book/quick-start.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ as the HTTP status if it falls in the 400 or 500 range (500 will be used
155155
otherwise).
156156

157157
You can also create custom exceptions that provide details for the factory to
158-
consume by implementing `ProblemDetails\ProblemDetailsException`, which defines
159-
the following:
158+
consume by implementing `ProblemDetails\Exception\ProblemDetailsException`,
159+
which defines the following:
160160

161161
```php
162-
namespace ProblemDetails;
162+
namespace ProblemDetails\Exception;
163163

164164
use JsonSerializable;
165165

@@ -211,8 +211,8 @@ By composing this trait, you can easily define custom exception types:
211211
namespace Api;
212212

213213
use DomainException as PhpDomainException;
214-
use ProblemDetails\CommonProblemDetailsException;
215-
use ProblemDetails\ProblemDetailsException;
214+
use ProblemDetails\Exception\CommonProblemDetailsException;
215+
use ProblemDetails\Exception\ProblemDetailsException;
216216

217217
class DomainException extends PhpDomainException implements ProblemDetailsException
218218
{
@@ -249,8 +249,8 @@ a `ProblemDetailsResponseFactory`, and does the following:
249249
- Otherwise, it creates a PHP error handler that converts PHP errors to
250250
`ErrorException` instances, and then wraps processing of the delegate in a
251251
try/catch block. If the delegate does not return a `ResponseInterface`, a
252-
`ProblemDetails\MissingResponseException` is raised; otherwise, the response
253-
is returned.
252+
`ProblemDetails\Exception\MissingResponseException` is raised; otherwise, the
253+
response is returned.
254254
- Any throwable or exception caught is passed to the
255255
`ProblemDetailsResponseFactory::createResponseFromThrowable()` method, and the
256256
response generated is returned.

src/CommonProblemDetailsException.php renamed to src/Exception/CommonProblemDetailsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProblemDetails;
3+
namespace ProblemDetails\Exception;
44

55
/**
66
* Common functionality for ProblemDetailsException implementations.

src/InvalidResponseBodyException.php renamed to src/Exception/InvalidResponseBodyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProblemDetails;
3+
namespace ProblemDetails\Exception;
44

55
use RuntimeException;
66

src/MissingResponseException.php renamed to src/Exception/MissingResponseException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProblemDetails;
3+
namespace ProblemDetails\Exception;
44

55
use RuntimeException;
66

src/ProblemDetailsException.php renamed to src/Exception/ProblemDetailsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ProblemDetails;
3+
namespace ProblemDetails\Exception;
44

55
use JsonSerializable;
66

src/ProblemDetailsMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
4141
$response = $delegate->process($request);
4242

4343
if (! $response instanceof ResponseInterface) {
44-
throw new MissingResponseException('Application did not return a response');
44+
throw new Exception\MissingResponseException('Application did not return a response');
4545
}
4646
} catch (Throwable $e) {
4747
$response = $this->responseFactory->createResponseFromThrowable($request, $e);

src/ProblemDetailsResponseFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function createResponseFromThrowable(
208208
ServerRequestInterface $request,
209209
Throwable $e
210210
) : ResponseInterface {
211-
if ($e instanceof ProblemDetailsException) {
211+
if ($e instanceof Exception\ProblemDetailsException) {
212212
return $this->createResponse(
213213
$request,
214214
$e->getStatus(),
@@ -258,13 +258,13 @@ protected function generateXmlResponse(array $payload) : ResponseInterface
258258
}
259259

260260
/**
261-
* @throws InvalidResponseBodyException
261+
* @throws Exception\InvalidResponseBodyException
262262
*/
263263
protected function generateResponse(int $status, string $contentType, string $payload) : ResponseInterface
264264
{
265265
$body = ($this->bodyFactory)();
266266
if (! $body instanceof StreamInterface) {
267-
throw new InvalidResponseBodyException(sprintf(
267+
throw new Exception\InvalidResponseBodyException(sprintf(
268268
'The factory for generating a problem details response body stream did not return a %s',
269269
StreamInterface::class
270270
));

test/ProblemDetailsExceptionTest.php renamed to test/Exception/ProblemDetailsExceptionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace ProblemDetailsTest;
3+
namespace ProblemDetailsTest\Exception;
44

55
use PHPUnit\Framework\TestCase;
6-
use ProblemDetails\CommonProblemDetailsException;
7-
use ProblemDetails\ProblemDetailsException;
6+
use ProblemDetails\Exception\CommonProblemDetailsException;
7+
use ProblemDetails\Exception\ProblemDetailsException;
88

99
class ProblemDetailsExceptionTest extends TestCase
1010
{

0 commit comments

Comments
 (0)