<commit_before><?php namespace Flarum\Api\Middleware;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Zend\Stratigility\MiddlewareInterface;

class ReadJsonParameters implements MiddlewareInterface
{
    /**
     * {@inheritdoc}
     */
    public function __invoke(Request $request, Response $response, callable $out = null)
    {
        if (str_contains($request->getHeaderLine('content-type'), 'application/vnd.api+json')) {
            $input = json_decode($request->getBody(), true);

            foreach ($input as $name => $value) {
                $request = $request->withAttribute($name, $value);
            }
        }

        return $out ? $out($request, $response) : $response;
    }
}<commit_msg>Make JSON parameter middleware a bit more generic<commit_after><?php namespace Flarum\Api\Middleware;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Zend\Stratigility\MiddlewareInterface;

class ReadJsonParameters implements MiddlewareInterface
{
    /**
     * {@inheritdoc}
     */
    public function __invoke(Request $request, Response $response, callable $out = null)
    {
        if (str_contains($request->getHeaderLine('content-type'), 'json')) {
            $input = json_decode($request->getBody(), true);

            foreach ($input as $name => $value) {
                $request = $request->withAttribute($name, $value);
            }
        }

        return $out ? $out($request, $response) : $response;
    }
}
{'fraction_non_alphanumeric': 0.12786259541984732, 'fraction_numerical': 0.0, 'mean_word_length': 3.1613756613756614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138132', 'n_tokens_mistral': 436, 'n_tokens_neox': 429, 'n_words': 99}