Skip to content

Commit

Permalink
Merge pull request #57 from JAK0TA/MiddlewareAction
Browse files Browse the repository at this point in the history
Clean up MiddlewareAbstract and MiddlewareActionAbstract
  • Loading branch information
tlueder authored Mar 14, 2024
2 parents 4fed031 + bb50564 commit d1dafaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
16 changes: 1 addition & 15 deletions Classes/Middleware/MiddlewareAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

namespace JAKOTA\Typo3ToolBox\Middleware;

use InvalidArgumentException;
use JAKOTA\Typo3ToolBox\Definition\ContentTypeDefinition;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use RuntimeException;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -28,21 +26,11 @@ abstract class MiddlewareAbstract implements MiddlewareInterface {
*/
protected $pathParams = [];

/**
* @var array<mixed>
*/
protected $queryParams = [];

/**
* @var ServerRequestInterface
*/
protected $request;

/**
* @var array<mixed>|object
*/
protected $requestBody = [];

/**
* @var ?ResponseInterface
*/
Expand All @@ -60,9 +48,7 @@ public function __construct(ResponseFactoryInterface $responseFactory) {
public function checkRequest(string $path, callable $callable, string $method): void {
if ($this->request->getMethod() == $method) {
if ($this->isPathWithQuery($path) || $this->isPath($path) || $this->isRequestTarget($path)) {
$this->requestBody = $this->request->getParsedBody() ?? [];
$this->queryParams = $this->request->getQueryParams();
$this->response = $callable($this->queryParams, $this->pathParams[$path] ?? [], $this->requestBody);
$this->response = $callable($this->pathParams[$path] ?? []);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Classes/Middleware/MiddlewareActionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ abstract class MiddlewareActionAbstract extends ApiAbstract {
*/
protected array $queryParams = [];

/**
* @var array<mixed>|object
*/
protected $requestBody = [];

protected ServerRequestInterface $request;

protected ?Site $site;
Expand All @@ -55,6 +60,7 @@ public function __construct(ServerRequestInterface $request, $pathParams) {
$this->request = $request;
$this->pathParams = $pathParams;
$this->queryParams = $this->request->getQueryParams();
$this->requestBody = $this->request->getParsedBody() ?? [];
$this->site = $this->request->getAttribute('site');

$langId = $this->queryParams['L'] ?? false;
Expand Down

0 comments on commit d1dafaf

Please sign in to comment.