Skip to content

Commit 8159d77

Browse files
committed
Fixed conflicts
Signed-off-by: alexmerlin <[email protected]>
2 parents fc59d66 + 668a665 commit 8159d77

File tree

7 files changed

+68
-64
lines changed

7 files changed

+68
-64
lines changed

.laminas-ci/pre-run.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@ COMMAND=$(echo "${JOB}" | jq -r '.command')
55
echo "Running pre-run $COMMAND"
66

77
if [[ ${COMMAND} =~ phpunit ]];then
8-
98
apt-get install php"${PHP_VERSION}"-sqlite3
10-
11-
cp config/autoload/local.php.dist config/autoload/local.php
12-
cp config/autoload/local.test.php.dist config/autoload/local.test.php
13-
149
fi

config/autoload/local.php.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ $databases = [
2121
return [
2222
'application' => [
2323
'name' => 'Dotkernel API',
24-
'version' => 6,
24+
'version' => 6.0,
2525
'url' => $baseUrl,
2626
'versioning' => [
27-
'documentation_url' => 'https://docs.dotkernel.org/api-documentation/v5/core-features/versioning',
27+
'documentation_url' => 'https://docs.dotkernel.org/api-documentation/v6/core-features/versioning',
2828
],
2929
],
3030
'authentication' => [

config/pipeline.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Api\App\Middleware\ContentNegotiationMiddleware;
99
use Api\App\Middleware\DeprecationMiddleware;
1010
use Api\App\Middleware\ResourceProviderMiddleware;
11-
use Api\App\Middleware\ResponseMiddleware;
12-
use Dot\ErrorHandler\ErrorHandlerInterface;
1311
use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware;
1412
use Mezzio\Application;
1513
use Mezzio\Cors\Middleware\CorsMiddleware;
@@ -25,9 +23,9 @@
2523
use Mezzio\Router\Middleware\RouteMiddleware;
2624

2725
return function (Application $app): void {
28-
// The error handler should be the first (most outer) middleware to catch
29-
// all Exceptions.
30-
$app->pipe(ErrorHandlerInterface::class);
26+
// This middleware must be the outest layer because - on error occurrence - it will:
27+
// - call \Dot\ErrorHandler\ErrorHandlerInterface::class
28+
// - return ProblemDetails response
3129
$app->pipe(ProblemDetailsMiddleware::class);
3230

3331
$app->pipe(BodyParamsMiddleware::class);
@@ -39,15 +37,14 @@
3937
// - pre-conditions
4038
// - modifications to outgoing responses
4139
//
42-
// Piped Middleware may be either callables or service names. Middleware may
43-
// also be passed as an array; each item in the array must resolve to
44-
// middleware eventually (i.e., callable or service name).
40+
// Piped Middleware may be either callables or service names.
41+
// Middleware may also be passed as an array; each item in the array must resolve to middleware eventually
42+
// (i.e., callable or service name).
4543
//
46-
// Middleware can be attached to specific paths, allowing you to mix and match
47-
// applications under a common domain. The handlers in each middleware
48-
// attached this way will see a URI with the matched path segment removed.
44+
// Middleware can be attached to specific paths, allowing you to mix and match applications under a common domain.
45+
// The handlers in each middleware attached this way will see a URI with the matched path segment removed.
4946
//
50-
// i.e., path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware
47+
// For example, the path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware
5148
// - $app->pipe('/api', $apiMiddleware);
5249
// - $app->pipe('/docs', $apiDocMiddleware);
5350
// - $app->pipe('/files', $filesMiddleware);
@@ -84,7 +81,6 @@
8481
// - route-based validation
8582
// - etc.
8683

87-
$app->pipe(ResponseMiddleware::class);
8884
$app->pipe(ResourceProviderMiddleware::class);
8985

9086
// Register the dispatch middleware in the middleware pipeline

src/App/src/ConfigProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Api\App\Command\TokenGenerateCommand;
88
use Api\App\Factory\HandlerDelegatorFactory;
9+
use Api\App\Factory\ProblemDetailsDelegatorFactory;
910
use Api\App\Handler\GetIndexResourceHandler;
1011
use Api\App\Handler\PostErrorReportResourceHandler;
1112
use Api\App\Middleware\AuthenticationMiddleware;
@@ -14,7 +15,6 @@
1415
use Api\App\Middleware\DeprecationMiddleware;
1516
use Api\App\Middleware\ErrorReportPermissionMiddleware;
1617
use Api\App\Middleware\ResourceProviderMiddleware;
17-
use Api\App\Middleware\ResponseMiddleware;
1818
use Api\App\Service\ErrorReportService;
1919
use Api\App\Service\ErrorReportServiceInterface;
2020
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
@@ -24,6 +24,7 @@
2424
use Mezzio\Authentication\OAuth2\OAuth2Adapter;
2525
use Mezzio\Hal\Metadata\RouteBasedCollectionMetadata;
2626
use Mezzio\Hal\Metadata\RouteBasedResourceMetadata;
27+
use Mezzio\ProblemDetails\ProblemDetailsMiddleware;
2728
use Mezzio\Template\TemplateRendererInterface;
2829
use Mezzio\Twig\TwigEnvironmentFactory;
2930
use Mezzio\Twig\TwigExtension;
@@ -48,6 +49,7 @@ private function getDependencies(): array
4849
Application::class => [RoutesDelegator::class],
4950
GetIndexResourceHandler::class => [HandlerDelegatorFactory::class],
5051
PostErrorReportResourceHandler::class => [HandlerDelegatorFactory::class],
52+
ProblemDetailsMiddleware::class => [ProblemDetailsDelegatorFactory::class],
5153
],
5254
'factories' => [
5355
AuthenticationMiddleware::class => AttributedServiceFactory::class,
@@ -56,7 +58,6 @@ private function getDependencies(): array
5658
DeprecationMiddleware::class => AttributedServiceFactory::class,
5759
ErrorReportPermissionMiddleware::class => AttributedServiceFactory::class,
5860
ResourceProviderMiddleware::class => AttributedServiceFactory::class,
59-
ResponseMiddleware::class => AttributedServiceFactory::class,
6061
GetIndexResourceHandler::class => AttributedServiceFactory::class,
6162
PostErrorReportResourceHandler::class => AttributedServiceFactory::class,
6263
ErrorReportService::class => AttributedServiceFactory::class,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Api\App\Factory;
6+
7+
use Api\App\Exception\RuntimeException;
8+
use Core\App\Message;
9+
use Dot\ErrorHandler\ErrorHandlerInterface;
10+
use Dot\ErrorHandler\LogErrorHandler;
11+
use Mezzio\ProblemDetails\ProblemDetailsMiddleware;
12+
use Psr\Container\ContainerExceptionInterface;
13+
use Psr\Container\ContainerInterface;
14+
use Psr\Container\NotFoundExceptionInterface;
15+
use Psr\Http\Message\RequestInterface;
16+
use Psr\Http\Message\ServerRequestInterface;
17+
use Throwable;
18+
19+
use function assert;
20+
21+
class ProblemDetailsDelegatorFactory
22+
{
23+
/**
24+
* @param class-string $name
25+
* @throws ContainerExceptionInterface
26+
* @throws NotFoundExceptionInterface
27+
* @throws RuntimeException
28+
*/
29+
public function __invoke(
30+
ContainerInterface $container,
31+
string $name,
32+
callable $callback
33+
): ProblemDetailsMiddleware {
34+
if (! $container->has(ErrorHandlerInterface::class)) {
35+
throw RuntimeException::create(Message::serviceNotFound(ErrorHandlerInterface::class));
36+
}
37+
38+
$problemDetailsMiddleware = $callback();
39+
assert($problemDetailsMiddleware instanceof ProblemDetailsMiddleware);
40+
41+
$errorHandler = $container->get(ErrorHandlerInterface::class);
42+
assert($errorHandler instanceof LogErrorHandler);
43+
44+
$listener = function (Throwable $throwable, RequestInterface $request) use ($errorHandler) {
45+
assert($request instanceof ServerRequestInterface);
46+
$errorHandler->handleThrowable($throwable, $request);
47+
};
48+
49+
$problemDetailsMiddleware->attachListener($listener);
50+
51+
return $problemDetailsMiddleware;
52+
}
53+
}

src/App/src/Handler/GetIndexResourceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
public function handle(ServerRequestInterface $request): ResponseInterface
3030
{
3131
return $this->jsonResponse([
32-
'message' => sprintf('%s version %s', $this->config['name'], $this->config['version']),
32+
'message' => sprintf('%s version %s', $this->config['name'], $this->config['version'] ?? 'X'),
3333
]);
3434
}
3535
}

src/App/src/Middleware/ResponseMiddleware.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)