Skip to content

Commit 3e7dd9f

Browse files
committed
Support middleware behavior for action result encoder
1 parent 88e10f1 commit 3e7dd9f

File tree

3 files changed

+135
-2
lines changed

3 files changed

+135
-2
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"activecollab/utils": "^2.0",
1616
"psr/http-factory": "^1.0",
1717
"psr/http-message": "^1.0",
18+
"psr/http-server-middleware": "^1.0",
1819
"psr/log": "~1.0",
1920
"laminas/laminas-diactoros": "^2.8"
2021
},

composer.lock

+115-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ActionResultEncoder/ActionResultEncoder.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
use ActiveCollab\ContainerAccess\ContainerAccessInterface\Implementation as ContainerAccessImplementation;
1515
use ActiveCollab\Controller\ActionResult\Container\ActionResultContainerInterface;
1616
use ActiveCollab\Controller\ActionResultEncoder\ValueEncoder\ValueEncoderInterface;
17+
use LogicException;
1718
use Psr\Http\Message\ResponseInterface;
1819
use Psr\Http\Message\ServerRequestInterface;
20+
use Psr\Http\Server\MiddlewareInterface;
21+
use Psr\Http\Server\RequestHandlerInterface;
1922
use Psr\Log\LoggerInterface;
2023
use RuntimeException;
2124

22-
class ActionResultEncoder implements ActionResultEncoderInterface, ContainerAccessInterface
25+
class ActionResultEncoder implements ActionResultEncoderInterface, ContainerAccessInterface, MiddlewareInterface
2326
{
2427
use ContainerAccessImplementation;
2528

@@ -99,6 +102,21 @@ public function &addValueEncoder(ValueEncoderInterface ...$value_encoders): Acti
99102
return $this;
100103
}
101104

105+
public function process(
106+
ServerRequestInterface $request,
107+
RequestHandlerInterface $handler
108+
): ResponseInterface
109+
{
110+
if (!$this->getEncodeOnExit()) {
111+
throw new LogicException('Action result can be encoded after handling only.');
112+
}
113+
114+
return $this->tryToEncodeValue(
115+
$handler->handle($request),
116+
$this->action_result_container
117+
);
118+
}
119+
102120
public function __invoke(
103121
ServerRequestInterface $request,
104122
ResponseInterface $response,

0 commit comments

Comments
 (0)