<commit_before><?php
/**
 * This file is part of the League.url library
 *
 * @license http://opensource.org/licenses/MIT
 * @link https://github.com/thephpleague/url/
 * @version 4.0.0
 * @package League.url
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace League\Url\Utilities;

use InvalidArgumentException;
use League\Url;
use ReflectionClass;

/**
 * A Trait to parse an URL
 *
 * @package League.url
 * @since 4.0.0
 */
trait UrlFactory
{
    /**
     * A Factory trait fetch info from Server environment variables
     */
    use ServerInfo;

    /**
     * Create a new League\Url\Url object from the environment
     *
     * @param array $server the environment server typically $_SERVER
     *
     * @throws \InvalidArgumentException If the URL can not be parsed
     *
     * @return Url\Url
     */
    public static function createFromServer(array $server)
    {
        return static::createFromUrl(
            static::fetchServerScheme($server).'//'
            .static::fetchServerUserInfo($server)
            .static::fetchServerHost($server)
            .static::fetchServerPort($server)
            .static::fetchServerRequestUri($server)
        );
    }

    /**
     * Create a new League\Url\Url instance from a string
     *
     * @param string $url
     *
     * @throws \InvalidArgumentException If the URL can not be parsed
     *
     * @return Url\Url
     */
    public static function createFromUrl($url)
    {
        return static::createFromComponents(static::parse($url));
    }

    /**
     * Create a new League\Url\Url instance from an array returned by
     * PHP parse_url function
     *
     * @param array $components
     *
     * @return Url\Url
     */
    public static function createFromComponents(array $components)
    {
        $components = array_merge([
            "scheme" => null, "user" => null, "pass" => null, "host" => null,
            "port" => null, "path" => null, "query" => null, "fragment" => null,
        ], $components);

        return new Url\Url(
            new Url\Scheme($components["scheme"]),
            new Url\UserInfo($components["user"], $components["pass"]),
            new Url\Host($components["host"]),
            new Url\Port($components["port"]),
            new Url\Path($components["path"]),
            new Url\Query($components["query"]),
            new Url\Fragment($components["fragment"])
        );
    }

    /**
     * Parse a string as an URL
     *
     * Parse an URL string using PHP parse_url while applying bug fixes
     *
     * @param string $url The URL to parse
     *
     * @throws InvalidArgumentException if the URL can not be parsed
     *
     * @return array
     */
    protected static function parse($url)
    {
        $defaultComponents = [
            "scheme" => null, "user" => null, "pass" => null, "host" => null,
            "port" => null, "path" => null, "query" => null, "fragment" => null,
        ];
        $url = trim($url);
        $components = @parse_url($url);
        if (is_array($components)) {
            return array_merge($defaultComponents, $components);
        }<commit_msg>make Url::parse public<commit_after><?php
/**
 * This file is part of the League.url library
 *
 * @license http://opensource.org/licenses/MIT
 * @link https://github.com/thephpleague/url/
 * @version 4.0.0
 * @package League.url
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace League\Url\Utilities;

use InvalidArgumentException;
use League\Url;
use ReflectionClass;

/**
 * A Trait to parse an URL
 *
 * @package League.url
 * @since 4.0.0
 */
trait UrlFactory
{
    /**
     * A Factory trait fetch info from Server environment variables
     */
    use ServerInfo;

    /**
     * Create a new League\Url\Url object from the environment
     *
     * @param array $server the environment server typically $_SERVER
     *
     * @throws \InvalidArgumentException If the URL can not be parsed
     *
     * @return Url\Url
     */
    public static function createFromServer(array $server)
    {
        return static::createFromUrl(
            static::fetchServerScheme($server).'//'
            .static::fetchServerUserInfo($server)
            .static::fetchServerHost($server)
            .static::fetchServerPort($server)
            .static::fetchServerRequestUri($server)
        );
    }

    /**
     * Create a new League\Url\Url instance from a string
     *
     * @param string $url
     *
     * @throws \InvalidArgumentException If the URL can not be parsed
     *
     * @return Url\Url
     */
    public static function createFromUrl($url)
    {
        return static::createFromComponents(static::parse($url));
    }

    /**
     * Create a new League\Url\Url instance from an array returned by
     * PHP parse_url function
     *
     * @param array $components
     *
     * @return Url\Url
     */
    public static function createFromComponents(array $components)
    {
        $components = array_merge([
            "scheme" => null, "user" => null, "pass" => null, "host" => null,
            "port" => null, "path" => null, "query" => null, "fragment" => null,
        ], $components);

        return new Url\Url(
            new Url\Scheme($components["scheme"]),
            new Url\UserInfo($components["user"], $components["pass"]),
            new Url\Host($components["host"]),
            new Url\Port($components["port"]),
            new Url\Path($components["path"]),
            new Url\Query($components["query"]),
            new Url\Fragment($components["fragment"])
        );
    }

    /**
     * Parse a string as an URL
     *
     * Parse an URL string using PHP parse_url while applying bug fixes
     *
     * @param string $url The URL to parse
     *
     * @throws InvalidArgumentException if the URL can not be parsed
     *
     * @return array
     */
    public static function parse($url)
    {
        $defaultComponents = [
            "scheme" => null, "user" => null, "pass" => null, "host" => null,
            "port" => null, "path" => null, "query" => null, "fragment" => null,
        ];
        $url = trim($url);
        $components = @parse_url($url);
        if (is_array($components)) {
            return array_merge($defaultComponents, $components);
        }
{'fraction_non_alphanumeric': 0.12631578947368421, 'fraction_numerical': 0.0018575851393188853, 'mean_word_length': 2.2747085656360873, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '3717534', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1784, 'n_words': 520}