Slim 4 - Custom Request (extending the existing Request)

the more i think about your use case the more i think this “could” be handled via a middleware and inject an attribute into the normal request

something along the lines of:
Middleware whatevers

public function __invoke(Request $request, RequestHandler $handler): Response {
        $post = array();
        foreach ((array)$request->getParsedBody() as $key=>$value){
            $post[$key]=funky_moneky_dance_santize($value);
        }
        $request->withAttribute("post",$post);
        return $handler->handle($request);
    }

or just return the post as an argument but that could get a bit confusing if you have a get and a post that are the same type thing hence why im separating them out into their own here post “namespace”.

then just in your route

 $request->getAttribute('post')['moonshine'] ?? null;

this way you dont need to extend any existing files etc.


edit: adding my motivation for the question in OP to its own post just to get my post count up (more like cause this post is about answering @dunkoh’s post whereas mine is more a general at the thread post)