<commit_before><?php namespace Orchestra\Extension;

use Illuminate\Http\Request;

class RouteGenerator
{
    /**
     * Request instance.
     *
     * @var \Illuminate\Http\Request
     */
    protected $request;

    /**
     * Domain name.
     *
     * @var string
     */
    protected $domain = null;

    /**
     * Handles path.
     *
     * @var string
     */
    protected $prefix = null;

    /**
     * Base URL.
     *
     * @var string
     */
    protected $baseUrl = null;

    /**
     * Base URL prefix.
     *
     * @var string
     */
    protected $basePrefix = null;

    /**
     * Construct a new instance.
     *
     * @param  string                      $handles
     * @param  \Illuminate\Http\Request    $request
     */
    public function __construct($handles, Request $request)
    {
        $this->request = $request;

        // Build base URL and prefix from Request::root();
        $baseUrl = str_replace(array('https://', 'http://'), '', $this->request->root());
        $base    = explode('/', $baseUrl, 2);

        if (count($base) > 1) {
            $this->basePrefix = array_pop($base);
        }

        $this->baseUrl = array_shift($base);

        // If the handles doesn't start as "//some.domain.com/foo" we should
        // assume that it doesn't belong to any subdomain, otherwise we
        // need to split the value to "some.domain.com" and "foo".
        if (is_null($handles) or ! starts_with($handles, '//')) {
            $this->prefix = $handles;
        } else {
            $handles      = substr($handles, 2);
            $fragments    = explode('/', $handles, 2);
            $this->domain = array_shift($fragments);
            $this->prefix = array_shift($fragments);
        }

        // It is possible that prefix would be null, in this case assume
        // it handle the main path under the domain.
        ! is_null($this->prefix) or $this->prefix = '/';
    }

    /**
     * Get route root.
     *
     * @return string
     */
    public function root()
    {
        $http   = ($this->request->secure() ? "https" : "http");
        $domain = trim($this->domain(true), '/');
        $prefix = $this->prefix(true);

        return trim("{$http}://{$domain}/{$prefix}", '/');
    }

    /**
     * Get route to.
     *
     * @param  string   $to
     * @return string
     */
    public function to($to)
    {
        $root = $this->root();
        $to   = trim($to, '/');

        return "{$root}/{$to}";
    }

    /**
     * Get route domain.
     *
     * @param  boolean  $forceBase
     * @return string
     */
    public function domain($forceBase = false)
    {
        $domain = $this->domain;

        if (is_null($domain) and $forceBase === true) {
            $domain = $this->baseUrl;
        } elseif (str_contains($domain, '{{domain}}')) {
            $domain = str_replace('{{domain}}', $this->baseUrl, $domain);
        }

        return $domain;
    }

    /**
     * Get route prefix.
     *
     * @param  boolean  $forceBase
     * @return string
     */
    public function prefix($forceBase = false)
    {
        $prefix = trim($this->prefix, '/');

        if (is_null($this->domain) and $forceBase === true) {
            $prefix = trim($this->basePrefix, '/')."/{$prefix}";
            $prefix = trim($prefix, '/');
        }

        empty($prefix) and $prefix = '/';

        return $prefix;
    }

    /**
     * Magic method to parse as string.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->prefix();
    }
}
<commit_msg>Reorganize some code.<commit_after><?php namespace Orchestra\Extension;

use Illuminate\Http\Request;

class RouteGenerator
{
    /**
     * Request instance.
     *
     * @var \Illuminate\Http\Request
     */
    protected $request;

    /**
     * Domain name.
     *
     * @var string
     */
    protected $domain = null;

    /**
     * Handles path.
     *
     * @var string
     */
    protected $prefix = null;

    /**
     * Base URL.
     *
     * @var string
     */
    protected $baseUrl = null;

    /**
     * Base URL prefix.
     *
     * @var string
     */
    protected $basePrefix = null;

    /**
     * Construct a new instance.
     *
     * @param  string                      $handles
     * @param  \Illuminate\Http\Request    $request
     */
    public function __construct($handles, Request $request)
    {
        $this->request = $request;

        // Build base URL and prefix from Request::root();
        $baseUrl = str_replace(array('https://', 'http://'), '', $this->request->root());
        $base    = explode('/', $baseUrl, 2);

        if (count($base) > 1) {
            $this->basePrefix = array_pop($base);
        }

        $this->baseUrl = array_shift($base);

        // If the handles doesn't start as "//some.domain.com/foo" we should
        // assume that it doesn't belong to any subdomain, otherwise we
        // need to split the value to "some.domain.com" and "foo".
        if (is_null($handles) or ! starts_with($handles, '//')) {
            $this->prefix = $handles;
        } else {
            $handles      = substr($handles, 2);
            $fragments    = explode('/', $handles, 2);
            $this->domain = array_shift($fragments);
            $this->prefix = array_shift($fragments);
        }

        // It is possible that prefix would be null, in this case assume
        // it handle the main path under the domain.
        ! is_null($this->prefix) or $this->prefix = '/';
    }

    /**
     * Get route domain.
     *
     * @param  boolean  $forceBase
     * @return string
     */
    public function domain($forceBase = false)
    {
        $domain = $this->domain;

        if (is_null($domain) and $forceBase === true) {
            $domain = $this->baseUrl;
        } elseif (str_contains($domain, '{{domain}}')) {
            $domain = str_replace('{{domain}}', $this->baseUrl, $domain);
        }

        return $domain;
    }

    /**
     * Get route prefix.
     *
     * @param  boolean  $forceBase
     * @return string
     */
    public function prefix($forceBase = false)
    {
        $prefix = trim($this->prefix, '/');

        if (is_null($this->domain) and $forceBase === true) {
            $prefix = trim($this->basePrefix, '/')."/{$prefix}";
            $prefix = trim($prefix, '/');
        }

        empty($prefix) and $prefix = '/';

        return $prefix;
    }

    /**
     * Get route root.
     *
     * @return string
     */
    public function root()
    {
        $http   = ($this->request->secure() ? "https" : "http");
        $domain = trim($this->domain(true), '/');
        $prefix = $this->prefix(true);

        return trim("{$http}://{$domain}/{$prefix}", '/');
    }

    /**
     * Get route to.
     *
     * @param  string   $to
     * @return string
     */
    public function to($to)
    {
        $root = $this->root();
        $to   = trim($to, '/');

        return "{$root}/{$to}";
    }

    /**
     * Magic method to parse as string.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->prefix();
    }
}

{'fraction_non_alphanumeric': 0.16230147673446643, 'fraction_numerical': 0.0011145165784341043, 'mean_word_length': 1.6747391952309985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '4543672', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2136, 'n_words': 516}