<commit_before><?php

/**
 * SilverEngine  - PHP MVC framework
 *
 * @package   SilverEngine
 * @author    SilverEngine Team
 * @copyright 2015-2017
 * @license   MIT
 * @link      https://github.com/SilverEngine/Framework
 */

namespace Silver\Http;

use Silver\Core\Route;
use Silver\Core\Blueprints\Http\RequestInterface;
use Silver\Core\AppInstanceTrait;

/**
 * Class Request
 *
 * @package Silver\Http
 */
class Request implements RequestInterface
{
    /**
     * this is an array of the available http methods
     *
     * @var array
     */
    private $methods = ['get', 'post', 'put', 'delete', 'patch', 'options'];

    /**
     * requested http uri
     *
     * @var null
     */
    private $uri;

    /**
     * traits
     */
    use AppInstanceTrait;


    /**
     * Request constructor.
     * initialize requeted uri
     */
    public function __construct()
    {
        $this->uri = isset($_GET['uri']) ? $_GET['uri'] : "/";
    }

    /**<commit_msg>fix uri issue for none apache users<commit_after><?php

/**
 * SilverEngine  - PHP MVC framework
 *
 * @package   SilverEngine
 * @author    SilverEngine Team
 * @copyright 2015-2017
 * @license   MIT
 * @link      https://github.com/SilverEngine/Framework
 */

namespace Silver\Http;

use Silver\Core\Route;
use Silver\Core\Blueprints\Http\RequestInterface;
use Silver\Core\AppInstanceTrait;

/**
 * Class Request
 *
 * @package Silver\Http
 */
class Request implements RequestInterface
{
    /**
     * this is an array of the available http methods
     *
     * @var array
     */
    private $methods = ['get', 'post', 'put', 'delete', 'patch', 'options'];

    /**
     * requested http uri
     *
     * @var null
     */
    private $uri;

    /**
     * traits
     */
    use AppInstanceTrait;


    /**
     * Request constructor.
     * initialize requeted uri
     */
    public function __construct()
    {
        // load uri from 
        $this->uri = $this->getStrippedUri();
    }

    /**
     * Load data from global $_SERVER
     * @param  string  $key
     * @param  $default
     * @return string
     */
    public function server($key, $default = false)
    {
        if ( isset($_SERVER[$key]) ) {
            return $_SERVER[$key];
        }

        return $default;
    }

    /**
     * Strip uri.
     * @return string
     */
    public function getStrippedUri()
    {
        // /sitename/index.php
        $path = explode('/', trim($this->server('SCRIPT_NAME', '/')));

        // /sitename/portfolio/design
        $uri  = explode('/', trim($this->server('REQUEST_URI'), '/'));

        // strip file.
        foreach ($path as $key => $val) {
            if (isset($uri[$key]) && $val == $uri[$key]) { unset($uri[$key]); } 
            else break;
        }

        // portfolio/design
        $uri = implode('/', $uri);

        // strip $_GET
        $uri = explode('?', $uri);
        return '/' . $uri[0];
    }


    /**
{'fraction_non_alphanumeric': 0.1531654186521443, 'fraction_numerical': 0.005786249149081007, 'mean_word_length': 1.983756345177665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '1322354', 'n_tokens_mistral': 912, 'n_tokens_neox': 873, 'n_words': 215}