<commit_before><?php

/**
 * This file is part of the Nextras\Dbal library.
 * @license    MIT
 * @link       https://github.com/nextras/dbal
 */

namespace Nextras\Dbal;

use Nextras\Dbal\Drivers\DriverException;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exceptions\DbalException;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Dbal\Result\Result;


class Connection
{
	/** @var array of callbacks: function(Connection $connection) */
	public $onConnect = [];

	/** @var array of callbacks: function(Connection $connection) */
	public $onDisconnect = [];

	/** @var array of callbacks: function(Connection $connection, string $query, Result $result) */
	public $onQuery = [];

	/** @var array */
	private $config;

	/** @var IDriver */
	private $driver;

	/** @var IPlatform */
	private $platform;

	/** @var SqlProcessor */
	private $sqlPreprocessor;


	public function __construct(array $config)
	{
		$this->config = $config;

		$driver = $config['driver'];
		if (is_object($driver)) {
			$this->driver = $driver;

		} else {
			$driver = ucfirst($driver);
			$driver = "Nextras\\Dbal\\Drivers\\{$driver}\\{$driver}Driver";
			$this->driver = new $driver;
		}

		$this->sqlPreprocessor = new SqlProcessor($this->driver);
	}


	public function connect()
	{
		if ($this->driver->isConnected()) {
			return;
		}

		try {
			$this->driver->connect($this->config);
		} catch (DriverException $e) {
			throw $this->driver->convertException($e);
		}

		$this->fireEvent('onConnect', [$this]);
	}


	public function disconnect()
	{
		$this->driver->disconnect();
		$this->fireEvent('onDisconnect', [$this]);
	}


	public function reconnect()
	{
		$this->disconnect();
		$this->connect();
	}


	public function getDriver()
	{
		return $this->driver;
	}


	/**
	 * @param  string $query
	 * @return Result|NULL
	 * @throws DbalException
	 */
	public function query($query)<commit_msg>Connection: added getConfiguration() method<commit_after><?php

/**
 * This file is part of the Nextras\Dbal library.
 * @license    MIT
 * @link       https://github.com/nextras/dbal
 */

namespace Nextras\Dbal;

use Nextras\Dbal\Drivers\DriverException;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exceptions\DbalException;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Dbal\Result\Result;


class Connection
{
	/** @var array of callbacks: function(Connection $connection) */
	public $onConnect = [];

	/** @var array of callbacks: function(Connection $connection) */
	public $onDisconnect = [];

	/** @var array of callbacks: function(Connection $connection, string $query, Result $result) */
	public $onQuery = [];

	/** @var array */
	private $config;

	/** @var IDriver */
	private $driver;

	/** @var IPlatform */
	private $platform;

	/** @var SqlProcessor */
	private $sqlPreprocessor;


	public function __construct(array $config)
	{
		$this->config = $config;

		$driver = $config['driver'];
		if (is_object($driver)) {
			$this->driver = $driver;

		} else {
			$driver = ucfirst($driver);
			$driver = "Nextras\\Dbal\\Drivers\\{$driver}\\{$driver}Driver";
			$this->driver = new $driver;
		}

		$this->sqlPreprocessor = new SqlProcessor($this->driver);
	}


	public function connect()
	{
		if ($this->driver->isConnected()) {
			return;
		}

		try {
			$this->driver->connect($this->config);
		} catch (DriverException $e) {
			throw $this->driver->convertException($e);
		}

		$this->fireEvent('onConnect', [$this]);
	}


	public function disconnect()
	{
		$this->driver->disconnect();
		$this->fireEvent('onDisconnect', [$this]);
	}


	public function reconnect()
	{
		$this->disconnect();
		$this->connect();
	}


	public function getDriver()
	{
		return $this->driver;
	}


	/**
	 * Returns connection configuration.
	 * @return array
	 */
	public function getConfiguration()
	{
		return $this->config;
	}


	/**
	 * @param  string $query
	 * @return Result|NULL
	 * @throws DbalException
	 */
	public function query($query)
{'fraction_non_alphanumeric': 0.16793505834601724, 'fraction_numerical': 0.0, 'mean_word_length': 3.7506024096385544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '7105899', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1278, 'n_words': 282}