<commit_before><?php
/**
 * Just Framework - It's a PHP micro-framework for Full Stack Web Developer
 *
 * @package     Just Framework
 * @copyright   2016 (c) <NAME>
 * @author      <NAME> <http://nezamy.com>
 * @link        http://justframework.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT
 * @version     1.0.0
 */
namespace System;
/**
 * Request
 *
 * @package     Just Framework
 * @author      <NAME> <http://nezamy.com>
 * @since       1.0.0
 */

class Request
{
    private static $instance;

    /**
     * Constructor - Define some variables.
     */
    public function __construct()
    {
        $this->server = $_SERVER;

        $uri    = parse_url($this->server["REQUEST_URI"], PHP_URL_PATH);
        $script = $_SERVER['SCRIPT_NAME'];
        $parent = dirname($script);

        // Fix path if not runing on domain or local domain.
        if (stripos($uri, $script) !== false) {
            $this->path = substr($uri, strlen($script));
        } elseif (stripos($uri, $parent) !== false) {
            $this->path = substr($uri, strlen($parent));
        } else {
            $this->path = $uri;
        }

        $this->path = preg_replace('/\/+/', '/', '/' . trim($this->path, '/') . '/');
        $this->hostname     = str_replace('/:(.*)$/', "", $_SERVER['HTTP_HOST']);
        $this->servername   = empty($_SERVER['SERVER_NAME']) ? $this->hostname : $_SERVER['SERVER_NAME'];
        $this->secure       = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
        $this->port         = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null;
        $this->protocol     = $this->secure ? 'https' : 'http';
        $this->url          = strtolower($this->protocol . '://' . $_SERVER['SERVER_NAME']) . '/';
        $this->curl         = rtrim($this->url, '/') . $this->path;
        $this->extension    = pathinfo($this->path, PATHINFO_EXTENSION);
        $this->headers      = call_user_func(function()
        {
            $r = [];
            foreach ($_SERVER as $k => $v)
            {
                if (stripos($k, 'http_') !== false) {
                    $r[strtolower(substr($k, 5))] = $v;
                }
            }
            return $r;
        });
        $this->method       = $_SERVER['REQUEST_METHOD'];
        $this->query        = $_GET;
        $this->args         = [];
        foreach ($this->query as $k => $v) {
            $this->query[$k] = preg_replace('/\/+/', '/', str_replace(['..', './'], ['', '/'], $v));
        }

        if (isset($this->headers['content_type']) && $this->headers['content_type'] == 'application/x-www-form-urlencoded') {
            parse_str(file_get_contents("php://input"), $input);
        } else {
            $input          = json_decode(file_get_contents("php://input"), true);
        }
        
        $this->body         = is_array($input) ? $input : [];<commit_msg>fix server name if empty<commit_after><?php
/**
 * Just Framework - It's a PHP micro-framework for Full Stack Web Developer
 *
 * @package     Just Framework
 * @copyright   2016 (c) <NAME>
 * @author      <NAME> <http://nezamy.com>
 * @link        http://justframework.com
 * @license     http://www.opensource.org/licenses/mit-license.php MIT
 * @version     1.0.0
 */
namespace System;
/**
 * Request
 *
 * @package     Just Framework
 * @author      <NAME> <http://nezamy.com>
 * @since       1.0.0
 */

class Request
{
    private static $instance;

    /**
     * Constructor - Define some variables.
     */
    public function __construct()
    {
        $this->server = $_SERVER;

        $uri    = parse_url($this->server["REQUEST_URI"], PHP_URL_PATH);
        $script = $_SERVER['SCRIPT_NAME'];
        $parent = dirname($script);

        // Fix path if not runing on domain or local domain.
        if (stripos($uri, $script) !== false) {
            $this->path = substr($uri, strlen($script));
        } elseif (stripos($uri, $parent) !== false) {
            $this->path = substr($uri, strlen($parent));
        } else {
            $this->path = $uri;
        }

        $this->path = preg_replace('/\/+/', '/', '/' . trim($this->path, '/') . '/');
        $this->hostname     = str_replace('/:(.*)$/', "", $_SERVER['HTTP_HOST']);
        $this->servername   = empty($_SERVER['SERVER_NAME']) ? $this->hostname : $_SERVER['SERVER_NAME'];
        $this->secure       = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
        $this->port         = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null;
        $this->protocol     = $this->secure ? 'https' : 'http';
        $this->url          = strtolower($this->protocol . '://' . $this->servername) . '/';
        $this->curl         = rtrim($this->url, '/') . $this->path;
        $this->extension    = pathinfo($this->path, PATHINFO_EXTENSION);
        $this->headers      = call_user_func(function()
        {
            $r = [];
            foreach ($_SERVER as $k => $v)
            {
                if (stripos($k, 'http_') !== false) {
                    $r[strtolower(substr($k, 5))] = $v;
                }
            }
            return $r;
        });
        $this->method       = $_SERVER['REQUEST_METHOD'];
        $this->query        = $_GET;
        $this->args         = [];
        foreach ($this->query as $k => $v) {
            $this->query[$k] = preg_replace('/\/+/', '/', str_replace(['..', './'], ['', '/'], $v));
        }

        if (isset($this->headers['content_type']) && $this->headers['content_type'] == 'application/x-www-form-urlencoded') {
            parse_str(file_get_contents("php://input"), $input);
        } else {
            $input          = json_decode(file_get_contents("php://input"), true);
        }
        
        $this->body         = is_array($input) ? $input : [];
{'fraction_non_alphanumeric': 0.20030922521903452, 'fraction_numerical': 0.0037794193437553684, 'mean_word_length': 1.9553299492385787, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7443112', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1757, 'n_words': 330}