<commit_before><?php

namespace wcf\action;

use wcf\system\exception\AJAXException;
use wcf\system\exception\IllegalLinkException;
use wcf\util\JSON;
use wcf\util\StringUtil;

/**
 * Abstract implementation of an action that displays a dialog and that is executed
 * in multiple steps.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\Action
 */
abstract class AbstractDialogAction extends AbstractSecureAction
{
    /**
     * current step
     * @var string
     */
    public $step = '';

    /**
     * template name
     * @var string
     */
    public $templateName = '';

    /**
     * response data
     * @var array
     */
    public $data = [];

    /**
     * @inheritDoc
     */
    public function readParameters()
    {
        parent::readParameters();

        if (empty($this->templateName)) {
            throw new IllegalLinkException();
        }

        if (isset($_REQUEST['step'])) {
            $this->step = StringUtil::trim($_REQUEST['step']);

            // append step as part of template name
            $this->templateName .= StringUtil::firstCharToUpperCase($this->step);
        }

        $this->validateStep();
    }

    /**
     * @inheritDoc
     */
    final public function execute()
    {
        parent::execute();

        $methodName = 'step' . StringUtil::firstCharToUpperCase($this->step);
        if (!\method_exists($this, $methodName)) {
            throw new AJAXException("Class '" . static::class . "' does not implement the required method '" . $methodName . "'");
        }

        // execute step
        $this->{$methodName}();

        $this->executed();

        // send JSON-encoded response
        \header('Content-type: application/json; charset=UTF-8');
        echo JSON::encode($this->data);

        exit;
    }
<commit_msg>Use PSR-7 responses in AbstractDialogAction<commit_after><?php

namespace wcf\action;

use Laminas\Diactoros\Response\JsonResponse;
use wcf\system\exception\AJAXException;
use wcf\system\exception\IllegalLinkException;
use wcf\util\StringUtil;

/**
 * Abstract implementation of an action that displays a dialog and that is executed
 * in multiple steps.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\Action
 */
abstract class AbstractDialogAction extends AbstractSecureAction
{
    /**
     * current step
     * @var string
     */
    public $step = '';

    /**
     * template name
     * @var string
     */
    public $templateName = '';

    /**
     * response data
     * @var array
     */
    public $data = [];

    /**
     * @inheritDoc
     */
    public function readParameters()
    {
        parent::readParameters();

        if (empty($this->templateName)) {
            throw new IllegalLinkException();
        }

        if (isset($_REQUEST['step'])) {
            $this->step = StringUtil::trim($_REQUEST['step']);

            // append step as part of template name
            $this->templateName .= StringUtil::firstCharToUpperCase($this->step);
        }

        $this->validateStep();
    }

    /**
     * @inheritDoc
     */
    final public function execute()
    {
        parent::execute();

        $methodName = 'step' . StringUtil::firstCharToUpperCase($this->step);
        if (!\method_exists($this, $methodName)) {
            throw new AJAXException("Class '" . static::class . "' does not implement the required method '" . $methodName . "'");
        }

        // execute step
        $this->{$methodName}();

        $this->executed();

        return new JsonResponse($this->data);
    }

{'fraction_non_alphanumeric': 0.13637555730396014, 'fraction_numerical': 0.004720692368214005, 'mean_word_length': 2.3280977312390925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '257469', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1044, 'n_words': 248}