<commit_before><?php namespace Zephyrus\Database;

use RuntimeException;
use Zephyrus\Application\Configuration;
use Zephyrus\Database\Core\Database;
use Zephyrus\Exceptions\FatalDatabaseException;

class DatabaseSession
{
    private static ?DatabaseSession $instance = null;
    private Database $database;
    private array $searchPaths;

    /**
     * @throws FatalDatabaseException
     */
    public final static function initiate(array $configurations, array $searchPaths = ['public'])
    {
        self::$instance = new self(new Database($configurations), $searchPaths);
    }

    public final static function getInstance(): self
    {
        if (is_null(self::$instance)) {
            throw new RuntimeException("DatabaseSession instance must first be initialized with [DatabaseSession::initiate(Database \$databaseInstance)].");
        }
        return self::$instance;
    }

    public function getDatabase(): Database
    {
        return $this->database;
    }

    private function __construct(Database $database, array $searchPaths)
    {
        $this->database = $database;
        $this->searchPaths = $searchPaths;
        $this->activateSearchPath();
        $this->activateLocale();
    }

    private function activateSearchPath()
    {
        if (empty($this->searchPaths)) {
            return;
        }
        $paths = implode(', ', $this->searchPaths);
        $this->database->query("SET search_path TO $paths;");
    }

    private function activateLocale()
    {
        $this->database->query("SET lc_time = '" . Configuration::getApplicationConfiguration('locale') . ".UTF-8'");
    }
}<commit_msg>feat: add method to get current search paths<commit_after><?php namespace Zephyrus\Database;

use RuntimeException;
use Zephyrus\Application\Configuration;
use Zephyrus\Database\Core\Database;
use Zephyrus\Exceptions\FatalDatabaseException;

class DatabaseSession
{
    private static ?DatabaseSession $instance = null;
    private Database $database;
    private array $searchPaths;

    /**
     * @throws FatalDatabaseException
     */
    public final static function initiate(array $configurations, array $searchPaths = ['public'])
    {
        self::$instance = new self(new Database($configurations), $searchPaths);
    }

    public final static function getInstance(): self
    {
        if (is_null(self::$instance)) {
            throw new RuntimeException("DatabaseSession instance must first be initialized with [DatabaseSession::initiate(Database \$databaseInstance)].");
        }
        return self::$instance;
    }

    public function getDatabase(): Database
    {
        return $this->database;
    }

    public function getSearchPaths(): array
    {
        return $this->searchPaths;
    }

    private function __construct(Database $database, array $searchPaths)
    {
        $this->database = $database;
        $this->searchPaths = $searchPaths;
        $this->activateSearchPath();
        $this->activateLocale();
    }

    private function activateSearchPath()
    {
        if (empty($this->searchPaths)) {
            return;
        }
        $paths = implode(', ', $this->searchPaths);
        $this->database->query("SET search_path TO $paths;");
    }

    private function activateLocale()
    {
        $this->database->query("SET lc_time = '" . Configuration::getApplicationConfiguration('locale') . ".UTF-8'");
    }
}
{'fraction_non_alphanumeric': 0.11937665392531609, 'fraction_numerical': 0.0005880623346074683, 'mean_word_length': 3.069377990430622, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '964683', 'n_tokens_mistral': 892, 'n_tokens_neox': 871, 'n_words': 211}