<commit_before><?php

namespace Build\Core\Http\Routing;

/**
 * This file is part of the Centagon Build/Core package.
 *
 * (c) Centagon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Build\Core\Eloquent\Models\Website;
use Illuminate\Database\Eloquent\Collection;

class Discovery
{

    /**
     * @var null|Website
     */
    protected $website;

    /**
     * @var null|Website
     */
    protected $backendWebsite;

    /**
     * @var null|Language
     */
    protected $language;

    /**
     * @var null|Language
     */
    protected $backendLanguage;

    /**
     * Get the current website.
     *
     * @return Website|null
     */
    public function website()
    {
        if ($this->website) {
            return $this->website;
        }

        $url = $this->getUrl();

        try {
            // First try to find exact matches.
            $this->website = Website::activated()
                ->select([
                    'id', 'domain', 'language_id',
                ])
                ->with(['language' => function ($q) {
                    $q->select(['id', 'locale']);
                }])
                ->byDomain($url)
                ->sorted()
                ->firstOrFail();<commit_msg>add setWebsite to Discovery<commit_after><?php

namespace Build\Core\Http\Routing;

/**
 * This file is part of the Centagon Build/Core package.
 *
 * (c) Centagon <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Build\Core\Eloquent\Models\Website;
use Illuminate\Database\Eloquent\Collection;

class Discovery
{

    /**
     * @var null|Website
     */
    protected $website;

    /**
     * @var null|Website
     */
    protected $backendWebsite;

    /**
     * @var null|Language
     */
    protected $language;

    /**
     * @var null|Language
     */
    protected $backendLanguage;

    /**
     * Force the website to be set to this value without discovery
     * 
     * @param Website $website
     */
    public function setWebsite(Website $website) {
        $this->website = $website;
    }
    
    /**
     * Get the current website.
     *
     * @return Website|null
     */
    public function website()
    {
        if ($this->website) {
            return $this->website;
        }

        $url = $this->getUrl();

        try {
            // First try to find exact matches.
            $this->website = Website::activated()
                ->select([
                    'id', 'domain', 'language_id',
                ])
                ->with(['language' => function ($q) {
                    $q->select(['id', 'locale']);
                }])
                ->byDomain($url)
                ->sorted()
                ->firstOrFail();
{'fraction_non_alphanumeric': 0.13262142611091973, 'fraction_numerical': 0.0, 'mean_word_length': 1.6424021838034577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 0, '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': '1776331', 'n_tokens_mistral': 838, 'n_tokens_neox': 786, 'n_words': 206}