<commit_before><?php

namespace Bone\Mvc;

use Bone\Filter;
use Bone\Server\Environment;
use Exception;
use ReflectionClass;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\SapiEmitter;

/**
 * Class Dispatcher
 * @package Bone\Mvc
 */
class Dispatcher
{
    // Garrrr! An arrrray!
    private $config = array();

    /** @var ServerRequestInterface $request */
    private $request;

    /** @var Controller */
    private $controller;

    /** @var ResponseInterface $response */
    private $response;

    /** @var Environment $env */
    private $env;

    /**
     * Dispatcher constructor.
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @throws \Exception
     */
    public function __construct(ServerRequestInterface $request, ResponseInterface $response, Environment $env)
    {
        $this->request = $request;
        $this->response = $response;
        $this->env = $env;

        $router = new Router($request);
        $router->parseRoute();

        // what controller be we talkin' about?
        $filtered = Filter::filterString($router->getController(), 'DashToCamelCase');
        $this->config['controller_name'] = '\App\Controller\\' . ucwords($filtered) . 'Controller';

        // whit be yer action ?
        $filtered = Filter::filterString($router->getAction(), 'DashToCamelCase');
        $this->config['action_name'] = $filtered . 'Action';
        $this->config['controller'] = $router->getController();
        $this->config['action'] = $router->getAction();
        $this->config['params'] = $router->getParams();
    }


    /**
     *  Gaaarrr! Check the Navigator be readin' the map!
     * @return null|void
     */
    public function checkNavigator()
    {
        // can we find th' darned controller?
        if (!$this->checkControllerExists()) {
            $this->setNotFound();
            return;
        }

        // merge the feckin params
        if (is_array($this->config) && is_array($this->config['params'])) {
            $merged = array_merge($this->config['params'], $this->request->getQueryParams());
            $this->request = $this->request->withQueryParams($merged);
        }

        // create the controller
        $this->controller = new $this->config['controller_name']($this->request);
        $this->controller->setServerEnvironment($this->getEnv());

        // where's the bloody action?
        if (!$this->checkActionExists()) {
            $this->setNotFound();
        }
        return null;
    }

<commit_msg>tweak if<commit_after><?php

namespace Bone\Mvc;

use Bone\Filter;
use Bone\Server\Environment;
use Exception;
use ReflectionClass;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\SapiEmitter;

/**
 * Class Dispatcher
 * @package Bone\Mvc
 */
class Dispatcher
{
    /** @var array $config */
    private $config = [];

    /** @var ServerRequestInterface $request */
    private $request;

    /** @var Controller */
    private $controller;

    /** @var ResponseInterface $response */
    private $response;

    /** @var Environment $env */
    private $env;

    /**
     * Dispatcher constructor.
     * @param ServerRequestInterface $request
     * @param ResponseInterface $response
     * @throws \Exception
     */
    public function __construct(ServerRequestInterface $request, ResponseInterface $response, Environment $env)
    {
        $this->request = $request;
        $this->response = $response;
        $this->env = $env;

        $router = new Router($request);
        $router->parseRoute();

        // what controller be we talkin' about?
        $filtered = Filter::filterString($router->getController(), 'DashToCamelCase');
        $this->config['controller_name'] = '\App\Controller\\' . ucwords($filtered) . 'Controller';

        // whit be yer action ?
        $filtered = Filter::filterString($router->getAction(), 'DashToCamelCase');
        $this->config['action_name'] = $filtered . 'Action';
        $this->config['controller'] = $router->getController();
        $this->config['action'] = $router->getAction();
        $this->config['params'] = $router->getParams();
    }


    /**
     *  Gaaarrr! Check the Navigator be readin' the map!
     * @return null|void
     */
    public function checkNavigator()
    {
        // can we find th' darned controller?
        if (!$this->checkControllerExists()) {
            $this->setNotFound();
            return;
        }

        // merge the feckin params
        if (is_array($this->config['params']) && array_key_exists('params')) {
            $merged = array_merge($this->config['params'], $this->request->getQueryParams());
            $this->request = $this->request->withQueryParams($merged);
        }

        // create the controller
        $this->controller = new $this->config['controller_name']($this->request);
        $this->controller->setServerEnvironment($this->getEnv());

        // where's the bloody action?
        if (!$this->checkActionExists()) {
            $this->setNotFound();
        }
        return null;
    }


{'fraction_non_alphanumeric': 0.1518646674356017, 'fraction_numerical': 0.0, 'mean_word_length': 2.6692524682651624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, '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': '1742335', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1425, 'n_words': 312}