<commit_before><?php
namespace ChrisAndChris\Common\RowMapperBundle\Services\Pdo;

use ChrisAndChris\Common\RowMapperBundle\Exceptions\DatabaseException;
use PDO;

/**
 * This is the main database connection which is used for the application
 *
 * @name PdoLayer
 * @version   1.1.1
 * @since     v1.0.0
 * @package   RowMapperBundle
 * @author    ChrisAndChris
 * @link      https://github.com/chrisandchris
 */
class PdoLayer extends \PDO
{

    function __construct($system, $host, $port = null, $name = null, $user = null, $password = null)
    {
        $system = self::getPdoSystem($system);
        $dsn = $this->getDsn($system, $host, $port, $name, $user, $password);
        try {
            parent::__construct($dsn, $user, $password);

            // force to use own pdo statement class
            $this->setPdoAttributes();
        } catch (\PDOException $e) {
            throw new DatabaseException('Unable to init pdo layer', null, $e);
        }
    }

    /**
     * Get the pdo-internal system name
     *
     * @param string $system the system name
     * @return string
     */
    public function getPdoSystem($system = 'pdo_mysql')
    {
        switch ($system) {
            case 'sqlite' :
            case 'pdo_sqlite' :
                return 'sqlite';
            case 'pgsql' :
            case 'pg' :
            case 'postgres' :
                return 'pgsql';
            case 'pdo_mysql' :
            case 'mysqli' :
            default :
                return 'mysql';
        }
    }

    /**
     * Create a dsn
     *
     * @param string $system   the system to connect to (sqlite|mysql)
     * @param string $host     the host
     * @param string $port     the port
     * @param string $database the database name
     * @return null|string
     */
    public function getDsn($system, $host, $port, $database, $username, $password)
    {
        switch ($system) {
            case 'mysql' :
                if (false !== ($env = $this->getEnvStatus())) {
                    $database = $database . '_' . $env;
                }

                return $this->getMysqlDsn($host, $port, $database);
            case 'sqlite' :

                return $this->getSqliteDsn($host);
            case 'pgsql' :
                if (false !== $env = $this->getEnvStatus()) {
                    $database = $database . '_' . $env;
                }

                return $this->getPgDsn($host, $port, $database, $username, $password);
            default :
                return null;
        }
    }<commit_msg>minor improvements in env variable handling<commit_after><?php
namespace ChrisAndChris\Common\RowMapperBundle\Services\Pdo;

use ChrisAndChris\Common\RowMapperBundle\Exceptions\DatabaseException;
use PDO;

/**
 * This is the main database connection which is used for the application
 *
 * @name PdoLayer
 * @version   1.1.1
 * @since     v1.0.0
 * @package   RowMapperBundle
 * @author    ChrisAndChris
 * @link      https://github.com/chrisandchris
 */
class PdoLayer extends \PDO
{

    function __construct($system, $host, $port = null, $name = null, $user = null, $password = null)
    {
        $system = self::getPdoSystem($system);
        $dsn = $this->getDsn($system, $host, $port, $name, $user, $password);
        try {
            parent::__construct($dsn, $user, $password);

            // force to use own pdo statement class
            $this->setPdoAttributes();
        } catch (\PDOException $e) {
            throw new DatabaseException('Unable to init pdo layer', null, $e);
        }
    }

    /**
     * Get the pdo-internal system name
     *
     * @param string $system the system name
     * @return string
     */
    public function getPdoSystem($system = 'pdo_mysql')
    {
        switch ($system) {
            case 'sqlite' :
            case 'pdo_sqlite' :
                return 'sqlite';
            case 'pgsql' :
            case 'pg' :
            case 'postgres' :
                return 'pgsql';
            case 'pdo_mysql' :
            case 'mysqli' :
            default :
                return 'mysql';
        }
    }

    /**
     * Create a dsn
     *
     * @param string $system   the system to connect to (sqlite|mysql)
     * @param string $host     the host
     * @param string $port     the port
     * @param string $database the database name
     * @return null|string
     */
    public function getDsn($system, $host, $port, $database, $username, $password)
    {
        if (false !== ($env = $this->getEnvStatus())) {
            $database = $env;
        }
        switch ($system) {
            case 'mysql' :
                return $this->getMysqlDsn($host, $port, $database);
            case 'sqlite' :
                if (false !== $env) {
                    $host = $env . '.sqlite';
                }
                return $this->getSqliteDsn($host);
            case 'pgsql' :
                return $this->getPgDsn($host, $port, $database, $username, $password);
            default :
                return null;
        }
    }
{'fraction_non_alphanumeric': 0.12403713213509777, 'fraction_numerical': 0.002370136282836263, 'mean_word_length': 1.7402597402597402, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '3315952', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1461, 'n_words': 391}