<commit_before><?php
namespace FrontendBridge\Lib;

trait FrontendBridgeTrait
{

    /**
     * jsonActionResponse
     *
     * @param \Cake\Network\Response $response the response
     * @return \FrontendBridge\Lib\ServiceResponse
     */
    protected function jsonActionResponse(\Cake\Network\Response $response)
    {
        // get the frontendData set by the Frontend plugin and remove unnecessary data
        $frontendData = $this->viewVars['frontendData'];
        unset($frontendData['Types']);
        $response = array(
            'code' => 'success',
            'data' => array(
                'frontendData' => $frontendData,
                'html' => $response->body()
            )
        );
        return new \FrontendBridge\Lib\ServiceResponse($response);
    }

    /**
     * renderJsonAction
     *
     * @param string $view   the view to render
     * @param string $layout the layout to render
     * @return \FrontendBridge\Lib\ServiceResponse
     */
    public function renderJsonAction($view, $layout)
    {
        if ($layout === null) {
            $layout = 'FrontendBridge.json_action';
        }
        if ($this->RequestHandler) {
            $this->RequestHandler->renderAs($this, 'ajax');
        }
        $response = parent::render($view, $layout);
        return $this->jsonActionResponse($response);<commit_msg>fix incompatibility with CakePHP 3.1 if RequestHandlerComponent is enabled.<commit_after><?php
namespace FrontendBridge\Lib;

trait FrontendBridgeTrait
{

    /**
     * jsonActionResponse
     *
     * @param \Cake\Network\Response $response the response
     * @return \FrontendBridge\Lib\ServiceResponse
     */
    protected function jsonActionResponse(\Cake\Network\Response $response)
    {
        // get the frontendData set by the Frontend plugin and remove unnecessary data
        $frontendData = $this->viewVars['frontendData'];
        unset($frontendData['Types']);
        $response = [
            'code' => 'success',
            'data' => [
                'frontendData' => $frontendData,
                'html' => $response->body()
            ]
        ];
        return new \FrontendBridge\Lib\ServiceResponse($response);
    }

    /**
     * renderJsonAction
     *
     * @param string $view   the view to render
     * @param string $layout the layout to render
     * @return \FrontendBridge\Lib\ServiceResponse
     */
    public function renderJsonAction($view, $layout)
    {
        if ($layout === null) {
            $layout = 'FrontendBridge.json_action';
        }
        if ($this->RequestHandler) {
            // Make sure the view is rendered as HTML, even if it is an AJAX request
            // jsonActionResponse() will make sure the JSON response is rendered correctly
            $this->RequestHandler->renderAs($this, 'ajax');
            $this->RequestHandler->ext = 'html';
        }
        $response = parent::render($view, $layout);
        return $this->jsonActionResponse($response);
{'fraction_non_alphanumeric': 0.11819699499165276, 'fraction_numerical': 0.000667779632721202, 'mean_word_length': 2.267175572519084, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4205119', 'n_tokens_mistral': 808, 'n_tokens_neox': 792, 'n_words': 192}