<commit_before><?php
namespace Webaholicson\Minimvc\Core;

class Request
{
    /**
     * @var array Options from the config
     */
    private $options;
    
    /**
     * @var array Request headers
     */
    protected $_headers = array();

    /**
     * @var string Request uri
     */
    protected $_path;
    
    /**
     * @var string Request method
     */
    protected $_method;
    
    /**
     * @var string Request url query string
     */
    protected $_query;

    /**
     * @var string Request scheme
     */
    protected $_scheme;
    
    /**
     * @var string Server host name 
     */
    protected $_host;
    
    /**
     * @var string Applications base uri
     */
    protected $_baseUri;
    
    /**
     * Instantiate the class and parse the url string if there is one.
     * @param string $url
     */
    public function __construct($url = '')
    {
        if ($url) {
            $options = parse_url($url);
            array_walk($options, function($value, &$key) {
                $key = '_' . $key;
            });
            
            $this->init($options);
        }
        
         if (!$this->options) {
                include 'config/config.php';
                $this->init($config['request']->get());
            }
    }
    
    /**
     * Initialize the request using an array of options
     * 
     * @param array $options
     * @return \Webaholicson\Minimvc\Core\Request
     */
    public function init($options)
    {
        if (!$options) {
            return $this;
        }
        
        $this->options = $options;

        foreach ($options as $key => $value) {
            if (property_exists('Request', '_'.$key)) {
                $this->key = $value;
            }
        }

        $this->_normalizeUri();
        return $this;
    }
    
    /**
     * Normalize the uri so it matches registered routes
     */
    protected function _normalizeUri()
    {
        $parts = explode('?', $this->options['path']);
        $this->options['path'] = $parts[0];

        if (substr($this->options['path'], -1) == '/') {
            $this->_path = substr($this->options['path'], 0, -1);
        } else {
            $this->_path = $this->options['path'];
        }

        $this->_path = str_replace(
            $this->options['baseUri'],
            '',
            $this->_path
        );

        if (!$this->_path) $this->_path = '/';
    }
    <commit_msg>Normalized the uri some more<commit_after><?php
namespace Webaholicson\Minimvc\Core;

class Request
{
    /**
     * @var array Options from the config
     */
    private $options;
    
    /**
     * @var array Request headers
     */
    protected $_headers = array();

    /**
     * @var string Request uri
     */
    protected $_path;
    
    /**
     * @var string Request method
     */
    protected $_method;
    
    /**
     * @var string Request url query string
     */
    protected $_query;

    /**
     * @var string Request scheme
     */
    protected $_scheme;
    
    /**
     * @var string Server host name 
     */
    protected $_host;
    
    /**
     * @var string Applications base uri
     */
    protected $_baseUri;
    
    /**
     * Instantiate the class and parse the url string if there is one.
     * @param string $url
     */
    public function __construct($url = '')
    {
        if ($url) {
            $options = parse_url($url);
            array_walk($options, function($value, &$key) {
                $key = '_' . $key;
            });
            
            $this->init($options);
        }
        
         if (!$this->options) {
                include 'config/config.php';
                $this->init($config['request']->get());
            }
    }
    
    /**
     * Initialize the request using an array of options
     * 
     * @param array $options
     * @return \Webaholicson\Minimvc\Core\Request
     */
    public function init($options)
    {
        if (!$options) {
            return $this;
        }
        
        $this->options = $options;

        foreach ($options as $key => $value) {
            if (property_exists('Request', '_'.$key)) {
                $this->key = $value;
            }
        }

        $this->_normalizeUri();
        return $this;
    }
    
    /**
     * Normalize the uri so it matches registered routes
     */
    protected function _normalizeUri()
    {
        $parts = explode('?', $this->options['path']);
        $this->options['path'] = $parts[0];

        if (substr($this->options['path'], -1) == '/') {
            $this->_path = substr($this->options['path'], 0, -1);
        } else {
            $this->_path = $this->options['path'];
        }

        $this->_path = '/' . ltrim(str_replace(
            array($this->options['baseUri'], 'index.php'),
            array('', ''),
            $this->_path
        ), '/');

        if (!$this->_path) $this->_path = '/';
    }
    
{'fraction_non_alphanumeric': 0.15115337919870497, 'fraction_numerical': 0.0016187778227438284, 'mean_word_length': 1.4789368104312939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1736002', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1397, 'n_words': 328}