Skip to content

Commit ccaa685

Browse files
committed
Update
1 parent 3cb6b7b commit ccaa685

File tree

3 files changed

+4
-87
lines changed

3 files changed

+4
-87
lines changed

Slim/Routing/PipelineOrder.php

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

Slim/Routing/PipelineRunner.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ final class PipelineRunner implements RequestHandlerInterface
2727
{
2828
private ContainerResolverInterface $resolver;
2929

30-
private PipelineOrder $order;
31-
3230
/**
3331
* @var array<int, mixed>
3432
*/
3533
private array $pipeline = [];
3634

37-
public function __construct(ContainerResolverInterface $resolver, PipelineOrder $order = PipelineOrder::FIFO)
35+
public function __construct(ContainerResolverInterface $resolver)
3836
{
3937
$this->resolver = $resolver;
40-
$this->order = $order;
4138
}
4239

4340
/**
@@ -51,26 +48,18 @@ public function withPipeline(array $pipeline): self
5148
return $clone;
5249
}
5350

54-
public function withOrder(PipelineOrder $order): self
55-
{
56-
$clone = clone $this;
57-
$clone->order = $order;
58-
59-
return $clone;
60-
}
61-
6251
public function handle(ServerRequestInterface $request): ResponseInterface
6352
{
64-
$entry = $this->order === PipelineOrder::FIFO
65-
? array_shift($this->pipeline)
66-
: array_pop($this->pipeline);
53+
$entry = current($this->pipeline);
6754

6855
if (!$entry) {
6956
throw new RuntimeException('The middleware pipeline is empty.');
7057
}
7158

7259
$entry = $this->resolver->resolve($entry);
7360

61+
next($this->pipeline);
62+
7463
if ($entry instanceof MiddlewareInterface) {
7564
return $entry->process($request, $this);
7665
}

tests/RequestHandler/RunnerTest.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Psr\Http\Server\RequestHandlerInterface;
1515
use RuntimeException;
1616
use Slim\Factory\AppFactory;
17-
use Slim\Routing\PipelineOrder;
1817
use Slim\Routing\PipelineRunner;
1918
use stdClass;
2019

@@ -191,58 +190,4 @@ public function testHandleWithInvalidMiddlewareStringThrowsException(): void
191190

192191
$runner->handle($request);
193192
}
194-
195-
public function testHandleExecutesPipelineInLifoOrder(): void
196-
{
197-
$app = AppFactory::create();
198-
$container = $app->getContainer();
199-
200-
$request = $container
201-
->get(ServerRequestFactoryInterface::class)
202-
->createServerRequest('GET', '/');
203-
204-
$responseFactory = $container->get(ResponseFactoryInterface::class);
205-
206-
// This middleware will be executed LAST in LIFO mode (because it was added first).
207-
$first = new class implements MiddlewareInterface {
208-
public function process(
209-
ServerRequestInterface $request,
210-
RequestHandlerInterface $handler,
211-
): ResponseInterface {
212-
$response = $handler->handle($request);
213-
return $response->withHeader('X-Order', 'First');
214-
}
215-
};
216-
217-
// This middleware will be executed FIRST in LIFO mode.
218-
$second = new class implements MiddlewareInterface {
219-
public function process(
220-
ServerRequestInterface $request,
221-
RequestHandlerInterface $handler,
222-
): ResponseInterface {
223-
$response = $handler->handle($request);
224-
return $response->withHeader('X-Order', 'Second');
225-
}
226-
};
227-
228-
// Final handler that produces a basic response
229-
$finalHandler = fn() => $responseFactory->createResponse();
230-
231-
$runner = $container
232-
->get(PipelineRunner::class)
233-
->withOrder(PipelineOrder::LIFO)
234-
->withPipeline(
235-
[
236-
$finalHandler, // end
237-
$second, // ^ second
238-
$first, // ^ start
239-
],
240-
);
241-
242-
$response = $runner->handle($request);
243-
244-
$this->assertSame('First', $response->getHeaderLine('X-Order'));
245-
}
246-
247-
248193
}

0 commit comments

Comments
 (0)