<commit_before><?php
/**
 * Slim Framework (http://slimframework.com)
 *
 * @link      https://github.com/codeguy/Slim
 * @copyright Copyright (c) 2011-2015 <NAME>
 * @license   https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
 */
namespace Slim\Http;

/**
 * Value object representing a URI for use in HTTP requests.
 *
 * This interface is meant to represent only URIs for use with HTTP requests,
 * and is not intended as a general-purpose URI implementation.
 *
 * Instances of this interface are considered immutable; all methods that
 * might change state MUST be implemented such that they retain the internal
 * state of the current instance and return a new instance that contains the
 * changed state.
 *
 * Typically the Host header will be also be present in the request message.
 * For server-side requests, the scheme will typically be discoverable in the
 * server parameters.
 *
 * @link http://tools.ietf.org/html/rfc3986 (the URI specification)
 */
class Uri implements \Psr\Http\Message\UriInterface
{
    /**
     * Uri scheme (without "://" suffix)
     *
     * @var string
     */
    protected $scheme;

    /**
     * Uri user
     *
     * @var string
     */
    protected $user;

    /**
     * Uri password
     *
     * @var string
     */
    protected $password;

    /**
     * Uri host
     *
     * @var string
     */
    protected $host;

    /**
     * Uri port number
     *
     * @var int
     */
    protected $port;

    /**
     * Uri base path
     *
     * @var string
     */
    protected $basePath;

    /**
     * Uri path
     *
     * @var string
     */
    protected $path;

    /**
     * Uri query string (without "?" prefix)
     *
     * @var string
     */
    protected $query;

    /**
     * Create new Uri
     *
     * @param string $scheme   Uri scheme
     * @param string $user     Uri user
     * @param string $password Uri password
     * @param string $host     Uri host
     * @param int    $port     Uri port number
     * @param string $path     Uri path
     * @param string $query    Uri query string
     */
    public function __construct($scheme, $user, $password, $host, $port, $path, $query = '')
    {
        $this->scheme = $scheme;
        $this->user = $user;
        $this->password = $password;
        $this->host = $host;
        $this->port = $port;
        $this->path = $path;
        $this->query = $query;
    }

    /**
     * Create new Uri from string
     *
     * @param  string $uri Complete Uri string (i.e., https://user:pass@host:443/path?query)
     * @return self
     */
    public static function createFromString($uri)
    {
        if (is_string($uri) === false) {
            throw new \InvalidArgumentException('URI must be a string');
        }

        $parts = parse_url($uri);
        $scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
        $user = isset($parts['user']) ? $parts['user'] : '';
        $pass = isset($parts['pass']) ? $parts['pass'] : '';
        $host = isset($parts['host']) ? $parts['host'] : '';
        $port = isset($parts['port']) ? $parts['port'] : '';
        $path = isset($parts['path']) ? $parts['path'] : '';
        $query = isset($parts['query']) ? $parts['query'] : '';

        return new static($scheme, $user, $pass, $host, $port, $path, $query);
    }

    /**
     * Create new Uri from environment
     *
     * @param  Environment $env
     * @return self
     */
    public static function createFromEnvironment(Environment $env)
    {
        // Scheme
        if ($env->has('HTTP_X_FORWARDED_PROTO') === true) {
            $scheme = $env->get('HTTP_X_FORWARDED_PROTO');
        } else {
            $https = $env->get('HTTPS', '');
            $scheme = empty($https) || $https === 'off' ? 'http' : 'https';
        }

        // Authority
        // TODO: Respect trusted proxy X-Forwarded-* headers
        $user = $env->get('PHP_AUTH_USER', '');
        $password = $env->get('PHP_AUTH_PW', '');
        $host = $env->get('HTTP_HOST', $env->get('SERVER_NAME'));
        $port = $env->get('SERVER_PORT');

        // Path
        $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
        $requestScriptDir = dirname($requestScriptName);
        $requestUri = parse_url($env->get('REQUEST_URI'), PHP_URL_PATH);
        $basePath = '';
        $virtualPath = $requestUri;
        if (strpos($requestUri, $requestScriptName) === 0) {
            $basePath = $requestScriptName;<commit_msg>Fixes #962, Missing SERVER_PORT on GAE.<commit_after><?php
/**
 * Slim Framework (http://slimframework.com)
 *
 * @link      https://github.com/codeguy/Slim
 * @copyright Copyright (c) 2011-2015 <NAME>
 * @license   https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
 */
namespace Slim\Http;

/**
 * Value object representing a URI for use in HTTP requests.
 *
 * This interface is meant to represent only URIs for use with HTTP requests,
 * and is not intended as a general-purpose URI implementation.
 *
 * Instances of this interface are considered immutable; all methods that
 * might change state MUST be implemented such that they retain the internal
 * state of the current instance and return a new instance that contains the
 * changed state.
 *
 * Typically the Host header will be also be present in the request message.
 * For server-side requests, the scheme will typically be discoverable in the
 * server parameters.
 *
 * @link http://tools.ietf.org/html/rfc3986 (the URI specification)
 */
class Uri implements \Psr\Http\Message\UriInterface
{
    /**
     * Uri scheme (without "://" suffix)
     *
     * @var string
     */
    protected $scheme;

    /**
     * Uri user
     *
     * @var string
     */
    protected $user;

    /**
     * Uri password
     *
     * @var string
     */
    protected $password;

    /**
     * Uri host
     *
     * @var string
     */
    protected $host;

    /**
     * Uri port number
     *
     * @var int
     */
    protected $port;

    /**
     * Uri base path
     *
     * @var string
     */
    protected $basePath;

    /**
     * Uri path
     *
     * @var string
     */
    protected $path;

    /**
     * Uri query string (without "?" prefix)
     *
     * @var string
     */
    protected $query;

    /**
     * Create new Uri
     *
     * @param string $scheme   Uri scheme
     * @param string $user     Uri user
     * @param string $password Uri password
     * @param string $host     Uri host
     * @param int    $port     Uri port number
     * @param string $path     Uri path
     * @param string $query    Uri query string
     */
    public function __construct($scheme, $user, $password, $host, $port, $path, $query = '')
    {
        $this->scheme = $scheme;
        $this->user = $user;
        $this->password = $password;
        $this->host = $host;
        $this->port = $port;
        $this->path = $path;
        $this->query = $query;
    }

    /**
     * Create new Uri from string
     *
     * @param  string $uri Complete Uri string (i.e., https://user:pass@host:443/path?query)
     * @return self
     */
    public static function createFromString($uri)
    {
        if (is_string($uri) === false) {
            throw new \InvalidArgumentException('URI must be a string');
        }

        $parts = parse_url($uri);
        $scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
        $user = isset($parts['user']) ? $parts['user'] : '';
        $pass = isset($parts['pass']) ? $parts['pass'] : '';
        $host = isset($parts['host']) ? $parts['host'] : '';
        $port = isset($parts['port']) ? $parts['port'] : '';
        $path = isset($parts['path']) ? $parts['path'] : '';
        $query = isset($parts['query']) ? $parts['query'] : '';

        return new static($scheme, $user, $pass, $host, $port, $path, $query);
    }

    /**
     * Create new Uri from environment
     *
     * @param  Environment $env
     * @return self
     */
    public static function createFromEnvironment(Environment $env)
    {
        // Scheme
        if ($env->has('HTTP_X_FORWARDED_PROTO') === true) {
            $scheme = $env->get('HTTP_X_FORWARDED_PROTO');
        } else {
            $https = $env->get('HTTPS', '');
            $scheme = empty($https) || $https === 'off' ? 'http' : 'https';
        }

        // Authority
        // TODO: Respect trusted proxy X-Forwarded-* headers
        $user = $env->get('PHP_AUTH_USER', '');
        $password = $env-><PASSWORD>('<PASSWORD>', '');
        $host = $env->get('HTTP_HOST', $env->get('SERVER_NAME'));
        $port = $env->get('SERVER_PORT', 80);

        // Path
        $requestScriptName = parse_url($env->get('SCRIPT_NAME'), PHP_URL_PATH);
        $requestScriptDir = dirname($requestScriptName);
        $requestUri = parse_url($env->get('REQUEST_URI'), PHP_URL_PATH);
        $basePath = '';
        $virtualPath = $requestUri;
        if (strpos($requestUri, $requestScriptName) === 0) {
            $basePath = $requestScriptName;
{'fraction_non_alphanumeric': 0.15171650055370986, 'fraction_numerical': 0.004097452934662237, 'mean_word_length': 2.2047551454932575, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 6, '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': '4846441', 'n_tokens_mistral': 2775, 'n_tokens_neox': 2667, 'n_words': 733}