<commit_before><?php

/**
 * OneDB Database Framework
 *
 * @author cvgellhorn
 */
class OneDB
{
	/**
	 * Instance implementation
	 *
	 * @var OneDB
	 */
	private static $_instance = null;

	/**
	 * Collection of active database connections
	 *
	 * @var array of OneDB connections
	 */
	private static $_connections = array();

	/**
	 * PDO object
	 *
	 * @var PDO
	 */
	protected $_pdo;

	/**
	 * The driver level statement PDO
	 *
	 * @var PDOStatement
	 */
	protected $_stmt;

	/**
	 * Default DB configuration
	 *
	 * @var array
	 */
	protected $_config = array(
		'pdo_type'  => 'mysql',
		'host'      => 'localhost',
		'charset'   => 'utf8',
		'database'  => null,
		'user'      => null,
		'password'  => <PASSWORD>
	);

	/**
	 * Single pattern implementation
	 *
	 * @param array $config Connection configs
	 * @return OneDB
	 */
	public static function load($config = array())
	{
		if (null === self::$_instance) {
			self::$_instance = self::_create($config);
		}
		return self::$_instance;
	}

	/**
	 * Handle database connections
	 *
	 * @param string $name Connection name
	 * @param array $config Connection configs
	 * @return OneDB
	 */
	public static function getConnection($name = null, $config = array())
	{
		if (null === $name) {
			return self::_create($config);
		} else {
			if (!isset(self::$_connections[$name])) {
				self::$_connections[$name] = self::_create($config);
			}
			return self::$_connections[$name];
		}
	}

	/**
	 * Create new OneDB connection
	 *
	 * @param array $config Connection configs
	 * @return OneDB
	 * @throws OneException
	 */
	private static function _create($config)
	{
		if (!empty($config)) {
			return new self($config);
		} else {
			throw new OneException('OneDB configuration not set');
		}
	}

	/**
	 * Create DB object and connect to database
	 *
	 * @throws OneException
	 */
	private function __construct($config)
	{
		try {
			if (!extension_loaded('pdo_mysql')) {
				throw new OneException('pdo_mysql extension is not installed');
			}

			// Prepare database configuration
			$config = $this->_prepareConfig($config);

			$dsn = array(
				'host='     . $config['host'],
				'dbname='   . $config['database'],
				'charset='  . $config['charset']
			);

			$this->_pdo = new PDO(
				$config['pdo_type'] . ':' . implode(';', $dsn),
				$config['user'],
				$config['password']
			);

			// Always use exceptions
			$this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

			// Set character encoding
			$this->_pdo->exec('SET CHARACTER SET ' . $config['charset']);
		} catch (PDOException $e) {
			throw new OneException($e->getMessage(), $e->getCode());
		}
	}

	/**
	 * Prepare database configuration
	 *
	 * @param array $config Connection configs
	 * @return array Matched connection configs
	 * @throws OneException
	 */
	private function _prepareConfig($config)
	{
		$config = array_merge($this->_config, $config);
		foreach ($config as $key => $val) {
			if (null === $val) {
				throw new OneException('Could not connect to database, missing parameter: ' . $key);
			}
		}
<commit_msg>Add port to DSN config<commit_after><?php

/**
 * OneDB Database Framework
 *
 * @author cvgellhorn
 */
class OneDB
{
	/**
	 * Instance implementation
	 *
	 * @var OneDB
	 */
	private static $_instance = null;

	/**
	 * Collection of active database connections
	 *
	 * @var array of OneDB connections
	 */
	private static $_connections = array();

	/**
	 * PDO object
	 *
	 * @var PDO
	 */
	protected $_pdo;

	/**
	 * The driver level statement PDO
	 *
	 * @var PDOStatement
	 */
	protected $_stmt;

	/**
	 * Default DB configuration
	 *
	 * @var array
	 */
	protected $_config = array(
		'pdo_type'  => 'mysql',
		'host'      => 'localhost',
		'charset'   => 'utf8',
		'database'  => null,
		'user'      => null,
		'password'  => <PASSWORD>
	);

	/**
	 * Single pattern implementation
	 *
	 * @param array $config Connection configs
	 * @return OneDB
	 */
	public static function load($config = array())
	{
		if (null === self::$_instance) {
			self::$_instance = self::_create($config);
		}
		return self::$_instance;
	}

	/**
	 * Handle database connections
	 *
	 * @param string $name Connection name
	 * @param array $config Connection configs
	 * @return OneDB
	 */
	public static function getConnection($name = null, $config = array())
	{
		if (null === $name) {
			return self::_create($config);
		} else {
			if (!isset(self::$_connections[$name])) {
				self::$_connections[$name] = self::_create($config);
			}
			return self::$_connections[$name];
		}
	}

	/**
	 * Create new OneDB connection
	 *
	 * @param array $config Connection configs
	 * @return OneDB
	 * @throws OneException
	 */
	private static function _create($config)
	{
		if (!empty($config)) {
			return new self($config);
		} else {
			throw new OneException('OneDB configuration not set');
		}
	}

	/**
	 * Create DB object and connect to database
	 *
	 * @throws OneException
	 */
	private function __construct($config)
	{
		try {
			if (!extension_loaded('pdo_mysql')) {
				throw new OneException('pdo_mysql extension is not installed');
			}

			// Prepare database configuration
			$config = $this->_prepareConfig($config);

			$this->_pdo = new PDO(
				$config['pdo_type'] . ':' . $config['dsn'],
				$config['user'],
				$config['password']
			);

			// Always use exceptions
			$this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

			// Set character encoding
			$this->_pdo->exec('SET CHARACTER SET ' . $config['charset']);
		} catch (PDOException $e) {
			throw new OneException($e->getMessage(), $e->getCode());
		}
	}

	/**
	 * Prepare database configuration
	 *
	 * @param array $config Connection configs
	 * @return array Matched connection configs
	 * @throws OneException
	 */
	private function _prepareConfig($config)
	{
		$config = array_merge($this->_config, $config);
		foreach ($config as $key => $val) {
			if (null === $val) {
				throw new OneException('Could not connect to database, missing parameter: ' . $key);
			}
		}

		$dsn = array(
			'host='     . $config['host'],
			'dbname='   . $config['database'],
			'charset='  . $config['charset']
		);

		if (isset($config['port'])) {
			$dsn[] = 'port=' . $config['port'];
		}

		$config['dsn'] = implode(';', $dsn);
{'fraction_non_alphanumeric': 0.16153723489076702, 'fraction_numerical': 0.0003189284005740711, 'mean_word_length': 3.1953177257525085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '2779634', 'n_tokens_mistral': 2270, 'n_tokens_neox': 1955, 'n_words': 513}