<commit_before><?php namespace Rakit\Framework\Http;

use Rakit\Framework\App;
use Rakit\Framework\Bag;
use Rakit\Framework\MacroableTrait;
use Rakit\Framework\Router\Route;

class Request {

    use MacroableTrait;

    const METHOD_GET = 'GET';
    const METHOD_POST = 'POST';
    const METHOD_PUT = 'PUT';
    const METHOD_PATCH = 'PATCH';
    const METHOD_DELETE = 'DELETE';

    protected $route;

    public $params = array();

    public function __construct(App $app, Route $route = null)
    {
        if($route) $this->defineRoute($route);
        $this->app = $app;

        $this->inputs = new Bag((array) $_POST + (array) $_GET);
        $this->files = new Bag((array) $_FILES);
        $this->server = new Bag($_SERVER);
    }

    public function path()
    {
        $path_info = $this->server->get('PATH_INFO');

        if(!$path_info) {
            $request_uri = $this->server->get('REQUEST_URI');
            $script_name = $this->server->get('SCRIPT_NAME');
            $path_info = str_replace($script_name, '', $request_uri);
            $path_info = explode('?', $path_info, 2)[0];
        }

        return '/'.trim($path_info, '/');
    }

    public function segment($index)
    {
        $paths = explode('/', $this->path());
        return isset($paths[$index])? $paths[$index] : null;
    }

    public function all()
    {
        $all_inputs = $this->inputs->all();
        $all_files = $this->files->all();
        foreach($all_files as $key => $value) {
            $all_files[$key] = $this->hasMultiFiles($key)? $this->multiFiles($key) : $this->file($key);
        }

        return array_merge($all_inputs, $all_files);
    }

    public function has($key)
    {
        return $this->inputs->has($key);
    }

    public function get($key, $default = null)<commit_msg>fixing request path bug<commit_after><?php namespace Rakit\Framework\Http;

use Rakit\Framework\App;
use Rakit\Framework\Bag;
use Rakit\Framework\MacroableTrait;
use Rakit\Framework\Router\Route;

class Request {

    use MacroableTrait;

    const METHOD_GET = 'GET';
    const METHOD_POST = 'POST';
    const METHOD_PUT = 'PUT';
    const METHOD_PATCH = 'PATCH';
    const METHOD_DELETE = 'DELETE';

    protected $route;

    public $params = array();

    public function __construct(App $app, Route $route = null)
    {
        if($route) $this->defineRoute($route);
        $this->app = $app;

        $this->inputs = new Bag((array) $_POST + (array) $_GET);
        $this->files = new Bag((array) $_FILES);
        $this->server = new Bag($_SERVER);
    }

    public function path()
    {
        $path_info = $this->server->get('PATH_INFO');

        if(!$path_info) {
            $request_uri = $this->server->get('REQUEST_URI');
            $script_name = $this->server->get('SCRIPT_NAME');
            if (pathinfo($script_name, PATHINFO_EXTENSION) == 'php') {
                $path_info = str_replace($script_name, '', $request_uri);
            }  else {
                $path_info = $request_uri;
            }
            
            $path_info = explode('?', $path_info, 2)[0];
        }

        return '/'.trim($path_info, '/');
    }

    public function segment($index)
    {
        $paths = explode('/', $this->path());
        return isset($paths[$index])? $paths[$index] : null;
    }

    public function all()
    {
        $all_inputs = $this->inputs->all();
        $all_files = $this->files->all();
        foreach($all_files as $key => $value) {
            $all_files[$key] = $this->hasMultiFiles($key)? $this->multiFiles($key) : $this->file($key);
        }

        return array_merge($all_inputs, $all_files);
    }

    public function has($key)
    {
        return $this->inputs->has($key);
    }

    public function get($key, $default = null)
{'fraction_non_alphanumeric': 0.16574294008973345, 'fraction_numerical': 0.0010556875164951175, 'mean_word_length': 2.480257116620753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '3353305', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1187, 'n_words': 241}