Builds configuration service

@param \PDO $pdo Prepared PDO instance
@param string $table Table name to work with
@return \Krystal\Config\Sql\SqlConfigService
430501
public static function build($pdo, $table)
    {
        $configMapper = new ConfigMapper(new Serializer(), $pdo, $table);
        return new SqlConfigService($configMapper, new ArrayConfig());
    }
596591
public function setPdo($pdo)
    {
        $this->connection = $this->createConnection();
        $this->getManagedConfigure($this->config);
        $this->useDefaultQueryGrammar();
        $this->useDefaultPostProcessor();

        return $this;
    }
126660
protected static function getAdapterFromPdo(\PDO $resource)
    {
        $driver = mb_strtolower($resource->getAttribute(\PDO::ATTR_DRIVER_NAME));
        switch ($driver) {
            case 'mysql':
                $adapter = new Adapter\PdoMysqlAdapter($resource);
                break;
            case 'sqlite':
                $adapter = new Adapter\PdoSqliteAdapter($resource);
                break;
            default:
                $msg = "Driver 'PDO_$driver' is not currently supported.";
                throw new Exception\UnsupportedDriverException($msg);
        }

        return $adapter;
    }
350968
public function pdo(PDO $pdo = null)
    {
        if ($pdo) {
            $this->pdo = $pdo;
        }

        return $this->pdo;
    }
502033
public function configure(PDOInterface $pdo): void
    {
        $sslMode = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_MODE);

        $protocol = $sslMode === PDO::CRATE_ATTR_SSL_MODE_DISABLED ? 'http' : 'https';

        $options = [
            RequestOptions::TIMEOUT         => $pdo->getAttribute(PDO::ATTR_TIMEOUT),
            RequestOptions::CONNECT_TIMEOUT => $pdo->getAttribute(PDO::ATTR_TIMEOUT),
            RequestOptions::AUTH            => $pdo->getAttribute(PDO::CRATE_ATTR_HTTP_BASIC_AUTH) ?: null,
            RequestOptions::HEADERS         => [
                'Default-Schema' => $pdo->getAttribute(PDO::CRATE_ATTR_DEFAULT_SCHEMA),
            ],
        ];

        if ($sslMode === PDO::CRATE_ATTR_SSL_MODE_ENABLED_BUT_WITHOUT_HOST_VERIFICATION) {
            $options['verify'] = false;
        }

        $ca         = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_CA_PATH);
        $caPassword = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_CA_PASSWORD);

        if ($ca) {
            if ($caPassword) {
                $options[RequestOptions::VERIFY] = [$ca, $caPassword];
            } else {
                $options[RequestOptions::VERIFY] = $ca;
            }
        }

        $cert         = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_CERT_PATH);
        $certPassword = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_CERT_PASSWORD);

        if ($cert) {
            if ($certPassword) {
                $options[RequestOptions::CERT] = [$cert, $certPassword];
            } else {
                $options[RequestOptions::CERT] = $cert;
            }
        }

        $key         = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_KEY_PATH);
        $keyPassword = $pdo->getAttribute(PDO::CRATE_ATTR_SSL_KEY_PASSWORD);

        if ($key) {
            if ($keyPassword) {
                $options[RequestOptions::SSL_KEY] = [$key, $keyPassword];
            } else {
                $options[RequestOptions::SSL_KEY] = $key;
            }
        }

        $this->protocol    = $protocol;
        $this->httpOptions = $options;
    }
268961
protected function createPdoStatement($query, $pdo = null)
    {
        if (is_null($pdo)) {
            $pdo = $this->getPdo();
        }

        $grammar = $this->getQueryGrammar();

        $query = preg_replace_callback('#\{(.*?)\}#', function ($matches) use ($grammar)
        {
            $value = $matches[1];

            return $grammar->wrap($value);

        }, $query);

        return $pdo->prepare($query);
    }
670760
public static function table($table)
    {
        static::verifyConnection();

        $table = static::$adapter->getTablePrefix().$table;

        return new QueryBuilder(
            $table,
            static::$adapter->getConnection()
        );
    }
95259
public function getPdoStatement(\PDO $pdo)
    {
        $stmt = $pdo->prepare($this->getSqlString());

        $bound = $this->getBoundValues();

        foreach ($bound as $name => $bind) {
            $stmt->bindValue($name, $bind[0], $bind[1]);
        }

        return $stmt;
    }
727152
public function getConfiguredSchemaParser(PDO $con = null)
    {
        $clazz = $this->getClassname("reverseParserClass");
        $parser = new $clazz();
        if (!$parser instanceof SchemaParser) {
            throw new BuildException("Specified platform class ($clazz) does implement SchemaParser interface.", $this->getLocation());
        }
        $parser->setConnection($con);
        $parser->setMigrationTable($this->getBuildProperty('migrationTable'));
        $parser->setGeneratorConfig($this);

        return $parser;
    }
53962
public function convert(\PDO $db) {

        $this->setMaxExecutionTime(86400);
        $this->setMemoryLimit(2000);

        //find all the tables in the db
        $tables = [];
        $sql = "SHOW TABLES";
        $stmt = $db->prepare($sql);
        $result = $stmt->execute();
        if ($result) {
            $tables = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
        }

        //loop through the tables and grab the create statements
        foreach ($tables as $table) {

            $this->log($table, "CONVERTING TABLE");
            $sql = "SHOW CREATE TABLE " . $table;
            $stmt = $db->prepare($sql);
            $result = $stmt->execute();
            if ($result) {
                $create = $stmt->fetchAll(\PDO::FETCH_COLUMN, 1)[0];
                $this->log($create . "\n", "ORIGINAL CREATE SQL");

                //convert the create statements into utf8 charset
                $utf_create = preg_replace("~CHARSET=(.*)~", "CHARSET=utf8", $create);

                $this->log($utf_create . "\n", "UTF8 CREATE SQL");
                $backup_table = $table . "_backup";

                //create table backup
                $sql = "CREATE TABLE `" . $backup_table . "` SELECT * FROM `" . $table . "`";
                $this->log($sql, "MAKING BACKUP");
                $stmt = $db->prepare($sql);
                $result = $stmt->execute();
                if ($result) {

                    $this->log($backup_table, "BACKUP COMPLETE");

                    //drop original table
                    $sql = "DROP TABLE `" . $table . "`";
                    $this->log($sql, "DROPPING ORIGINAL");
                    $stmt = $db->prepare($sql);
                    $result = $stmt->execute();
                    
                    if ($result) {
                        
                        $this->log($table, "DROPPED ORIGINAL");
                        //create the UTF8 version of the table
                        $this->log($table, "CREATING UTF TABLE");
                        $result = false;
                        try{
                        $stmt = $db->prepare($utf_create);
                        $result = $stmt->execute();
                        }catch(\PDOException $e){
                            $this->log($table.': '.print_r($e->getMessage()), "ERROR!!!!!");
                        }
                        
                        if ($result) {

                            $this->log($table, "UTF TABLE CREATED");

                            //restore the data from the backup table
                            $sql = "INSERT INTO `" . $table . "` SELECT * FROM `" . $backup_table . "`";
                            $this->log($backup_table . ' -> ' . $table, "RESTORING");
                            $stmt = $db->prepare($sql);
                            $result = $stmt->execute();
                           
                            if ($result) {
                                $this->log($backup_table . ' -> ' . $table, "RESTORED");

                                //dropping the backup table
                                $this->log($backup_table, "DROPPING");
                                $sql = "DROP TABLE " . $backup_table;
                                $stmt = $db->prepare($sql);
                                $result = $stmt->execute();
                                if ($result) {
                                    $this->log($backup_table, "BACKUP DROPPED");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
1207556
public function connect(array $config): PDO
    {
        if (isset($config['options']) === false) {
            $config['options'] = [];
        }

        return $this->doConnect($config);
    }
166119
public function getPdo() : PDO
    {
        if(empty($this->pdo)) {
            $this->pdo = new PDO("sqlite:".$this->getDir().$this->getFileNames()[0]);
        }
        return $this->pdo;
    }
830643
protected function connect(): PDO
	{
		// Connect to the database

		try
		{
			$pdo = new PDO($this->dsn, $this->username, $this->password, $this->getConnectionOptions());
		}
		catch(PDOException $e)
		{
			throw new RuntimeException(vsprintf('Failed to connect to the [ %s ] database. %s', [$this->name, $e->getMessage()]));
		}

		// Run queries

		foreach($this->onConnectQueries as $query)
		{
			$pdo->exec($query);
		}

		// Return PDO instance

		return $pdo;
	}
553517
public function setup($table, $connection = 'default')
    {
        $query = $this->query();
        $this->setDatabase($connection == 'default' ? $query->getDefaultConnection() : $connection);
        $this->setTableName($table);
        $query->setActiveRecord($this);

        return $query;
    }
304847
protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
    {
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, array($connection, $database, $prefix, $config));
        }

        switch ($driver)
        {
            case 'mysql':
                return new MySqlConnection($connection, $database, $prefix, $config);

            case 'pgsql':
                return new PostgresConnection($connection, $database, $prefix, $config);

            case 'sqlite':
                return new SQLiteConnection($connection, $database, $prefix, $config);

            case 'sqlsrv':
                return new SqlServerConnection($connection, $database, $prefix, $config);
        }

        throw new \InvalidArgumentException("Unsupported driver [$driver]");
    }
1090623
public function getPDO($name = null)
    {
        if (null === $name) {
            $name = $this->current ?: 'default';
        }
        if (!isset($this->connections[$name])) {
            $config = $this->configs[$name];
            $this->connections[$name] = new \PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
        }

        return $this->connections[$name];
    }
840541
public function generateNewPDO() :\PDO
    {
        if($this->validateConfig()) {
            $dns = $this->driver . ':dbname=' . $this->database . ";host=" . $this->host;
            return new \PDO($dns, $this->user, $this->pass);
        }
        else {
            throw (new \Exception("Invalid or missing database connection parameters"));
        }
    }