<commit_before><?php
/**
 * User: <NAME>
 * Date: 27.11.2016
 * Time: 02:09
 */

namespace femtimo\engine;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernel;

/**
 * Class BaseController
 * @package femtimo\engine
 */
class BaseController
{
    /** @var  \Symfony\Component\DependencyInjection\Container */
    protected $container;

    /** @var  RedirectResponse $redirect */
    protected $redirect;

    protected $action;

    protected $controller;

    /**
     * @var
     */
    protected $json;

    /**
     * BaseController constructor.
     * @param $request Request
     * @param $container Container
     * @param $from array
     */
    public function __construct($request, $container, $from)
    {
        /** @var Request request */
        $this->request = $request;
        /** @var Container container */
        $this->container = $container;

        $this->action = $from['action'];
        $this->controller = $from['controller'];

        /*
         * If a class authentication available,
         * check if we're in. If not move to AuthenticationController->indexAction
         * */
        if (is_object($this->container->get('authentication'))) {
            if ($this->container->get('authentication')->login() === false) {
                $this->redirect('authentication', 'index');
            }
        }
    }

    /**
     * @return \Symfony\Component\DependencyInjection\Container
     */
    protected function getContainer()
    {
        return $this->container;
    }

    /**
     * @param $controller
     * @param $action
     * @param int $status
     */
    protected function redirect($controller, $action, $status = 302)
    {
        if ($this->controller != $controller) {
            if ($this->action != $action) {
                $response = new RedirectResponse("$controller" . DIRECTORY_SEPARATOR . "$action");
                $response->setStatusCode($status);
                $this->redirect = $response;
            }
        }
    }

    /**
     * @param $controller
     * @param $action
     * @param null $params
     * @return int|RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    protected function forward($controller, $action, $params = null)
    {
        if ($this->controller != $controller) {
            if ($this->action != $action) {
                if (isset($params)) {
                    $this->request->attributes->add($params);
                }

                $subRequest = $this->request->duplicate(
                    array_merge($this->request->query->all(), $params),
                    array_merge($this->request->request->all(), $params),
                    null,
                    null,
                    null,
                    array_merge($this->request->server->all(), [
                        'REQUEST_URI' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                        'REDIRECT_URL' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                    ]));
                return ((new Kernel())->handle($subRequest, HttpKernel::SUB_REQUEST));
            }
        }
    }

    /**
     * @return RedirectResponse
     */
    public function isRedirect()
    {
        return $this->redirect;
    }

    /**
     * @return mixed
     */
    public function isJson()
    {
        return $this->json;
    }

    /** @param $json array */
    public function setXHR($json)<commit_msg>changed redirect and forwarding check<commit_after><?php
/**
 * User: <NAME>
 * Date: 27.11.2016
 * Time: 02:09
 */

namespace femtimo\engine;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernel;

/**
 * Class BaseController
 * @package femtimo\engine
 */
class BaseController
{
    /** @var  \Symfony\Component\DependencyInjection\Container */
    protected $container;

    /** @var  RedirectResponse $redirect */
    protected $redirect;

    protected $action;

    protected $controller;

    /**
     * @var
     */
    protected $json;

    /**
     * BaseController constructor.
     * @param $request Request
     * @param $container Container
     * @param $from array
     */
    public function __construct($request, $container, $from)
    {
        /** @var Request request */
        $this->request = $request;
        /** @var Container container */
        $this->container = $container;

        $this->action = $from['action'];
        $this->controller = $from['controller'];

        /*
         * If a class authentication available,
         * check if we're in. If not move to AuthenticationController->indexAction
         * */
        if (is_object($this->container->get('authentication'))) {
            if ($this->container->get('authentication')->login() === false) {
                $this->redirect('authentication', 'index');
            }
        }
    }

    /**
     * @return \Symfony\Component\DependencyInjection\Container
     */
    protected function getContainer()
    {
        return $this->container;
    }

    /**
     * @param $controller
     * @param $action
     * @param int $status
     */
    protected function redirect($controller, $action, $status = 302)
    {
        if (strcmp($this->controller, $controller) !== 0) {
            if ($this->action != $action) {
                $response = new RedirectResponse("$controller" . DIRECTORY_SEPARATOR . "$action");
                $response->setStatusCode($status);
                $this->redirect = $response;
            }
        }
        else{
            if(strcmp($this->action, $action) !== 0){
                $response = new RedirectResponse("$controller" . DIRECTORY_SEPARATOR . "$action");
                $response->setStatusCode($status);
                $this->redirect = $response;
            }
        }
    }

    /**
     * @param $controller
     * @param $action
     * @param null $params
     * @return int|RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    protected function forward($controller, $action, $params = null)
    {

        if (strcmp($this->controller, $controller) !== 0) {
            if ($this->action != $action) {
                if ($this->action != $action) {
                    if (isset($params)) {
                        $this->request->attributes->add($params);
                    }

                    $subRequest = $this->request->duplicate(
                        array_merge($this->request->query->all(), $params),
                        array_merge($this->request->request->all(), $params),
                        null,
                        null,
                        null,
                        array_merge($this->request->server->all(), [
                            'REQUEST_URI' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                            'REDIRECT_URL' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                        ]));
                    return ((new Kernel())->handle($subRequest, HttpKernel::SUB_REQUEST));
                }
            }
        }
        else{
            if(strcmp($this->action, $action) !== 0){
                if ($this->action != $action) {
                    if (isset($params)) {
                        $this->request->attributes->add($params);
                    }

                    $subRequest = $this->request->duplicate(
                        array_merge($this->request->query->all(), $params),
                        array_merge($this->request->request->all(), $params),
                        null,
                        null,
                        null,
                        array_merge($this->request->server->all(), [
                            'REQUEST_URI' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                            'REDIRECT_URL' => DIRECTORY_SEPARATOR . "$controller" . DIRECTORY_SEPARATOR . "$action",
                        ]));
                    return ((new Kernel())->handle($subRequest, HttpKernel::SUB_REQUEST));
                }
            }
        }
    }

    /**
     * @return RedirectResponse
     */
    public function isRedirect()
    {
        return $this->redirect;
    }

    /**
     * @return mixed
     */
    public function isJson()
    {
        return $this->json;
    }

    /** @param $json array */
    public function setXHR($json)
{'fraction_non_alphanumeric': 0.13944954128440368, 'fraction_numerical': 0.0038990825688073397, 'mean_word_length': 1.7580645161290323, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 102, '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': '3711141', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2214, 'n_words': 438}