Hi everyone,
I’m currently developing my first extbase Extension. I need to handle an AJAX request from the frontend, and after some reading I decided to go with a Middleware-Class. My Problem: I configured everything as decribed in the docs but somehow I’m missing something because the dependency injection doesn’t work:
This is my php-Class:
<?php
namespace Feyerabend\RiddlePack\Middleware;
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;
/**
* AnswerFormHandler
*/
class AnswerFormHandler implements MiddlewareInterface
{
/** @var ResponseFactoryInterface */
private $responseFactory;
/**
* @param \Psr\Http\Message\ResponseFactoryInterface\ResponseFactoryInterface $responseFactory
*/
public function __construct(ResponseFactory $responseFactory)
{
$this->responseFactory = $responseFactory;
}
/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Server\RequestHandlerInterface $handler
* @return \Psr\Http\Message\ResponseInterface
*/
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
if ($request->getRequestTarget() === '/answers') {
$data = ['status' => 'ok'];
$response = $this->responseFactory->createResponse()
->withHeader('Content-Type', 'application/json; charset=utf-8');
$response->getBody()->write(json_encode($data));
return $response;
}
return $handler->handle($request);
}
}
My Services.yaml looks like this:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Feyerabend\RiddlePack\:
resource: '../Classes/*'
This is basically just the example code from the docs but it still doesn’t work.
It produces the following error:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: Too few arguments to function Feyerabend\RiddlePack\Middleware\AnswerFormHandler::__construct(), 0 passed in /var/typo3_src-9.5.22/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 3689 and exactly 1 expected | ArgumentCountError thrown in file /var/www/html/typo3conf/ext/riddle_pack/Classes/Middleware/AnswerFormHandler.php in line 34.
Thank’s in advance for your Help