Skip to content

Commit

Permalink
middleware with context
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrnik committed Apr 14, 2024
1 parent 854d495 commit 700eaa1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Content/MiddlewareWithContextInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Zrnik\Zweist\Content;

interface MiddlewareWithContextInterface
Expand Down
4 changes: 2 additions & 2 deletions src/ZweistOpenApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ZweistOpenApiGenerator extends Generator implements ProcessorInterface
{
public function __construct(
private readonly ZweistConfiguration $zweistConfiguration,
?LoggerInterface $logger = null,
?LoggerInterface $logger = null,
)
{
parent::__construct($logger);
Expand Down Expand Up @@ -61,7 +61,7 @@ public function __invoke(Analysis $analysis): void
/** @var class-string $class */
$class = sprintf('%s\%s', $annotation->_context->namespace, $annotation->_context->class);

$method = (string)$annotation->_context->method;
$method = (string) $annotation->_context->method;

$middlewareData = [];

Expand Down
2 changes: 1 addition & 1 deletion src/ZweistRouteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ZweistRouteService
{
public function __construct(
private readonly ZweistConfiguration $zweistConfiguration,
private readonly ContainerInterface $container,
private readonly ContainerInterface $container,
)
{
}
Expand Down
9 changes: 5 additions & 4 deletions tests/ExampleApplication/Controllers/HelloWorldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Zrnik\Zweist\Content\JsonContentFacade;
use Zrnik\Zweist\Tests\ExampleApplication\ExampleClassMiddleware;
use Zrnik\Zweist\Tests\ExampleApplication\ExampleMiddleware;
use Zrnik\Zweist\Tests\ExampleApplication\ExampleMiddlewareWithContext;

#[Middleware(ExampleClassMiddleware::class)]
class HelloWorldController
Expand Down Expand Up @@ -46,12 +45,14 @@ public function __construct()
content: new JsonContent(ref: TestResponse::class)
),
Middleware(ExampleMiddleware::class),
Middleware(ExampleMiddleware::class, ['context' => 'value']),
Middleware(ExampleMiddleware::class, [
'context' => 'value',
]),
]
public function sayHello(
RequestInterface $request,
RequestInterface $request,
ResponseInterface $response,
array $arguments = []
array $arguments = []
): ResponseInterface
{
return $this->jsonContentFacade->updateResponse(
Expand Down
4 changes: 3 additions & 1 deletion tests/ExampleApplication/ExampleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
class ExampleMiddleware implements MiddlewareInterface, MiddlewareWithContextInterface
{
public const CONTEXT_HEADER_NAME = 'X-Test-Middleware-Context';

public const VALUE_HEADER_NAME = 'X-Test-Middleware-Called';

public const VALUE_HEADER_VALUE = 'true';

private mixed $context;
Expand All @@ -24,7 +26,7 @@ public function setContext(mixed $context): void
}

public function process(
ServerRequestInterface $request,
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface
{
Expand Down
1 change: 0 additions & 1 deletion tests/MiddlewareAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Psr\Log\LoggerInterface;
use Slim\App;
use Zrnik\Zweist\Tests\ExampleApplication\ExampleMiddleware;
use Zrnik\Zweist\Tests\ExampleApplication\ExampleMiddlewareWithContext;
use Zrnik\Zweist\ZweistConfiguration;
use Zrnik\Zweist\ZweistOpenApiGenerator;
use Zrnik\Zweist\ZweistRouteService;
Expand Down

0 comments on commit 700eaa1

Please sign in to comment.